Delphi 'Could not convert variant type (UnicodeString) to type (Boolean)
I have this code for color row of grid based on column data (grid from devexpress)
var
AColumn: TcxCustomGridTableItem;
gs: variant;
begin
AColumn := (Sender as TcxGridDBTableView).GetColumnByFieldName('COLOR');
gs := ARecord.Values[AColumn.Index];
if VarType(gs) and VarTypeMask = varString or varUString then
AStyle.Color := gs; //<<<----- exception
The field color
is a varchar (firebird) containing values like cllime, clred, etc. but I get the error "Could not convert variant of type (UnicodeString) to type (Boolean)" on the line with the exception comment. what should I change?
thank
+3
source to share
1 answer
I would replace your operator with the if
following. It uses a function VarIsType
that is more straightforward to type-check the Variant and converts the string value stored in the Variant variable to color with StringToColor
:
...
if VarIsType(gs, [varString, varUString]) then
AStyle.Color := StringToColor(gs);
+9
source to share