Board index » delphi » Global DB components (and kudos to you all)

Global DB components (and kudos to you all)

Quote
smith...@ix.netcom.com (J.Smith) wrote:
>Sorry if this is in the FAQ or is "common" knowledge...
>I have an SQL query on my main form - I need to access it on a sub
>form.  I've tried moving the damned thing to the public declarations,
>to another "global" form and put that in the uses section.  When I try
>to hook my DBGrid component on the sub form to it - it acts like it
>ain't never heard of such a thing..  I *know* it has to be possible
>and I'll be damned if I use SQL's on *every* page!  

You can keep it on your mainform and simply have your mainform create
the subform and then pass the object to the subform through a method.
This means you can't set the information at design time, you will have
to do it at run-time.  But that's not too difficult.

Quote
>                                                  Thanks...
>PS: You guys have been the greatest - my main calling is  C++ and the
>folks over there could take a few pointers from you guys - my Pascal

That's because we distinguish pointers from arrays :).

Quote
>is rusty and this stuff is a new learning curve which you guys have
>flattened considerably.  I make a point to read thru every other day
>or so - I've picked up so much already that could've bit me but good!
>Thanks for the sharing and caring...

I have to second that.  This newsgroup is great.  You rarely see a
single question go unanswered.  And, the answers are usually
correct!!!  Even better.  My thanks to all you also.

Jay Cole

 

Re:Global DB components (and kudos to you all)


If the qry is on the mainform and you wish to use it from the subform
use 'mainform.qry.somefield' on the subform.

Make sure the mainform is in the implimentation uses clause for the
subform.

Have a nice day.

Quote
J.Smith wrote:

> Sorry if this is in the FAQ or is "common" knowledge...
> I have an SQL query on my main form - I need to access it on a sub
> form.  I've tried moving the damned thing to the public declarations,
> to another "global" form and put that in the uses section.  When I try
> to hook my DBGrid component on the sub form to it - it acts like it
> ain't never heard of such a thing..  I *know* it has to be possible
> and I'll be damned if I use SQL's on *every* page!
>                                                   Thanks...

> PS: You guys have been the greatest - my main calling is  C++ and the
> folks over there could take a few pointers from you guys - my Pascal
> is rusty and this stuff is a new learning curve which you guys have
> flattened considerably.  I make a point to read thru every other day
> or so - I've picked up so much already that could've bit me but good!
> Thanks for the sharing and caring...

Re:Global DB components (and kudos to you all)


I am assuming you have a TQuery on your main form. Just ignore this if
my assumption is incorrect.

In D1 you cannot reference a component on one form from another in the
IDE, but you certainly can do it at run time. In the form that has
your grid, simply assign the DBGrid's DataSource property to the
DataSource for the TQuery reference on the Main Form. (Alternately,
you can put the DataSource on your Grid form and assign its data set
property to the TQuery):

(a) If you are not using MDI and letting Delphi load the forms for
you, the reference to the main form is in its global variable:

           DBGrid1.DataSource := Form1.DataSource1;

(b) If the main form is a fsMDIChild, then you will have to have your
form anchored to it by a back reference set during Create.

In D2 you can set the Grid's DataSource reference to the DataSource on
your main form in the IDE using the dot notation. You will not get an
entry in the combo box dropdown for it, but if you type it in
correctly, it will work. Unfortunately, this will not work with MDI,
but you can still set it at run time and are no worse off than in D1.

Leo

On Fri, 11 Oct 1996 03:17:28 GMT, smith...@ix.netcom.com (J.Smith)
wrote:

Quote
>Sorry if this is in the FAQ or is "common" knowledge...
>I have an SQL query on my main form - I need to access it on a sub
>form.  I've tried moving the damned thing to the public declarations,
>to another "global" form and put that in the uses section.  When I try
>to hook my DBGrid component on the sub form to it - it acts like it
>ain't never heard of such a thing..  I *know* it has to be possible
>and I'll be damned if I use SQL's on *every* page!  
>                                                  Thanks...

>PS: You guys have been the greatest - my main calling is  C++ and the
>folks over there could take a few pointers from you guys - my Pascal
>is rusty and this stuff is a new learning curve which you guys have
>flattened considerably.  I make a point to read thru every other day
>or so - I've picked up so much already that could've bit me but good!
>Thanks for the sharing and caring...

Other Threads