Jump to content

How to create a child object


fil

Recommended Posts

Hello,

I try to create objects by dynamic.

But when I create the child object I get an error.

My code:
 

type
TParamString=record
  LabelNameSpace:TUniLabel;
  RadioGroup:TUniRadioGroup;
  RadioButton:TUniRadioButton;
end;

...
var
	ParamString:array of TParamString;
...

SetLength(ParamString,0);
SetLength(ParamString,10);

for i:=1 to 10 do
  begin
  ParamString[i].RadioGroup:=TUniRadioGroup.Create(MainForm);
  ParamString[i].RadioGroup.Parent:= MainForm;
  ParamString[i].RadioGroup.Left:=10;
  ParamString[i].RadioGroup.Top:=i*50;
  ParamString[i].RadioGroup.Width:=200;
  ParamString[i].RadioGroup.Height:=45;

  ParamString[i].LabelNameSpace:=TUniLabel.Create(ParamString[i].RadioGroup);
  ParamString[i].LabelNameSpace.Parent:=  ParamString[i].RadioGroup;
  ParamString[i].LabelNameSpace.Left:=10;
  ParamString[i].LabelNameSpace.Top:=5;
  ParamString[i].LabelNameSpace.Width:=75;
  ParamString[i].LabelNameSpace.Height:=25;
  ParamString[i].LabelNameSpace.Caption:=inttostr(i);
  end;

How to correct create the child objects?

 

Thanks

Link to comment
Share on other sites

1 hour ago, fil said:

 I understood.

 

child cannot be created :(

Hello,

1. Use instead inherited Objects

2. When you use dynamic array allocation for n  values,  you have to go to  n+1.

SetLength(ParamString, n+1);

Then, you can work with :

For i:=0 to n do

Regards.

 

Link to comment
Share on other sites

Looked at demos, unfortunately there are no examples with RadioButtons

I need to group the RadioButtons 

but unfortunately:
They are created but they all have one choice

type
TParamString=record
  LabelNameSpace:TUniLabel;
  RadioButton1:TUniRadioButton;
  RadioButton2:TUniRadioButton;
  RadioButton3:TUniRadioButton;
  Panel:TUniPanel;
end;

for i:=1 to 10 do
  begin
  ParamString[i].Panel:=TUniPanel.Create(MainForm);
  ParamString[i].Panel.Parent:= MainForm;
  ParamString[i].Panel.Left:=10;
  ParamString[i].Panel.Top:=i*50;
  ParamString[i].Panel.Width:=200;
  ParamString[i].Panel.Height:=45;


  ParamString[i].LabelNameSpace:=TUniLabel.Create(ParamString[i].Panel);
  ParamString[i].LabelNameSpace.Parent:=  ParamString[i].Panel;
  ParamString[i].LabelNameSpace.Left:=5;
  ParamString[i].LabelNameSpace.Top:=5;
  ParamString[i].LabelNameSpace.Width:=75;
  ParamString[i].LabelNameSpace.Height:=25;
  ParamString[i].LabelNameSpace.Caption:='TEST';


  ParamString[i].RadioButton1:=TUniRadioButton.Create(ParamString[i].Panel);
  ParamString[i].RadioButton1.Parent:=  ParamString[i].Panel;
  ParamString[i].RadioButton1.Left:=50;
  ParamString[i].RadioButton1.Top:=5;
  ParamString[i].RadioButton1.Width:=75;
  ParamString[i].RadioButton1.Height:=25;
  ParamString[i].RadioButton1.Caption:='TEST';

  ParamString[i].RadioButton2:=TUniRadioButton.Create(ParamString[i].Panel);
  ParamString[i].RadioButton2.Parent:=  ParamString[i].Panel;
  ParamString[i].RadioButton2.Left:=100;
  ParamString[i].RadioButton2.Top:=5;
  ParamString[i].RadioButton2.Width:=75;
  ParamString[i].RadioButton2.Height:=25;
  ParamString[i].RadioButton2.Caption:='TEST';

  end;

 

Link to comment
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...