RTTI 动态数组 TValue Delphi 2010
我有一个问题。我是来自 Delphi 2010 的运行时类型信息的新手。我需要将动态数组的长度设置为 TValue。你可以看到代码。
Type TMyArray = array of integer;
TMyClass = class
publihed
function Do:TMyArray;
end;
function TMyClass.Do:TMyArray;
begin
SetLength(Result,5);
for i:=0 to 4 Result[i]=3;
end;
.......
.......
......
y:TValue;
Param:array of TValue;
.........
y=Methods[i].Invoke(Obj,Param);//delphi give me a DynArray type kind, is working, Param works to any functions.
if Method[i].ReturnType.TypeKind = tkDynArray then//is working...
begin
I want to set length for y to 10000//i don't know how to write.
end;
我不喜欢泛型集合。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TValue
并不是为任意操作其内容而设计的(如果是的话,它将有更多的帮助器,例如设置记录字段等),而是为在具体静态类型和动态 RTTI 之间传输值而设计。在这方面,TValue.SetArrayElement
是一种异常现象,事后看来,也许不应该包含在内。然而,你问的是可能的:TValue
wasn't designed for arbitrary manipulation of its contents (it would have more helpers for e.g. setting record fields etc. if so), but rather for transporting values between concrete static types and dynamic RTTI. In this respect,TValue.SetArrayElement
is an anomaly, and in hindsight, perhaps should not have been included. However, what you ask is possible: