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;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步