views:

87

answers:

3

hi,

i'm developing a custom component, and i'd like to add a published property that would be an array of TQuery (it should be visible in the object inspector). the main feature would be to drop the component on a form and then visually select the queries that are present on the same form, or on any other project form.

is that doable? from what i've seen till now, you can only programatically use such an array property...

UPDATE

first, thanks for your answer Alex!

second, the chatch is that i have to modify an old app someone else created, so i want to tangle with it as little as possible (actually there's a second app i need to "fix" which i was told is twice as big). now for the details: the app has abou 15 forms for various db operations. as you can imagine each form has 2-3 TQuery objects. the problem is that the user must authenticate with the db in order to execute the queries, thus he knows the db user & pwd which is a security flow.

in order to avoid this, an intermediate system has been introduced. one connects & authenticates with it and requests the necessary db data: user, pwd, and database name. my job is to use this system and autologin to the db. the necessary credentials to access this intermediate system are not considered a security flow so i'll read them from an inifile that depends on the environment where it's deployed: test, pre-production, production.

so i placed a TDatabase component on my form, setting its LoginPrompt property to FALSE. the tricky part however is adjusting each TQuery to the diferent database name for each environment before execution..

dunno if i made myself clear but it's the simplest explaination i managed to come up with


thanks, G

A: 

Yes, it can be done but you will have to write your own Property editor with it's own input form to manage the data inside the array. There's plenty of information to be found online. And yes, you could create a component that checks for controls on it's parent, allowing you to access those.
But is it practical? Why do you need an array of TQuery components in design time? Maybe you need to rethink your design first, so you're absolutely sure that you need this functionality. (Besides, what's wrong with using a Data Module to contain your queries?)

Workshop Alex
check the update section in the original post. ty, G
Grove
Check my second answer for the update. :-)
Workshop Alex
A: 

Okay, you've added a TDatabase to your project. Now, fill the "DatabaseName" property of TDatabase with some random name. Every TQuery component in your project also has a "DatabaseName" property and fill in the same name in those properties! Now your database and all it's queries will be connected and you could use the TDatabase object to access them all.

Workshop Alex
dammit, how did i miss that (basic noob mistake)? thanks mate, you're a life saver :D
Grove
You're not the first one to miss that. :-) Believe me, thousands of experienced Delphi Developers had a problem with that before you. :-)
Workshop Alex
well now that you've reminded me of it, i've changed the aproach. i'm subclassing a TDatabase and overriding its 'SetConnected(Value: Boolean);' method. this allows me to introduce the authentication logic before the login, and i only need to update all the TQuery to use its 'DatabaseName'. so basically i don't need to touch the old code... many thanks :-D
Grove
+2  A: 

To make life as simple as possible, you may have to grin and bear it once:

  • Create a datamodule and make sure it gets instantiated before the main form.
  • Put your TDatabase component on that data module.
  • Go through all your forms once and
    • add the database's data module to its uses clause (can be in implementation section).
    • Change all your TQuery and other database related components once to use the database component from the data module instead of having their own connection strings.

At run time, login as you described via your TDatabase component et voila, all your components will now use these settings automagically (as they are all connected to your TDatabase instance).

Marjan Venema
cool idea, but the answer was way simpler, only i didn't have the eyes to see it. actually i was looking for a feature i forgot that was already present. thank god for these kind of communities and you guys for making them happen
Grove