Delphi学习(三)——面向对象

1、新建单元,代码如下
unit Models;

interface
    uses Windows, SysUtils, Messages,Dialogs;

type
    Tstudent = class(TObject)    //创建类
    public
        sno : string;
        sname:string;
        Ssex : string;
        SAge : string;
        procedure SayHelloBy(name:string);
        function SayHelloByF(name:string): string;
    end;
implementation

procedure Tstudent.SayHelloBy(name:string);
begin
    showmessage('234'+sname);
end;

function Tstudent.SayHelloByF(name:string):string;
begin
    Result:=name;
end;
end.

窗体button Click事件如下
uses
    Models;

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
    student : Tstudent;
begin

实例化类
    student := Tstudent.Create;
    student.sname :='rxy';
    student.SayHelloBy('12');

    student.Free;//撤销类Free或Destroy

end;

posted on   为学日损  阅读(138)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示