Jump to content

find component within another component


Recommended Posts

There have been a few threads about this topic but I couldn't get any of them to work with my current challenge.

 

My challenge was accessing a label (child) on a panel. The problem I was having was GetChildCount and GetChildObject are not accessible from the objects so I cast them a Tw3TagContainer instead, probably ok to cast as something else. I will post my solution as an example. 

procedure TForm1.InitializeForm;
begin
  inherited;
  // this is a good place to initialize components

  var W3Panel1 := tw3panel.create(self);
  W3Panel1.setbounds(10,10,400,400);

  var mylbl := TW3Label.create(W3Panel1);
  mylbl.SetBounds(10,10,80,30);
  mylbl.caption := 'label on panel';
  mylbl.tagvalue := 2;


  for var i := TW3TagContainer(W3Panel1).GetChildCount -1 downto 0 do
  begin
   var obj := TW3TagContainer(W3Panel1).GetChildObject(i);
   if obj is TW3Label then
          tw3label(obj).caption := 'IT WORKED';
  end;
end;

 

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...