demo 一个
procedure TForm1.Button1Click(Sender: TObject);
type
TData = record
S: string;
end;
PData = ^TData;
var
P: PData;
I, nIndex: Integer;
begin
with THashedStringList.Create do
try
P := AllocMem(SizeOf(TData));
P.S := 'asdasd';
AddObject('123', TObject(P));
P := AllocMem(SizeOf(TData));
P.S := 'qwe';
AddObject('234', TObject(P));
nIndex := IndexOf('123');
if nIndex >= 0 then Caption := PData(Objects[nIndex])^.S;
finally
for I := 0 to Count - 1 do
begin
PData(Objects)^.S := '';
FreeMem(PData(Objects));
end;
Free;
end;
end;
不过个人还是喜欢自己写 TMyObject、TMyObjectList,使用 TObjectList 管理。
还是 .net 的泛型好啊 . ;>