Einzelnen Beitrag anzeigen

Benutzerbild von Binärbaum
Binärbaum

Registriert seit: 19. Jan 2005
Ort: Elstra
764 Beiträge
 
Delphi 7 Enterprise
 
#8

Re: Problme mit Variablenabfrage

  Alt 29. Mär 2005, 23:23
Nur so eine Idee von mir:
Wenn nur die Werte 0 und 1 erlaubt sind, könnte man z.B. auch eine einzige Variable vom Typ Cardinal nehmen und dann nur die entsprechenden Bits setzen:

Delphi-Quellcode:
const
  FLAGRESTART: Byte = 0;
  FLAGPAUSE: Byte = 1;
  FLAGSTOP: Byte = 2;
  //usw., kann nach Bedarf fortgesetzt werden...
  ...

function GetFlag(flags: Cardinal; flagindex: Byte): Boolean;
begin
  Result:= (flags and (1 shl flagindex))<>0;
end;

procedure SetFlag(var flags: Cardinal; flagindex: Byte; value: Boolean);
begin
  if (GetFlag(flags, flagindex) and not(value)) then
    flags:= flags -(1 shl flagindex)
  else if (value and not(GetFlag(flags, flagindex))) then
    flags:= flags + (1 shl flagindex);
end;
Ein Beispiel könnte dann so aussehen:
Delphi-Quellcode:
var myFlags: Cardinal;//<-- hier werden die Flags gespeichert
begin
  myFlags:= 0;
  SetFlag(myflag, FLAGRESTART, True);//FLAGRESTART auf 1 setzen
  SetFlag(myflag, FLAGPAUSE, False);//FLAGPAUSE auf 0 setzen
  //usw, je nach Bedarf
  ...
  if GetFlag(myflag, FLAGRESTART) then ShowMessage('FLAGRESTART ist gesetzt')
    else ShowMessage('FLAGRESTART nicht gesetzt');
end;
MfG
Binärbaum
There are exactly 10 kinds of people: those who understand binary, and those who don't.
---
"Software reift beim Kunden. Bei Hardware ist es anders: Hardware fault beim Kunden." - Rainer G. Spallek
  Mit Zitat antworten Zitat