CnPack Forum


 
Subject: 关于组件包中HashMap存放动态数组的问题!
85860492
新警察
Rank: 1



UID 41462
Digest Posts 0
Credits 4
Posts 1
点点分 4
Reading Access 10
Registered 2008-12-14
Status Offline
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 编辑 ]
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-12-14 16:11  Profile | Blog | P.M. 
FPacketMapping.Add('S0000',@PacketField);改为FPacketMapping.Add('S0000',Pointer(PacketField));试试看?
Top
 




All times are GMT++8, the time now is 2024-11-25 23:59

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008848 second(s), 9 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP