gpt4 book ai didi

Delphi'无法将类型(UnicodeString)的变体转换为类型( bool )

转载 作者:行者123 更新时间:2023-12-03 15:43:33 26 4
gpt4 key购买 nike

我有这段代码可以根据列数据为网格行着色(网格来自 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

字段 color 是 varchar (firebird),包含 cllime、clred 等值...但我在带有异常注释的行收到错误“无法将类型 (UnicodeString) 的变体转换为类型 (Boolean)”。我应该改变什么?

谢谢

最佳答案

我将用以下内容替换您的 if 语句。它使用 VarIsType函数,这对于 Variant 类型检查来说更直接,它使用 StringToColor 将存储在 Variant 变量中的字符串值转换为颜色。功能:

...
if VarIsType(gs, [varString, varUString]) then
AStyle.Color := StringToColor(gs);

关于Delphi'无法将类型(UnicodeString)的变体转换为类型( bool ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14563862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com