Home > Archive > Getting Started with dBASE > March 2006 > Queries in .CC's









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Queries in .CC's
John Marshall

2006-03-17, 8:23 pm


I have an accounting system that needs to query remote system sales data. I want to keep all code and queries relating to the specific 'polling' of each remote system separate from the core system and thus thought of a .CC. Depending on which remote sys
tem the client uses, I intend to just 'set procedure to ... XYZ' to point to their appropriate system interface.

I have successfully used xBase "Use' to do so, but can I also define queries INSIDE .CC's in order to move to dbl?

Thanks,

JM
Michael Nuwer [dBVIPS]

2006-03-17, 8:23 pm

John Marshall wrote:
> I have an accounting system that needs to query remote system sales data. I want to keep all code and queries relating to the specific 'polling' of each remote system separate from the core system and thus thought of a .CC. Depending on which remote s

ystem the client uses, I intend to just 'set procedure to ... XYZ' to point to their appropriate system interface.
>
> I have successfully used xBase "Use' to do so, but can I also define queries INSIDE .CC's in order to move to dbl?


Yes, you can have query code inside a file with a CC extension. Do you
also plan to make a custom class in this file, so that the queries are
part of a custom class? That would be a good idea. But, did you know
that the datamodule is intended for just the type of thing you are
exploring? Instead of a generic CC class, you might look at using a
datamodule.
John Marshall

2006-03-17, 8:23 pm

Let me take a look at that over the weekend. What is the advantage over placing it in the .CC?

While I've got you, If I need to send a reference of the calling form to the .CC, how do I do that in the function call?

i.e.: POS.Get_Employee(this.form)?

where POS.Get_Employee is inside the .CC? And, yes the .CC defines a custom class named for the POS.


JM

Michael Nuwer [dBVIPS] Wrote:

> John Marshall wrote:
system the client uses, I intend to just 'set procedure to ... XYZ' to point to their appropriate system interface.[color=darkred]
>
> Yes, you can have query code inside a file with a CC extension. Do you
> also plan to make a custom class in this file, so that the queries are
> part of a custom class? That would be a good idea. But, did you know
> that the datamodule is intended for just the type of thing you are
> exploring? Instead of a generic CC class, you might look at using a
> datamodule.


Michael Nuwer [dBVIPS]

2006-03-17, 8:23 pm

John Marshall wrote:
> Let me take a look at that over the weekend. What is the advantage over placing it in the .CC?


The main advantage is that you would be able to use dQuery to help you
set-up the parts.

>
> While I've got you, If I need to send a reference of the calling form to the .CC, how do I do that in the function call?
>
> i.e.: POS.Get_Employee(this.form)?
>
> where POS.Get_Employee is inside the .CC? And, yes the .CC defines a custom class named for the POS.



In many cases you would create an instance of the CC class in your form.

form.Object = new MyCustomCC()

Then you would have access to all the properties and methods inside the
CC class via the form.Object reference. For example:

nEmp = form.Object.get_employee()

