Forum > LCL

RTTI controls action

(1/1)

egsuh:
I'm developing an application that uses many RTTI controls. The basic skeleton is as follows.


--- 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 uform2; {$mode ObjFPC}{$H+} interface uses   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, RTTICtrls; type   TQType = (qt1, qt2, qt3);   TMyObj = class       QType: TQType;       Value1,       value2,       value3 :  string;   end;     { TForm1 }    TForm1 = class(TForm)      TIValue1: TTIEdit;      TIQtype: TTIRadioGroup;      procedure FormCreate(Sender: TObject);   private      MyObj: TMyObj;       function getQType: TQType;      function getValue1: string;       procedure setQType(AValue: TQType);      procedure setValue1 (AValue: string);    published      property QType : TQType read getQType write setQType;      property Value1 : string read getValue1 write setValue1;   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin   MyObj := TMyObj.create;   with MyObj do begin      QType:= qt2;      Value1 := 'v1';      Value2 := 'v2';      Value3 := 'v3';   end;    TIQType.Link.TIObject := Self;   TIQType.Link.TIPropertyName := 'QType';    TIValue1.Link.TIObject := Self;   TIValue1.Link.TIPropertyName := 'Value1';end; function TForm1.getQType: TQType;begin  if Assigned(MyObj) then Result := MyObj.QType;end; function TForm1.getValue1: string;begin  if Assigned(MyObj) then begin      case MyObj.QType of          qt1: Result := MyObj.Value1;          qt2: Result := MyObj.Value2;          qt3: Result := MyObj.Value3;      end;  end;end; procedure TForm1.setQType(AValue: TQType);begin   if Assigned(MyObj) then MyObj.QType := AValue;end; procedure TForm1.setValue1(AValue: string);begin   if Assigned(MyObj) then begin       case MyObj.QType of           qt1: MyObj.Value1 := Avalue;           qt2: MyObj.Value2 := Avalue;           qt3: MyObj.Value3 := Avalue;       end;   end;end; end. 
Here, the key is that TIEdit1's content is changed automatically as I change the qtype from TIQType, which is a TIRadioGroup. It seems to call setQType getValue1, even though  do not call setValue1 in the setQType myself. How does this operate?

Thaddy:
If the rtti that is generated has getters and setters for the QType property then it will be called through essentially invoke, afaiu.
I reconstructed your code without changes, observed the same, but i still have to run it with the debugger.

egsuh:

--- Quote ---If the rtti that is generated has getters and setters for the QType property then it will be called through essentially invoke, afaiu.
I reconstructed your code without changes, observed the same, but i still have to run it with the debugger.
--- End quote ---

Thank you, Thaddy. I prefer the current result --- actually this is very valuable, but want to know how it operates.

egsuh:
I modified above code a little bit. I used TRadioGroup instead of TTIRadioGroup, and still it works. I mean, when the radiogroup's value changes, the Rtti control's value follows.



--- 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";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin   MyObj := TMyObj.create;   with MyObj do begin      QType:= qt2;      Value1 := 'v1';      Value2 := 'v2';      Value3 := 'v3';   end;   // TIQType.Link.TIObject := Self;  // TIQType.Link.TIPropertyName := 'QType';    with RadioGroup1.Items do begin  //--  these are added      Clear;      Add('Q1');      Add('Q2');      Add('Q3');   end;    TIValue1.Link.TIObject := Self;   TIValue1.Link.TIPropertyName := 'Value1';end; // ---------- and following procedure was addded --------------procedure TForm1.RadioGroup1Click(Sender: TObject);begin   if Assigned(MyObj) then MyObj.QType:= TQType(RadioGroup1.ItemIndex);end; 
So, does this mean that any  RTTI control checks changes of other properties of its TIObjects?  In my example, the TIEdit1 must be observing the changes in the value of property QType.

egsuh:
But this is not reliable. When there are multiple RTTI controls in one form, which change values depending on the state of another control (e.g. clicking radio button, etc.), some of them change values automatically while others do not. I have to use "LoadfromProperty", like following:


--- 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";}};} ---procedure TForm1.RadioGroup1Click(Sender: TObject);begin   if Assigned(MyObj) then begin       MyObj.QType:= TQType(RadioGroup1.ItemIndex);      TIValue1.Link.LoadFromProperty;   end; end;
But in this case, it is more like loading values manually to non-RTTI controls.

Navigation

[0] Message Index

Go to full version