//--------Swatch.pas :类的实现-------------//
unit Swatch;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSwatch=Class(TObject)
private
public
S:array of array of double;
constructor Create(M,N: Integer); overload;
procedure SayHello();
end;
implementation
procedure TSwatch.SayHello();
begin
MessageDlg('Hello,Adam!',mtInformation,[mbOK],0);
end;
constructor TSwatch.Create(M,N: Integer);
begin
inherited Create;
setLength(S,3);
setLength(S[0],2);
SetLength(S[1],2);
SetLength(S[2],2);
end;
end.
//------------------主窗口的.pas文件-------------------------------------------//
unit M_NH;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Swatch; //引用自定义类Swatch
type
TForm1 = class(TForm)
Button2: TButton;
Edit1: TEdit;
Button1: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
Swatch:TSwatch; //我的TSwatch类对象
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
Swatch:=TSwatch.Create(3,2); //调用构造函数创建对象
Swatch.S[0,0]:=1;
Swatch.S[0,1]:=2;
Swatch.S[1,0]:=3;
Swatch.S[1,1]:=4;
i:= trunc(Swatch.S[0,0]*Swatch.S[0,1]);
self.Edit1.Text:=intTostr(i);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Swatch.SayHello;
end;
end.