const Colors : array[0..1] of integer = ($00FF00, $FF0000); procedure TForm7.FormCreate(Sender: TObject); begin // Items[0] = 0000FF00 // Objects[0] = 0x0000FF00 ListBox1.Items.AddObject(format('%.8x',[Colors[0]]), Pointer(Colors[0])); // Objects[0] = 0x00FF0000 ListBox1.Items.Objects[0] := Pointer(Colors[1]); // Color = $00FF0000 color := integer(ListBox1.Items.Objects[0]); end;
const MaxColors = (10 shl 20) div SizeOf(Integer); type // Attention Colors utilise le champ Objects! // on utilise soit l'un, soit l'autre. TStringsHelper = class helper for TStrings private function GetColors(index: integer): integer; procedure SetColors(index: integer; const Value: integer); public function AddColor(const Str: string; const Color: integer): integer; property Colors[index: integer] : integer read GetColors write SetColors; end; const Colors : array[0..1] of integer = ($00FF00, $FF0000); procedure TForm7.FormCreate(Sender: TObject); begin ListBox1.Items.AddColor(format('%.8x',[Colors[0]]), Colors[0]); ListBox1.Items.Colors[0] := Colors[1]; color := ListBox1.Items.Colors[0]; end; { TStringsHelper } function TStringsHelper.AddColor(const Str: string; const Color: integer): integer; begin AddObject(Str, Pointer(Color)); end; function TStringsHelper.GetColors(index: integer): integer; begin result := integer(Objects[index]); end; procedure TStringsHelper.SetColors(index: integer; const Value: integer); begin Objects[index] := pointer(Value); end;