Zugriffsmethoden:
Delphi-Quellcode:
unit Unit2;
interface
type
Form2 =
class (TForm)
// ...
private
FVariable1: Integer;
function GetVariable1: Integer;
procedure SetVariable1 (Value: Integer);
public
// ..
published
property TestVariable1: Integer
read FVariable1
write FVariable1;
property TestVariable2: Integer
read GetVariable1
write SetVariable1;
end;
implementation
function TForm2.GetVariable1: Integer;
begin
Result := FVariable1;
end;
procedure TForm2.SetVariable1 (Value: Integer);
begin
FVariable1 := Value;
end;
end.
Delphi-Quellcode:
procedure TForm1.Button1Click (Sender: TObject);
begin
Form2.TestVariable1 := 12345;
ShowMessage (inttostr (Form2.TestVariable2)); // = 12345
end;
Beide Varianten greifen innerhalb von Form2 auf die gleiche Variable zu. TestVariable1 ist ein direkter Zugriff, TestVariable2 über Getter/Setter-Methoden.