Accessing controls on a form
Hi!
I'm having some trouble accessing controls on a form. What I tried to do
is to set up an array of TCheckBox-es and assign four checkboxes (which
are contained in a group box "GroupBox", which is on a form "Form") to it:
{=====}
var MyCheckBox : array [1..4] of TCheckBox;
BoxN,Ctrl : integer;
begin
BoxN := 1;
for Ctrl := 0 to GroupBox.ControlCount-1 do
if( GroupBox.Controls[i] is TCheckBox ) then begin
MyCheckBox[BoxN] := TCheckBox(GroupBox.Controls[i]);
inc(BoxN);
end{if};
{endfor};
end;
{=====}
I can read the properties, but if I try to change a property with
"MyCheckBox[1].Checked := False;", I get an access violation error.
I *do* know that I can do the same thing with
{=====}
var MyCheckBox : array [1..4] of integer;
BoxN,Ctrl : integer;
begin
BoxN := 1;
for Ctrl := 0 to GroupBox.ControlCount-1 do
if( GroupBox.Controls[i] is TCheckBox ) then begin
MyCheckBox[BoxN] := i;
inc(BoxN);
end{if};
{endfor};
end;
{=====}
and use "TCheckBox(GroupBox.Controls[1]).Checked := True;" to set the
checkbox state, but I've absolutely no idea why the first approach doesn't
work. Any ideas, anyone?
Please send me e-mail in addition to the newsgroup post.
Cheers, Jan
-----
Jan Kalin (male), ZAG Ljubljana, Dimiceva 12, 1000 Ljubljana, Slovenija
tel: +386 61 1888-458 or 1888-309, fax: +386 61 1888-484 or 348-369
email: jan.ka...@zag.si, URL: http://www.zag.si/people/jank.html
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet