简体   繁体   English

Delphi Firemonkey在运行时创建TExpander和TLabel

[英]Delphi Firemonkey creating TExpanders and TLabels at runtime

Using Rad Studio 10.3 使用Rad Studio 10.3

I am creating TExpanders at runtime based on a FireDAC query. 我在运行时基于FireDAC查询创建TExpander。 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? 有一个简单的解决方案吗?

Your line 你的线

lab.Parent := TExpander;

should be 应该

lab.Parent := Exp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM