Re:Objects created during runtime
The message <8sebhk$1g...@riker.addcom.de>
from "Ronny Falk" <r_f...@addcom.de> contains these words:
Quote
> How can I access the properties of an object (i.e. EditBox.Text "Test" or
> s.th.]) that was created during runtime? I parented the EditBox with a
> GroupBox.
> So I try to access GroupBox1.Edit1
> ^ can't access : undefined
> reference (or s.th. like that)
> Then I try: X := GroupBox1.Components[0].Text
> ^
> undefined again
Hi,
If you declared your edit box like this:-
Type
TForm1 = Class(TForm)
......
private
.......
Edit1:Tedit;
.......
public
end;
var Form1:TForm1;
Then in FormCreate you can say
TForm1.FormCreate(sender:TOBject);
begin
Edit1:=TEdit.Create(Form1);
Edit1.Parent:=Groupbox1;
Edit1.Visible:=True;
....
end;
Then in any method or event handler
you can access it using it's name.
TForm1.Button1Click(Sender:TOBject);
begin
Edit1.Text:='Hello There';
end;
It's as simple as that!
Quote
> Then I try: X := GroupBox1.Components[0].Text
In order for the compiler to recognise this as a TEdit you have to
use a typecast.
Assuming X is of type string...
X:=TEdit(GroupBox1.Components[0]).Text;
This is only safe to use if you are certain that component 0 in the
array is a TEdit
otherwise you need to say
if (GroupBox1.Components[0]) is TEdit then
X:=TEdit(GroupBox1.Components[0]).Text;
You also need to check the component count, because if the count is
zero, trying to
access Components[0] will produce an exception.
--
Regards,
Andreas Kyriacou
----------------
http://www.andrikkos.co.uk