2,497
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FFormCount: Integer;
FormArray: array of TForm;
protected
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FFormCount := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(FFormCount);
SetLength(FormArray, FFormCount);
FormArray[FFormCount - 1] := TForm.Create(Application);
FormArray[FFormCount - 1].OnClose := FormClose;
FormArray[FFormCount - 1].Caption := Format('Form%d', [FFormCount]);
FormArray[FFormCount - 1].Width := 200;
FormArray[FFormCount - 1].Height := 200;
FormArray[FFormCount - 1].Position := poScreenCenter;
FormArray[FFormCount - 1].Show;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShowMessage(TForm(Sender).Caption + ' has been closed.');
TForm(Sender).Free;
end;
end.
procedure TForm1.CreateForm;
begin
Inc(Count); //Count变量初值为0
SetLength(f1, Count);
f1[Count - 1] := TForm.Create(Application);
with f1[Count - 1] do begin
......//属性设置
end;
f1[Count - 1].OnClose := FormClose;
f1[Count - 1].Show;
GroupBox3:=TGroupBox.Create(nil);
...... //GroupBox3的属性设置
GroupBox3.Caption:='数字键';
GroupBox3.Parent:=f1[Count - 1];
GroupBox3.Visible:=True;
......//在动态创建的f1[Count - 1]窗体上动态创建动态组件
......//在f1[Count - 1]上动态创建ADOQuery
end;