取消自动创建窗体

Delphi避免重复打开窗体

Form1关键代码
implementation

uses
  Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(Form2) then       //assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(false)。
begin
Form2 := TForm2.Create(Self);
Form2.Show;
end;
end;
Form2关键代码需要在Form2里释放资源
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Form2:=nil;       //Form对象指向空地址
  Action := caFree; //Form关闭后释放占用的内
end;

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2021-09-12
  • 2022-01-21
  • 2021-07-20
相关资源
相似解决方案