delphi 窗体创建

//-----------------------方式一

procedure Tfomr1.Excute_Form();
begin
    with Tfomr1.Create(Application) do
    begin
      try
        Init;
        ShowModal;
      finally
        Free;
      end;
    end
end;

//-------------------------------方式二

unit UMydany;

interface

uses
  System.SysUtils, Vcl.Dialogs;
 

type
  TMydany = class
    class function THIS: TMydany;
  private
  public
    constructor Create();
    destructor Destroy(); override;
    procedure f1();
  end;

implementation

var
  _Mydany: TMydany;

constructor TMydany.Create;
begin
  //
end;

destructor TMydany.Destroy;
begin

  inherited;
end;

procedure TMydany.f1;
begin
  showmessage('11');
end;

class function TMydany.THIS: TMydany;
begin
  Result := _Mydany;
end;

initialization
begin
  _Mydany := TMydany.Create();
end;

finalization
begin
  if Assigned(_Mydany) then
    FreeAndNil(_Mydany);
end;

end.

猜你喜欢

转载自blog.csdn.net/ozhy111/article/details/86135716