是否可以动态创建没有* .dfm和* .pas文件的表单? [英] Is it possible to dynamically create form without having *.dfm and *.pas files?
本文介绍了是否可以动态创建没有* .dfm和* .pas文件的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以创建和显示TForm而不需要源文件?
我想在运行时创建我的表单,并且空的* .dfm和* .pas文件似乎对我无用。
is it possible to create and show TForm without having source files for it ? I want to create my forms at runtime and having the empty *.dfm and *.pas files seems to me useless.
谢谢
推荐答案
你的意思是这样吗?
procedure TForm1.Button1Click(Sender: TObject);
var
Form: TForm;
Lbl: TLabel;
Btn: TButton;
begin
Form := TForm.Create(nil);
try
Form.BorderStyle := bsDialog;
Form.Caption := 'My Dynamic Form!';
Form.Position := poScreenCenter;
Form.ClientWidth := 400;
Form.ClientHeight := 200;
Lbl := TLabel.Create(Form);
Lbl.Parent := Form;
Lbl.Caption := 'Hello World!';
Lbl.Top := 10;
Lbl.Left := 10;
Lbl.Font.Size := 24;
Btn := TButton.Create(Form);
Btn.Parent := Form;
Btn.Caption := 'Close';
Btn.ModalResult := mrClose;
Btn.Left := Form.ClientWidth - Btn.Width - 16;
Btn.Top := Form.ClientHeight - Btn.Height - 16;
Form.ShowModal;
finally
Form.Free;
end;
end;
这篇关于是否可以动态创建没有* .dfm和* .pas文件的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文