Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Dynamic checkbox creation
Thu, Apr 30 2015 7:12 PMPermanent Link

Kane Jun

EZ-Tech, Inc

Hi all

I am trying to create checkbox dynamically with following code in EWB2.

with tcheckbox.create(panel1) do
begin
  caption:= 'x';  //  <--- This line cause compiler error
  ...
end;

So I work around with this

c:tcheckbox;

c:=tcheckbox.create(nil);
c.parent:=panel1;

However if I do this when I iterating component, componentcount of panel1 does not count c.

Any help would be appreciated.
Thu, Apr 30 2015 10:25 PMPermanent Link

Raul

Team Elevate Team Elevate

On 4/30/2015 7:12 PM, Kane Jun wrote:
> I am trying to create checkbox dynamically with following code in EWB2.
> with tcheckbox.create(panel1) do
> begin
>     caption:= 'x';  //  <--- This line cause compiler error
>     ...
> end;

I'm seeing it here also but just for caption - other other properties
work just fine though. for example this is ok:

   with TCheckBox.create(self) do
   begin
      name := 'MyDynamicCheckbox';
      Parent := BasicPanel2 ;
   end;

Would need Tim to comment.


> c:tcheckbox;
>
> c:=tcheckbox.create(nil);
> c.parent:=panel1;
>
> However if I do this when I iterating component, componentcount of panel1 does not count c.

Yes - because you set the owner to nil (create(nil)) and componentcount
represents objects owned by the panel.

Parent property is for controls contained within the panel so in your
case above your panel1.ControlCount would be 1 (the checkbox) while
componentcount would be 0 (since panel is just parent and not owner of
checkbox).

As an example you could do what IDE does with something like this :

   with TCheckBox.create(self) do
   begin
      Parent := panel1;
      name := 'MyDynamicCheckbox';
      //...   
   end;

and then loop thru control like this :

   for i := 0 to panel1.ControlCount -1 do
   begin
      //do something with the control
   end;


Raul
Fri, May 1 2015 6:34 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Kane,

<< I am trying to create checkbox dynamically with following code in EWB2.

with tcheckbox.create(panel1) do
begin
  caption:= 'x';  //  <--- This line cause compiler error
  ...
end; >>

Yep, this is a bug and will be fixed in the final release.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Image