Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi 'Could not convert variant of type (UnicodeString) into type (Boolean)

Tags:

delphi

I have this code to color grid row based on column data (the grid is 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 varchar (firebird) contain values like cllime, clred, etc... but I get error 'Could not convert variant of type (UnicodeString) into type (Boolean)' at the line with exception comment. what should I change ?

Thanks

like image 751
zac Avatar asked Dec 20 '25 01:12

zac


1 Answers

I would replace your if statement with the following. It uses the VarIsType function, which is more straight for Variant type checking and it converts string value stored in your Variant variable to color by using the StringToColor function:

...
if VarIsType(gs, [varString, varUString]) then
  AStyle.Color := StringToColor(gs);
like image 147
TLama Avatar answered Dec 21 '25 16:12

TLama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!