Hi all
Can anyone point me to an example how to use TTIComboBox, please?
I just started with the RTTI components and the few things i tried so far works as expected.
But i can't figure out what TTIComboBox is intended to do.
I have had a look to the example program provided with Lazarus, wich use the "special case" of a boolean property to show true/false in the combobox.
Having a look into the source of TTIComboBox i found that the component wants a TStrings as property. But i didn't understand how this can work. Unless i manually change one of the entries there was no change in the property, right? It does not change.
Obvious, because only the ItemIndex changes (beside the visual representation). But ItemIndex is not part of the property.
My intended use is this:
In my model i have some integers (subranges) that i would like to present using constant strings.
I.e. 0 in the model means 'Left channel', 1 means 'Right channel', 3 means 'Both channels' etc.
Just as an experiment i replaced the LinkLoadFromProperty and LinkSaveToProperty methods with modified ones that handles the ItemIndex instead of Itmes.
For now the following works (playcode only):
procedure TForm1.FormCreate(Sender: TObject);
begin
fModel := TModel.Create; // Only to provide the strings to TIComboBox1
...
with TIComboBox1 do
begin
Link.OnLoadFromProperty := @LinkLoadFromProperty;
Link.OnSaveToProperty := @LinkSaveToProperty;
Link.SetObjectAndProperty(SpinEdit1, 'Value'); // SpinEdit1 is "misused" to provide a model property
Items := fModel.fStrings;
if Items.Count > 0 then ItemIndex := 0;
end;
end;
procedure TForm1.LinkLoadFromProperty(Sender: TObject);
var
theOwner: TTICustomComboBox;
theLink: TCustomPropertyLink;
actualIndex: integer;
begin
if Sender=nil then ;
theLink := TCustomPropertyLink(Sender);
if (theLink.Editor = nil) then
exit;
theOwner := TTICustomComboBox(theLink.Owner);
actualIndex := theLink.GetAsInt;
theOwner.ItemIndex:=actualIndex;
end;
procedure TForm1.LinkSaveToProperty(Sender: TObject);
var
theOwner: TTICustomComboBox;
theLink: TCustomPropertyLink;
actualIndex: integer;
begin
if Sender = nil then
;
theLink := TCustomPropertyLink(Sender);
if (theLink.Editor = nil) then
exit;
theOwner := TTICustomComboBox(theLink.Owner);
actualIndex := theOwner.ItemIndex;
theLink.SetAsInt(actualIndex);
end;
But i'm not shure if this is the intended use of that class. Hence i'm looking for examples. But found none, unfortunally ...
So, as usual: Any hints are highly welcome.

Regards
feds