Delphi的object Pascal里面有没有类似Map的数据结构,就是给定一个Key(String类型)可以找到对应的value。
例如
value1:=map('key1');
value2:=map('key2');
或者那位大侠已经实现了这种功能的类,也发出来共享一下吧
例如
value1:=map('key1');
value2:=map('key2');
或者那位大侠已经实现了这种功能的类,也发出来共享一下吧
解决方案 »
- RMB请人写注册表权限操作程序,价格好说,具体面议
- 怎样让树型的节点Tlable(treeview1.selected.data).caption)支持SQL语句?
- 求程序启动从服务器下载数据的实现方法!
- 高手请进(INI问题)
- 请教 事务问题
- 关于components的问题!
- 我有一个问题,高手帮忙,急,关于数值的问题
- 奇怪,TQuery,用BDE连接Sybase,EOF,BOF,IsEmpty不起作用?看里面:
- WebBrowser1粘贴问题
- 遇到这问题,真伤脑筋.您说该......
- 怎样才能点击关闭按钮(就那个叉叉)后让它产生Application.Terminate的效果?
- 请教高手:delphi 中存储过程的使用
unit UnitHasedTable;interface
uses
Classes;type
TStringHashedTable = class(TPersistent)
FKeyList: TStrings;
FStrList: TStrings;
private
function GetItems(Key: string): string;
procedure SetItems(Key: string; const Value: string);
function GetCount: Integer;
public
constructor Create;
destructor Destroy; override;
property Items[Key: string]: string read GetItems write SetItems; default;
property Count: Integer read GetCount;
procedure Add(Key, Str: string);
procedure Delete(Key:String); end;implementation{ TStringHashedTable }procedure TStringHashedTable.Add(Key, Str: string);
begin
if FKeyList.IndexOf(Key) <> -1 then
begin Exit;
end;
FKeyList.Add(Key);
FStrList.Add(Str);
end;constructor TStringHashedTable.Create;
begin FKeyList := TStringList.Create;
FStrList := TStringList.Create;
end;procedure TStringHashedTable.Delete(Key:String);
var
KeyIndex:Integer;
begin
KeyIndex := FKeyList.IndexOf(Key);
FKeyList.Delete(KeyIndex);
FStrList.Delete(KeyIndex);
end;destructor TStringHashedTable.Destroy;
begin
FStrList.Free;
FKeyList.Free;
inherited Destroy;
end;function TStringHashedTable.GetCount: Integer;
begin
Result := FKeyList.Count;
end;function TStringHashedTable.GetItems(Key: string): string;
var
KeyIndex : Integer;
begin
KeyIndex :=FKeyList.IndexOf(Key);
Result := FStrList[KeyIndex];
end;procedure TStringHashedTable.SetItems(Key: string; const Value: string);
var
KeyIndex : Integer;
begin
KeyIndex :=FKeyList.IndexOf(Key);
FStrList[KeyIndex] := Value;
end;end.
------------------------------
用法
------------------------------
var
FHT:TStringHashedTable;
Msg:String;
begin
FHT:=TStringHashedTable.Create;
FHT.Add('Key1','aaa');
FHT.Add('Key2','aaabbb');
FHT.Add('Key3','aaaccc');
Msg:= FHT['Key3'];
ShowMessage(Msg);
FHT.Free;
end;