这是一个例子,全部的代码,编译通过的,你参考下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Tstudent=class
private
name:string;
age:integer;
sex:string;
public
function getname(mingzi:string):string;
procedure getage(nianlin:integer);
procedure getsex(xingbie:string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tstudent.getname(mingzi:string):string;
begin
name:=mingzi;
end;
procedure Tstudent.getage(nianlin:integer);
begin
age:=nianlin;
end;
procedure Tstudent.getsex(xingbie:string);
begin
sex:=xingbie;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
std:Tstudent;
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
std:=Tstudent.Create();
std.getname('小明');
std.getage(10);
std.getsex('男');
edit1.Text:=std.name;
edit2.Text:=inttostr(std.age);
edit3.Text:=std.sex;
end;
end.