Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Test;
- uses Vcl.Dialogs, Classes;
- type
- TMyArray = array[0..4] of String;
- TStringHash = class
- private
- FKeys : TStringList;
- FValues : Array of TMyArray;
- function GetContent(Key: String; Index : Integer): String;
- procedure SetContent(Key : String; Index : Integer; Value: String);
- public
- property Contents[Key : String; Index : Integer] : String read GetContent write SetContent; Default;
- constructor Create;
- function Count : Integer;
- end;
- constructor TStringHash.Create;
- begin
- inherited;
- FKeys := TStringList.Create;
- FKeys.Add('');
- SetLength(FValues, 1);
- FValues[0][0] := '';
- end;
- function TStringHash.Count: Integer;
- begin
- Result := FKeys.Count;
- end;
- function TStringHash.GetContent(Key: String; Index : Integer) : String;
- var
- I : Integer;
- begin
- Result := '';
- I := FKeys.IndexOf(Key) ;
- if I > -1 then
- Result := FValues[I][Index];
- end;
- procedure TStringHash.SetContent(Key : String; Index : Integer; Value: String);
- var
- I : Integer;
- begin
- I := FKeys.IndexOf(Key) ;
- if I > -1 then
- FValues[I][Index] := Value
- else
- begin
- SetLength(FValues, Length(FValues) + 1);
- FValues[Length(FValues) - 1][Index] := Value;
- FKeys.Add(Key);
- end;
- end;
- var
- MinhaHash : TStringHash;
- begin
- MinhaHash := TStringHash.Create;
- MinhaHash['Teste', 0] := 'Olรก Mundo!';
- ShowMessage(MinhaHash['Teste', 0]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement