Jump to content
Sign in to follow this  

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;
  // this is a good place to initialize components

  var W3Panel1 := tw3panel.create(self);

  var mylbl := TW3Label.create(W3Panel1);
  mylbl.caption := 'label on panel';
  mylbl.tagvalue := 2;

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




Share this post

Link to post
Share on other sites

You can use ForEach() to loop through the children:

  MyPanel.ForEach( function (const Child: TW3TagContainer): TEnumResult
      if Child is TW3Label then begin
        TW3Label(Child).Caption:='IT WORKED!';
        //result:=erBreak; //If you want to exit


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this