Einzelnen Beitrag anzeigen

Benutzerbild von dataspider
dataspider

Registriert seit: 9. Nov 2003
Ort: 04539 Groitzsch
1.350 Beiträge
 
Delphi 11 Alexandria
 
#3

Re: Beschränkter Bereich für Variable

  Alt 27. Jan 2006, 16:29
Hi,

aus meiner Sicht durch ein Property relisierbar.

Delphi-Quellcode:
  privat
    FVariable: Integer;
    procedure SetVariable(const Value: Integer);
    { Private-Deklarationen }
  public
    property Variable: Integer read FVariable write SetVariable;
    { Public-Deklarationen }
  end;
  ...

implementation

procedure TForm1.SetVariable(const Value: Integer);
begin
  if FVariable <> Value then
  begin
    if Value in [1..3] then
      FVariable := Value
    else
      if Value > 3 then
        FVariable := 3
      else
        FVariable := 1;
  end;
end;
Cu, Frank
Frank Reim
  Mit Zitat antworten Zitat