这很难,但我已经解决了
首先,您在 Delphi 中使用表单编辑器设计一个表单模板,
然后您编写代码以生成与您设计的相同布局的 .dfm。
例如,我们可以导出带有我们在模板中创建的标签的编辑。
var Component: integer;
For Component := 0 to Form1.ComponentCount -1 do
begin
if Form1.Component[Component] is TEdit then
ExportEditToMemo
else
if Form1.Component[Component] is TLabel then
ExportLabelToMemo
...
//all components kind you want
end;
我只是展示一段代码来瞄准这个布局
class procedure TTemplateFormatter.ExportLabel(ALabel: TLabel; ALines: TStrings);
begin
ALines.add(format(' object %s: %s', [ALabel.Name, ALabel.ClassName]));
ALines.add(format(' Left = %d', [ALabel.Left]));
ALines.add(format(' Top = %d', [ALabel.Top]));
ALines.add(format(' Width = %d', [ALabel.Width]));
ALines.add(format(' Height = %d', [ALabel.Height]));
ALines.add(format(' Caption = ''%s''', [ALabel.Caption]));
if Not ALabel.ParentFont then
begin
ALines.add(format(' Font.Charset = DEFAULT_CHARSET', []));
ALines.add(format(' Font.Color = clWindowText', []));
ALines.add(format(' Font.Height = %d', [ALabel.Font.Height]));
ALines.add(format(' Font.Name = ''%s', [ALabel.Font.Name]));
ALines.add(format(' Font.Style = []', []));
ALines.add(format(' ParentFont = False', []));
end;
ALines.add(format(' end', []));