Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem finding the required control parents (Want to go out of scope)

Status
Not open for further replies.

cyberium

Programmer
Aug 25, 2001
8
NO
This problem probably seem dull to many, but in my case it's important to get through in one way or another - it has to do with obtaining an HWND pointer to a control in order to enable use of FindControl(Handle: HWND). To explain this, let's look at what I'm trying to do... I'm writing a script engine component in Delphi 5, and this script engine has built-in commands (or opcodes) that activates creation or freeing of dynamically created controls. The engine component is supposed to be placed on only one form and be able to create controls for any and all other forms in the application, as well as define the new controls' Parent property accordingly. This seems utterly awkward because TApplication does not present any list of the forms that it owns, only an array of components that expose a very limited range of properties. If TApplication had a unit list which exposed name labels and handles, it could have been possible to do some out-of-scope referencing. I know this all seems pretty odd, but I hope someone out there can reply with something that can solve my problem. Any and all hard-coding by the script engine component user should be avoided, and as such the component should incorporate its own ways of getting stuff done. ...And one more thing - if anyone knows how to dynamically read/write variables or properties across units, I'd be happy for answers. Thanks. -Steinar Skaalvik
 
TApplication's list of components can be typecast to what they really are. For example, you could say
if application.Components[0] is TForm then
begin
myForm := application.Components[0] as TForm;
//then use myForm here to get the hwnd
end;

I'm not sure what you mean by dynamically reading/writing variables across units?


TealWren
 
Hi TealWren, thanks for your reply.

As for what I meant by reading/writing to variables dynamically, I meant something like being able to perhaps call a function, say SetAnyProperty('Unit1','Edit1','Text','Hi World!') to read or write to a property, or a variable. I think I can work out the part about searching using the Components[] array of components to find scopes like Unit1 or Unit2, by just passing a string to the search function (a custom function of my own). The difficult part would be to actually access existing properties or variables (not just ordinary variables but arrays as well (preferably)) owned by the component or control that the custom search function returned. Say, you have a pointer to a TEdit component and you want to be able to read or write to any of its properties without hard cording everything, only passing the pointer and the name string of the wanted variable to a special function.

Since I'm writing a script engine, and it's supposed to enable the script editor to create controls using the script, I want to enable a script syntax that looks something like this:
CreateControl(TEdit,'Edit1',Form1); or using object binding it could be Form1.Panel1 instead of just Form1, if we wanted to put our edit control in a panel. Further, property access would go like this:
SetProp(Form1.Edit1,Text,'Hi there!');
S:=GetProp(Form1.Edit1,Text);
And for freeing the object through script code we would just write FreeControl(Form1.Edit1);
Note that the script syntax presented here is different from that of my script engine. My script engine uses an Assembly-like syntax, but for easier reading I just wrote the above pseudo-code in Pascal.

Actually, the part about "Form1.Edit1" is something I haven't thought of before now - how to access Edit1 through finding Form1, but I guess that can be solved by writing a more complex custom search function, as mentioned above.

Thanks again,

-Steinar
 
By the way...one more thing:
All operands (or parameters, or variables, if you like) in my script engine are presented as ShortString to the engine.

When it comes to telling the script engine what kind of a control (eg. TEdit, TSpeedButton, TMemo) to create, this may be hard-coded by me, but if you have any suggestions to how to add a more flexible system I'd be happy to listen.

-Steinar
 
The TypInfo unit might be useful to you. With that, you can "Get" or "Set" any published property of a component. For Example, you could use FindComponent to find an edit box with a certain name, then use SetStrProp from typinfo to change the property. However, you'd probably need to handle different property datatypes yourself - you would not be able to use SetStrProp to set an integer type property.

Good luck!
TealWren
 
Hi TealWren,

Thanks for your help - I think I might just achieve just what I need now. I'm still unsure wether I'm going to need more help from somewhere though, because I haven't finished the parent search function yet. I'm also correcting a set of commands and functions within my script engine, so I guess I may have to wait a few days to see the control creation stuff in action.

As for the control creation function, I might post it here for everyone to use. If so, it will appear here this week or during the coming weekend.

Technical details regarding the control creation search function, such as speed and the complexity of its "search tree" (temporary pointers to the components being examined for valid idenitifers) may have to be adjustable. That is, maybe I should let the user/programmer choose if the search function should search any components necessary, or if it should ignore ownership levels as high as, say Application.Form.Panel.Button and only go as high as Application.Form.Button.
As for using a static lookuptable for speeding up searching, it's probably not a good idea because it would just restrict the application in general by indirectly forcing the use of a dedicated object creation function.

And one more thing - My script engine may be released as freeware for public use in free-of-charge applications (or even commercial ones. Just maybe). The name of the engine is STXScript - so if you see STXScript anywhere with my name (Steinar Skaalvik) on it, it's my component :)

Have a nice day,
-Steinar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top