(I'm not sure how you are using "POS")

In a general way, using a custom CC in a form is no different that using
any other object, like notebooks, entryfields, etc.

In your custom CC class each object (like a query) is referenced with
"this" (like this.query1). From the viewpoint of the form, "this" is
replaced with the object reference (form.Object.query1)


The following is a working example. Save all the code one PRG file and
run it.


f = new demoForm()
f.open()

class demoForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
endwith

function form_onOpen
// set proceedure to myCCFile.cc
form.obj = new myCustomCC()
this.rowset = form.obj.fish1.rowset
? form.obj.fish1.sql
form.obj.sayHi()
form.obj.fish1.rowset.next()
? form.obj.fish1.rowset.fields['name'].value
? form.rowset.fields['name'].value
cName = form.obj.fish1.rowset.fields['name'].value
? form.obj.getID(cName)
return

endclass


// The following would be
// in the cc file
class MyCustomCC

this.DB = new DATABASE()
with (this.DB)
databaseName = "DBASESAMPLES"
active = true
endwith

this.FISH1 = new QUERY()
with (this.FISH1)
database = this.db
sql = "select * from fish.dbf"
active = true
endwith

this.rowset = this.fish1
this.fish1.rowset.index = "name"

function sayHi
? "Hi guy"

function getID(var)
this.fish1.rowset.findKey(var)
return this.fish1.rowset.fields['ID'].value

endclass
Michael Nuwer [dBVIPS]

2006-03-17, 8:23 pm

Michael Nuwer [dBVIPS] wrote:

> class MyCustomCC
>
> this.rowset = this.fish1


Opps, should be
this.rowset = this.fish1.rowset

> endclass

John Marshall

2006-03-18, 7:23 am


What I was considering is that the .CC tests its local query results against the entryfields on the calling form, updating the entryfields where necessary. The ojective is to keep the external query separate from the main code, but able to influence it.
Does this make sense?


JM

Michael Nuwer [dBVIPS] Wrote:
[color=darkred]
> Michael Nuwer [dBVIPS] wrote:
>
>
> Opps, should be
> this.rowset = this.fish1.rowset
>

Michael Nuwer [dBVIPS]

2006-03-19, 11:07 am

John Marshall wrote:
> What I was considering is that the .CC tests its local query results against the entryfields on the calling form, updating the entryfields where necessary. The ojective is to keep the external query separate from the main code, but able to influence it

. Does this make sense?
>


I believe the example code I posted can do what you want.
John Marshall

2006-03-19, 11:07 am


That sample looked as though the interaction was to happen at the calling program side and not within the called program side. I want to keep the calling program free of specifics on how the data is posted. I'd like to send references to the entryfields
to the called .CC and have that procedure change the entryfield values (when appropriate).

JM

Michael Nuwer [dBVIPS] Wrote:

> John Marshall wrote:
it. Does this make sense?[color=darkred]
>
> I believe the example code I posted can do what you want.


Michael Nuwer [dBVIPS]

2006-03-21, 3:25 am

John Marshall wrote:
> That sample looked as though the interaction was to happen at the calling program side and not within the called program side. I want to keep the calling program free of specifics on how the data is posted. I'd like to send references to the entryfiel

ds to the called .CC and have that procedure change the entryfield values (when appropriate).

This type of thing can be a bit tricky. The generally accepted OOP
method is to use "setters" and "getters" in the custom class.

I have included an example below. In this example the custom class makes
a call to a function named "setEntryfield." This internal function calls
a function in the form (if it exists). Structured this way the form
handles any form-specific information, like the entryfield name, and the
custom class need not know that detail.

additionally to the example below, a "setter" in the custom class might
set a property to a specific value. Thus a setValues function might look
like this.

function setValues
this.Property1 = something
this.Property2 = something else
if type("this.parent.parent.parent.getEntryfield")=="FP"
this.parent.parent.parent.getEntryfield()
endif

Then, in the form, the getEntryfield function might do something like this:

function getEntryfield()
form.entryfield1.value = form.obj.property1
form.entryfield2.value = form.obj.property2

Note that setters do not always make calls to functions in the parent
form. In the examples here we do so because an event inside the custom
class is triggering the action. If the trigger event is in the form (a
more common structure), then the form makes the function calls to the
custom class.

Note also that the custom class has access to all the form objects. When
the form opens we tell the class that the form is it's parent:
form.obj.parent=this

Then in the class, "this.parent" is the form and this.parent.entryfield1
is the entry field on the form. However it not a good idea to set form
object properties directly from inside the custom class.



f = new demoForm()
f.open()

class demoForm of FORM
set procedure to :FormControls:DATABU
TTONS.CC additive
with (this)
onOpen = class::FORM_ONOPEN
endwith
this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
width = 25
value = "Entryfield1"
endwith

this.BITMAPNEXT1 = new BITMAPNEXT(this)
with (this.BITMAPNEXT1)
left = 28.0
endwith


function form_onOpen
// set proceedure to myCCFile.cc
form.obj = new myCustomCC()
form.obj.parent = this
form.rowset = form.obj.rowset
// or
// this.rowset = form.obj.fish1.rowset
return

function setEntryfield(cVal)
form.entryfield1.value = cVal

endclass


// The following would be
// in the cc file
class MyCustomCC

this.DB = new DATABASE()
with (this.DB)
databaseName = "DBASESAMPLES"
active = true
endwith

this.FISH1 = new QUERY()
this.fish1.parent = this
with (this.FISH1)
database = this.db
sql = "select * from fish.dbf"
active = true
rowset.onNavigate = class::setValues
endwith

this.rowset = this.fish1.rowset

function setValues(type, nRows)
if type("this.parent.parent.parent.setEntryfield")=="FP"
this.parent.parent.parent.setEntryfield(this.fields['name'].value)
endif

return

endclass
John Marshall

2006-03-22, 9:23 am


Michael:

What about setting a parameter to convey the form (and form controls) to the external .CC? This way one would not have to send each field value separately. Is this just as simple as mForm = form, and sending mForm as a parameter? Can one then get a
hold of and change mForm.entryfield1.value, etc?

JM


John Marshall Wrote:

>
> What I was considering is that the .CC tests its local query results against the entryfields on the calling form, updating the entryfields where necessary. The ojective is to keep the external query separate from the main code, but able to influence it

. Does this make sense?
>
>
> JM
>
> Michael Nuwer [dBVIPS] Wrote:
>
>


Michael Nuwer [dBVIPS]

2006-03-22, 11:24 am

John Marshall wrote:
> Michael:
>
> What about setting a parameter to convey the form (and form controls) to the external .CC? This way one would not have to send each field value separately. Is this just as simple as mForm = form, and sending mForm as a parameter? Can one then get

ahold of and change mForm.entryfield1.value, etc?
>


This approach would violate a number of OOP rules, although you can do
it. The main problem is that the custom class will need to know
information that is specific to the form. Consequencely, the class will
have no value in any other context. So, it will not be reusable and I
don't see any point of using a custom class.

Why not just make a custom form with the entry fields, etc., and
subclass it for each remote system?

John Marshall

2006-03-23, 1:24 pm


I guess I could just compare not to the entryfields, but the file fields the populat the entryfields. In this way the remote .CC updates unmatched data and on returning from the .CC call, I could just execute a Requery() to update the entryfileds locally
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com