Hi experts:
There is a hash pas file http://gpdelphiunits.googlecode.com/svn-history/r4/trunk/src/GpStringHash.pas
We can create hash and add key - value
Question 1: We want to know how to iterate key - value and copy data to listview.
Question 2: is there a way to fast copy like assign method to it?
Thank you very much in advance.
Dear gabr, Thank you so much for your immediate reply and your hash file. Is there doc or help files or examples or demo for your code ? Thank you so much again.
Just test, I do not know where i did wrong Thank you so much. I just used your code but there is the following error prompt. Or I made some mistakes:
procedure TForm8.ab;
var
a: TGpStringHash;
i,j, fr:integer;
k: string;
enlist: TGpStringHashenumerator;
kv: TGpStringHashKV;
begin
a:=TGpStringHash.Create;
kv:=TGpStringHashKV.Create;
enlist:= TGpStringHashenumerator.Create(a);
for j:=1 to 10 do begin
if a.HasKey(inttostr(j)) then begin
fr:=a.ValueOf(inttostr(j));
a.Update(inttostr(j),fr+1);
end
else begin
a.Add(inttostr(j),1);
end;
end;
for i:=0 to a.Count -1 do begin
kv:=enlist.GetCurrent;
memo1.Lines.Add(kv.Key + inttostr(kv.value) );
end;
end; /// Division by Zero ERROr ///FindBucket(const key: string): cardinal;
ANSWER: You're using enumerator improperly. Don't instantiate it in front and always use MoveNext to move to the next element.
// fill 'a' as above
enlist := TGpStringHashenumerator.Create(a);
while enList.MoveNext do begin
kv:=enlist.GetCurrent;
memo1.Lines.Add(kv.Key + inttostr(kv.value) );
end;