Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
CnVCL 组件包
» 关于组件包中HashMap存放动态数组的问题!
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: 关于组件包中HashMap存放动态数组的问题!
85860492
新警察
UID 41462
Digest Posts 0
Credits 4
Posts 1
点点分 4
Reading Access 10
Registered 2008-12-14
Status Offline
#1
Post at 2008-12-14 12:50
Profile
|
Blog
|
P.M.
关于组件包中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 编辑
]
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#2
Post at 2008-12-14 16:11
Profile
|
Blog
|
P.M.
FPacketMapping.Add('S0000',@PacketField);改为FPacketMapping.Add('S0000',Pointer(PacketField));试试看?
Poll
Trade
Reward
Activity
CnPack Forum
CnPack English Forum
> CnWizards IDE Wizards
> CVSTracNT
> Announcements & Others
All times are GMT++8, the time now is 2024-11-22 12:45
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.013613 second(s), 8 queries , Gzip enabled
TOP
Clear Cookies
-
Contact Us
-
CnPack Website
-
Archiver
-
WAP
Member's CP Home
Edit Profile
Credits Transaction
Public User Groups
Buddy List
Main
Page Views
User Agents
Posts History
Top Forums
Top Threads
Post Ranking
Credit Ranking
Online Time
Team
Moderation Stats