Subject:
关于组件包中HashMap存放动态数组的问题!
[Print This Page]
Author:
85860492
Time:
2008-12-14 12:50
Subject:
关于组件包中HashMap存放动态数组的问题!
我有这样一个实现:
在对象的初始化时初始化一个存放动态数组的HashMap,但是在获取内容时总是为空。我的代码
type
TPacketFieldArray = Array of String ;
PPacketFieldArray = ^TPacketFieldArray;
TMyObject = Class(TObject)
public
constructor Create();
destructor Destroy; override;
private
FPacketMapping:
TCnStrToPtrHashMap
;
procedure init;
。。。。。。。。。
constructor TMyObject .Create;
begin
Init;
end;
destructor TMyObject .Destroy;
begin
FreeAndNil(FPacketMapping);
inherited;
end;
procedure TTransformer.init;
var
PacketField:TPacketFieldArray;
begin
try
FPacketMapping := TCnStrToPtrHashMap.Create(5);
SetLength(PacketField,2);
PacketField[0] := 'CommandId';
PacketField[1] := 'Code';
FPacketMapping.Add('S0000',@PacketField);
SetLength(PacketField,2);
PacketField[0] := 'CommandId';
PacketField[1] := 'Data';
FPacketMapping.Add('R0000',@PacketField);
.............//放入多个动态数组
except
FreeAndNil(FPacketMapping);
raise;
end;
end;
////////////////在方法中使用上面初始化的Map
var
PArray Pointer;
TempS:String;
begin
FPacketMapping.Find('S'+CommandId,PArray);
if Assigned(PArray)then
begin
PF := PPacketFieldArray(PArray);
for i:=Low(PF^) to High(PF^)do
begin
TempS := TempS+'|'+PF^
;
end;
end;
end;
问题:为什么获取的动态数字不可以操作!并未 初始化,能给出个建议的做法吗?谢谢!!!!!
[
本帖最后由 85860492 于 2008-12-14 12:51 编辑
]
Author:
Passion
Time:
2008-12-14 16:11
FPacketMapping.Add('S0000',@PacketField);改为FPacketMapping.Add('S0000',Pointer(PacketField));试试看?
Welcome to CnPack Forum (http://bbs.cnpack.org/)
Powered by Discuz! 5.0.0