Schreibe eine Klasse mit einer Property und einem Setter und Getter. Ein Klassen Tutorial, was dies demonstriert, findets du hier:
http://tutorials.luckie-online.de
Delphi-Quellcode:
type
TFoo = class
private
FLbl: TLabel;
function GetText: string;
procedure SetText(s: String);
public
constructor Create(lbl: TLabel);
property MyText: string read GetText write SetText;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TFoo.Create(Lbl: TLabel);
begin
inherited Create;
FLbl := Lbl;
end;
procedure TFoo.SetText(s: String);
begin
FLbl.Caption := s;
end;
function TFoo.GetText: String;
begin
result := FLbl.Caption;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Foo: TFoo;
begin
Foo := TFoo.Create(Label1);
try
ShowMessage(Foo.MyText);
finally
FreeAndNIl(Foo);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Foo: TFoo;
begin
Foo := TFoo.Create(Label1);
try
Foo.MyText := 'Hello';
finally
FreeAndNil(Foo);
end;
end;