Delphi Firemonkey creating TExpanders and TLabels at runtime

  

Using Rad Studio 10.3

I am creating TExpanders at runtime based on a FireDAC query. However i am running into an issue setting the Parent of the label to the expander i have just created.

I am using the following to create the components

procedure TfrmMain.FormCreate(Sender: TObject);
var
i: integer;
begin
// Populate previous saved conversions stringgrid
FDQuery1.SQL.Clear;
FDQuery1.Close;
FDQuery1.SQL.Add(‘SELECT convert from conversions’);
FDQuery1.Open;
i := 1;
while not FDQuery1.Eof do
begin
// Create Expanders here to display database query to user
exp := TExpander.Create(Self);
exp.Parent := layoutDBDisplay;
exp.Align := TAlignLayout.Top;
exp.Name := ‘dbExp’ + i.ToString;
exp.Height := 100;
exp.TextSettings.Font.Size := 14;
exp.TextSettings.Font.Style := [TFontStyle.fsBold];

// Create TLabel inside of above expander
lab := TLabel.Create(Self);
lab.Parent := TExpander;
lab.Align := TAlignLayout.Top;
lab.Name := ‘dbResLabel’ + i.ToString;
inc(i);
FDQuery1.Next;
end;
FDQuery1.Close;

end;

The issue is lies in this line

lab.Parent := expName;

Obviously the above won’t compile because of the following

[dcc32 Error] frmConverter.pas(266): E2010 Incompatible types: ‘TFmxObject’ and ‘class of TExpander’

Is there a simple solution to this?

Comments are closed.