Jump to content
Jud

Spacing tRadioGroup on a TabSheet

Recommended Posts

I'm trying to space a bunch of radio groups on a tab sheet.  I have this in the form activate:

 

var i, TheTop : integer;

begin
TheTop := 14;

  for i := 0 to TabSheet6.ComponentCount - 1 do
  if TabSheet6.controls[ i] is TRadioGroup then
  begin
    TabSheet6.controls[ i].top := TheTop;

    inc( TheTop, 32);
  end; // for i
end;

 

but the CompontentCount is 0 (here and the other TabSheets).

 

What am I doing wrong?

Share this post


Link to post

As you are already accessing TabSheet6.Controls, you better use ControlCount instead of ComponentCount.

Share this post


Link to post

That was the problem - thanks!  (I haven't done one of these in quite a few years.)

Share this post


Link to post

The TComponent.Components list contains the TComponent objects that are owned by the containing TComponent for memory management purposes. All components created at design-time are owned by the parent TForm/TFrame/TDataModule that they were dropped onto. This is why your TTabSheet's ComponentCount is 0 at runtime as it doesn't own anything.

 

The TWinControl.Controls list contains the child TControl objects that are nested inside of the containing TWinControl for UI purposes. This is why your code works when you use the TTabSheet's ControlCount as its child controls list is not empty.

Share this post


Link to post

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

×