Reputation:
How do you get the value that has been entered into the JvInspector at runtime?
The Demo in \..\jvcl\examples\JvInspector
shows how to add strings, by writing something like this (extract from the demo):
var
FirstName: string;
implementation
procedure TfrmInspector.AddVarious;
var
InspCat: TJvInspectorCustomCategoryItem;
begin
TJvInspectorVarData.New(InspCat, 'First', TypeInfo(string), @FirstName).DisplayName := 'Copy of first name';
end;
I wanted to add a TColor property so I did this:
var
FirstName: string;
SomeColor: TColor;
implementation
procedure TfrmInspector.AddVarious;
var
InspCat: TJvInspectorCustomCategoryItem;
begin
TJvInspectorVarData.New(InspCat, 'First', TypeInfo(string), @FirstName).DisplayName := 'Copy of first name';
TJvInspectorVarData.New(InspCat, 'SomeColor', TypeInfo(TColor), @SomeColor;
end;
This displays correctly but I cannot seem to get the value that is changed for SomeColor when selecting a new color from the dropdown list in the inspector.
I tried this:
procedure TfrmInspector.JvInspector1ItemValueChanged(Sender: TObject;
Item: TJvCustomInspectorItem);
begin
if (Item.Data <> nil) and (CompareText(Item.Data.Name, 'FirstName') = 0) then
ShowMessage(Item.Data.AsString) //< works
else if (Item.Data <> nil) and (CompareText(Item.Data.Name, 'SomeColor') = 0) then
ShowMessage(ColorToString(TColor(Item.Data))); //< does not return correct value
end;
I don't normally use Jedi components but thought I would give them another chance but there seems to be little documentation, I looked on the Wiki page for OnItemValueChanged event: http://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvInspector.OnItemValueChanged but again barely any information or help.
I am sure instead of trying to get ColorToString(TColor(Item.Data))
I need to use Item.Data.AsVariant
but I could be wrong, when I tried I got AV errors so I probably am totally wrong, nothing I ever do or try seems to work :(
Upvotes: 1
Views: 1224
Reputation: 163257
The Item.Data
property is an object reference of type TJvCustomInspectorData
; type-casting it to TColor
yields nonsense. TColor
is an ordinal type, so use the AsOrdinal
method just as the string code uses AsString
:
ShowMessage(ColorToString(TColor(Item.Data.AsOrdinal)));
Alternatively, you should just be able to read from the global SomeColor
variable you passed when you created the item in the first place.
Upvotes: 2
Reputation:
I found one way that works:
procedure TfrmInspector.JvInspector1ItemValueChanged(Sender: TObject;
Item: TJvCustomInspectorItem);
var
sVal: string;
begin
if (Item.Data <> nil) then
begin
sVal := Item.DisplayValue;
if (CompareText(Item.Data.Name, 'FirstName') = 0) then
ShowMessage('FirstName Value: ' + sVal)
else if (CompareText(Item.Data.Name, 'SomeColor') = 0) then
ShowMessage('SomeColor Value: ' + sVal); //<can use StringToColor now
end;
end;
Though probably not the best way I thought I would post it anyway.
Upvotes: 0