type TNewClass = class public constructor Create; virtual; destructor Destroy; override; end;// with TNewClass.Create do try finally Free; end;
unit; interface; type TNewClass = class public constructor Create; virtual; destructor Destroy; override; end;implementationconstructor TNewClass.Create; begin end;destructor Destroy; begin end;end.
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TMyClass=Class(TButton) Private {私有声明} Protected {保护声明} Public Procedure MyShowMessage(); {公有声明} end;//声明自己的类 TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}Procedure TMyClass.MyShowMessage(); begin Showmessage('MyTestDiaLog'); end;procedure TForm1.Button1Click(Sender: TObject); Var MyClass:TMyClass; begin try MyClass:=TMyClass.Create(self);//实例化 MyClass.MyShowMessage(); finally MyClass.Free; end; end;end.
TNewClass = class
public
constructor Create; virtual;
destructor Destroy; override;
end;//
with TNewClass.Create do
try
finally
Free;
end;
interface;
type
TNewClass = class
public
constructor Create; virtual;
destructor Destroy; override;
end;implementationconstructor TNewClass.Create;
begin
end;destructor Destroy;
begin
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TMyClass=Class(TButton)
Private
{私有声明}
Protected
{保护声明}
Public
Procedure MyShowMessage();
{公有声明}
end;//声明自己的类
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}Procedure TMyClass.MyShowMessage();
begin
Showmessage('MyTestDiaLog');
end;procedure TForm1.Button1Click(Sender: TObject);
Var
MyClass:TMyClass;
begin
try
MyClass:=TMyClass.Create(self);//实例化
MyClass.MyShowMessage();
finally
MyClass.Free;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TMyClass=Class(TButton)
Private
{私有声明}
Protected
{保护声明}
Public
Procedure MyShowMessage();
{公有声明}
end;//声明自己的类