можно еще немного модифицировать:
Код:
type
IFlagContainer = interface
procedure SetData(ID: Byte; Value: Boolean);
function GetData(ID: Byte): Boolean;
property Value[Index: Byte]: Boolean read GetData write SetData; default;
end;
TFlagContainer = class(TInterfacedObject, IFlagContainer)
private
FData: Byte;
procedure SetData(ID: Byte; Value: Boolean);
function GetData(ID: Byte): Boolean;
end;
{ TFlagContainer }
procedure TFlagContainer.SetData(ID: Byte; Value: Boolean);
begin
FData:=FData and not (1 shl ID) or ((Byte(Value) and 1) shl ID);
end;
function TFlagContainer.GetData(ID: Byte): Boolean;
begin
Result:=((FData shr ID) and 1)=1;
end;
использование:
Код:
var
f: IFlagContainer;
i: Integer;
begin
f:=TFlagContainer.Create;
for i:=0 to 7 do f[i]:=(i mod 2)=0;
for i:=0 to 7 do if f[i] then Memo1.Lines.Add(IntToStr(i));
end;
Destroy объекту не нужен.