开发者

Component published property as array of TQuery

开发者 https://www.devze.com 2023-01-19 23:50 出处:网络
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 com

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 howeve开发者_如何学编程r 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


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).


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.


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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号