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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FieldAddress() Designtime vs Runtime. Why does it always return nil?

Status
Not open for further replies.

knnknn

Technical User
Nov 18, 2001
7
0
0
CY
How can I find out an address of a WinControl?

If the WinControl (e.g. a button) has been dropped on the Form1 at designtime it works like a charm.

But if I dynamically create a button then it doesn't.

Is there any way how to find out the address of the dynamically created Control?

Code:
addr := form1.FieldAddress('Button1'); // <--- WORKS! addr = C0493C, Button1 was put onto Form1 at DESIGN time

b := TButton.Create(form1);
b.Name := 'mybutton';
b.parent := Form1;
addr := form1.FieldAddress('mybutton'); // addr = NIL. Why?
 
If the WinControl (e.g. a button) has been dropped on the Form1 at designtime it works like a charm. But if I dynamically create a button then it doesn't.

You are likely seeing this (and by likely I mean I'm 99.99% sure) because the button on design-time is statically associated with the TForm type. Your dynamically created control is not associated with the object, so Form1.FieldAddress doesn't work.

Is there any way how to find out the address of the dynamically created Control?

Yes. Typecast the control variable (b in your post above) to a pointer.


It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top