Delphi中自定义类的实现

//--------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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值