记录类型转换成Variant类型的困惑

lifejoy 2003-06-20 10:42:12
如何将一个记录类型转换成Variant类型.
这是在Com的连接点的时候出现的问题。在D5中在类型库中声明的记录类型的参数
当把把类型库作为事件源的时候产生的代码为Variant我应该如何转换呢?
TARec=record
a:widestring;
b:widestring;
c:widestring;
end
这样的一个变量ARec如何转换成Variant呢?
...全文
65 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lvloj 2003-07-14
  • 打赏
  • 举报
回复
lifejoy(活着的穿马甲中) :
用 dolphin2001(抢包山) 的办法即可,不过TARec必须是ShortString类型
TARec=record
a:ShortString;
b:ShortString;
c:ShortString;
end
lifejoy 2003-06-23
  • 打赏
  • 举报
回复
thks
dolphin2001 2003-06-21
  • 打赏
  • 举报
回复
TARec=record
a:widestring;
b:widestring;
c:widestring;
end


// TARec ---> Variant
function RecordToVariant(value:TARec):OleVariant;
var
P:Pointer;
begin
Result := VarArrayCreate([0,sizeof(TARec)],varByte);
P := VarArrayLock(Result);
Move(value,P^,sizeof(P));
VarArrayUnlock(Result);
end;


// OleVariant ----> TARec
function VariantToRecord(value:OleVariant):TARec;
var
P:Pointer;
begin
P:= VarArrayLock(value);
Move(P^,Result,sizeof(TARec));
VarArrayUnlock(value);
end;
lifejoy 2003-06-20
  • 打赏
  • 举报
回复
我需要的是
v:Variant;
我要用v来表示ARec
erp2 2003-06-20
  • 打赏
  • 举报
回复
TVar=record
a:variant;
b:variant;
c:variant;
end;
TARec:=TVar;
hiflower 2003-06-20
  • 打赏
  • 举报
回复
变通办法:

TYourRecord=class
a:Integer;
b:Integer;
end;
TYourVarData = packed record
VType: TVarType;
Reserved1, Reserved2, Reserved3: Word;
VComplex: TYourRecord;
Reserved4: LongInt;
end;

var
d:TYourVarData;
v:Variant;

v:=Variant(d);
hiflower 2003-06-20
  • 打赏
  • 举报
回复
By default, Variants can hold values of any type except records, sets, static arrays, files, classes, class references, and pointers. In other words, variants can hold anything but structured types and pointers. They can hold interfaces, whose methods and properties can be accessed through them. (See Object interfaces.) They can hold dynamic arrays, and they can hold a special kind of static array called a variant array. (See Variant arrays.) Variants can mix with other variants and with integer, real, string, and Boolean values in expressions and assignments; the compiler automatically performs type conversions.

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