Any better idea to set TTICheckGroup? lazarus / 31-LCL ---------------------------------------------------------------------- egsuh · 2024-04-29 11:01 I have set up a TTICheckGroup in following way. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i interfacetype    TColor = (red, blue, green);  TColors = set of TColor;   TfrmMain = class(TForm)    TICheckGroup1: TTICheckGroup;    procedure FormShow(Sender: TObject);   private    IColors: integer;  function getColors: TColors;    procedure setColors(AValue: TColors);   published     property Colors : TColors read getColors write setColors;  public   end; implementation {$R *.lfm} procedure TfrmMain.FormShow(Sender: TObject);begin  TICheckGroup1.Link.TIObject := Self;  TICheckGroup1.Link.TIPropertyName := Colors;end; function PowerOf2 (n:integer) : integer;var   ti: integer;begin   Result := 1;   for ti := 1 to n do Result *= 2;end; function TfrmMain.getColors: TColors;var   tc: TColor;begin   Result := [];   for tc := Low(TColor) to High(TColor) do      if (PowerOf2(Ord(tc)) and IColors) <> 0 then Result += [tc];end; procedure TfrmMain.setColors(AValue: TColors);var   tc: TColor;   ts: string = '';begin   IColors := 0;   for tc := Low(TColor) to High(TColor) do begin     if TC in AValue        then IColors := IColors or PowerOf2(Ord(tc));   end;end;  The purpose is to save the set result (i.e. IColors) as an integer. This seems to work fine. But do you have any better idea, like declaring Colors as integer, etc.? ---------------------------------------------------------------------- egsuh · 2024-04-30 01:21 I did some further experiments with this. I found following codes succeed. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TColor = (red, blue, green, c4, c5, c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,            c17,c18,c19,c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,c30,            c31,c32);  TColors = set of TColor;   TfrmMain = class(TForm)    TICheckGroup1: TTICheckGroup;   private    IColors: integer;    function getColors: TColors;    procedure setColors(AValue: TColors);   published     property Colors : TColors read getColors write setColors;end;   //........................................implementation function TfrmMain.getColors: TColors;begin   Result := TColors(IColors);end; procedure TfrmMain.setColors(AValue: TColors);begin   IColors := Integer(AValue);end; Sizes of both TColors and integer are 4, on my system. So they look typecast-able to each other.  But why isn't the size of integer 8 on 64bit machine (and OS)? Once the number of TColor's element become over 32, i.e. when I add c33, then error message: property Colors:TColors  is not publishable. Any caveats or comments? ---------------------------------------------------------------------- alpine · 2024-04-30 06:18 I'm using sets to bitpack flags, usually for communication purposes. I do the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TSetBits32 = Set of 0..31; // Use TSetBits32(LongWord) => Set  TOrdBits32 = LongWord;     // Use TOrdBits32(TSetBits32) => LongWord   TMyClass = class  private     FFlags: LongWord;    function GetFlagByIndex(AIndex: Integer): Boolean;    procedure SetFlagByIndex(AIndex: Integer; AValue: Boolean);  public    property Flag0: Boolean index 0 read GetFlagByIndex write SetFlagByIndex;    property Flag1: Boolean index 1 read GetFlagByIndex write SetFlagByIndex;    {...}  end; function TMyClass.GetFlagByIndex(AIndex: Integer): Boolean;begin  Result := (AIndex in TSetBits32(FFlags));end; procedure TMyClass.SetFlagByIndex(AIndex: Integer; AValue: Boolean);begin  if AValue     then Include(TSetBits32(FFlags), AIndex)    else Exclude(TSetBits32(FFlags), AIndex);end;  That way I can publish individually every bit that I want, keeping them bit-packed when I want to transfer them on the wire. You can declare FFlags as an array of TSetBits32 and subscribe like (AIndex mod 32) in FFlags[AIndex div 32] with bigger number of bits if you want. EDIT: Sorry, but I've completely missed the TTICheckGroup part. Still drinking my first coffee. But anyway , you can use TTIPropertyGrid in that case ---------------------------------------------------------------------- egsuh · 2024-04-30 06:44 @alpine Yours is an interesting example as well. Typecasting integer (or longword) to set type is interesting.