开发者

Are there any Delphi DFM to Delphi source code convertion tools?

开发者 https://www.devze.com 2023-04-03 18:08 出处:网络
The Delphi form designer is very good but we need to work directly from source. Is there a tool or script that can take a开发者_开发技巧 batch of DFM files and convert them to Delphi source code?You c

The Delphi form designer is very good but we need to work directly from source. Is there a tool or script that can take a开发者_开发技巧 batch of DFM files and convert them to Delphi source code?


You can use the ComponentsToCode function from GExperts


It's difficult, but i have done a sollution

First, you design a Form Template with form editor, in Delphi, then you write a code to generate a .dfm with the same layout you designed.

For example, we can export an Edit with label we created in template.

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;

I just show a piece of code to aim this layout

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', []));
0

精彩评论

暂无评论...
验证码 换一张
取 消