Forum > LCL

A little funny test with RTTI controls

(1/1)

egsuh:
I did some experiments with RTTI controls, and found out the following.

My intention is to define all possible values in "AliasValues", and then limit the available choices via "Items" definition, as shown below.

This WORKs with TIComboBox, but NOT with TICheckGroup.



--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit MainForm; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,  RTTICtrls; 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 }   TfrmMain = class(TForm)     Button1: TButton;    TICheckGroup1: TTICheckGroup;    TIComboBox1: TTIComboBox;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);   private    FColor: TColor;    IColors: integer;    function getColors: TColors;    procedure setColors(AValue: TColors);   published     property Colors : TColors read getColors write setColors;     property Color: TColor read FColor write FColor;  public   end; var  frmMain: TfrmMain; implementation {$R *.lfm} function TfrmMain.getColors: TColors;begin   Result := TColors(IColors);end; procedure TfrmMain.setColors(AValue: TColors);begin   IColors := Integer(AValue);end;  procedure TfrmMain.FormCreate(Sender: TObject);var  acolor: TColor;  ts: string;begin   TIComboBox1.Link.TIObject:= Self;   TIComboBox1.Link.TIPropertyName:= 'Color';    TICheckGroup1.Link.TIObject:= Self;   TICheckGroup1.Link.TIPropertyName:= 'Colors';    // with TiCheckGroup1 do begin   with TiComboBox1 do begin      with Items do begin         Clear;         Add('Red');         Add('Blue');         Add('C6');         Add('C22');      end;       with Link.AliasValues do begin         Clear;         for aColor in TColor do begin             writestr(ts, aColor);             Add(Format('%s=%s', [ts, uppercase(ts)]));         end;      end;   end; end; procedure TfrmMain.Button1Click(Sender: TObject);var   ts: string;begin   // ShowMessageFmt('FColor:%d, IColor:%d', [SizeOf(FColors), SizeOf(IColors)]);   // WriteStr(ts, Color);   // ShowMessage(ts);   // ShowMessage(InttoStr(IColors));    ShowMessage(BoolToStr(Red in Colors, true));end; end.

egsuh:
I found limiting the displayed items is possible with TIRadioGroup, as well as TIComboBox.

Navigation

[0] Message Index

Go to full version