//類單元unit Person;
//測試:
interface
type
TPerson = class(TObject)
private
FName: string;
FAge: Integer;
public
procedure SetName(const strName: string);
procedure SetAge(const intAge: Integer);
property Name: string read FName write SetName;
property Age: Integer read FAge write SetAge;
end;
implementation
{ TPerson }
procedure TPerson.SetName(const strName: string);
begin
FName := strName;
end;
procedure TPerson.SetAge(const intAge: Integer);
begin
if intAge<0 then FAge := 0 else FAge := intAge;
end;
end.uses Person;
procedure TForm1.Button1Click(Sender: TObject);
var
PersonOne: TPerson;
begin
PersonOne := TPerson.Create;
PersonOne.Name := '萬一';
PersonOne.Age := 100;
ShowMessage('姓名:' + PersonOne.Name + '; 年齡:' +
IntToStr(PersonOne.Age)); //姓名:萬一; 年齡:100
PersonOne.Free;
end;