Registriert seit: 29. Mai 2002
37.621 Beiträge
Delphi 2006 Professional
|
AW: Private Variable "verweigert Zutritt"
22. Sep 2011, 01:27
Delphi-Quellcode:
type
TWuerfel = class (TObject)
private
FAugen: integer;
function GetAugen: Integer;
procedure SetAugen(Value: Integer);
public
property Augen: Integer read GetAugen write SetAugen;
Constructor Create;
procedure Werfen;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FWuerfel: TWuerfel;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TWuerfel }
constructor TWuerfel.Create;
begin
Randomize;
end;
function TWuerfel.GetAugen: Integer;
begin
Result := FAugen;
end;
procedure TWuerfel.SetAugen(Value: Integer);
begin
FAugen := Value;
end;
procedure TWuerfel.Werfen;
var
Augen: Integer;
begin
Augen := Random(6) + 1;
SetAugen(Augen);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FWuerfel := TWuerfel.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Augen: Integer;
begin
FWuerfel.Werfen;
Augen := FWuerfel.Augen;
ShowMessage(IntToStr(Augen));
end;
Michael Ein Teil meines Codes würde euch verunsichern.
|