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

lifejoy 2003-06-20 10:42:12
如何将一个记录类型转换成Variant类型.
这是在Com的连接点的时候出现的问题。在D5中在类型库中声明的记录类型的参数
当把把类型库作为事件源的时候产生的代码为Variant我应该如何转换呢?
TARec=record
a:widestring;
b:widestring;
c:widestring;
end
这样的一个变量ARec如何转换成Variant呢?
...全文
33 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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.
回复
相关推荐
发帖
网络通信/分布式开发
创建于2007-08-02

1573

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2003-06-20 10:42
社区公告
暂无公告