|
Last change
on this file was 82, checked in by george, 16 years ago |
- Přidáno: Výchozí zdrojové kódy pro http server ve free pascalu.
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | unit UAssociativeArray;
|
|---|
| 2 |
|
|---|
| 3 | {$mode Delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | TAssociativeArray = class(TStringList)
|
|---|
| 12 | private
|
|---|
| 13 | function GetValues(Index: string): string;
|
|---|
| 14 | function GetValuesAtIndex(Index: Integer): string;
|
|---|
| 15 | procedure SetValues(Index: string; const Value: string);
|
|---|
| 16 | public
|
|---|
| 17 | constructor Create;
|
|---|
| 18 | destructor Destroy; override;
|
|---|
| 19 | function GetAllValues: string;
|
|---|
| 20 | procedure AddKeyValue(Key, Value: string);
|
|---|
| 21 | property ValuesAtIndex[Index: Integer]: string read GetValuesAtIndex;
|
|---|
| 22 | property Values[Index: string]: string read GetValues write SetValues; default;
|
|---|
| 23 | end;
|
|---|
| 24 |
|
|---|
| 25 | implementation
|
|---|
| 26 |
|
|---|
| 27 | { TAssociativeArray }
|
|---|
| 28 |
|
|---|
| 29 | procedure TAssociativeArray.SetValues(Index: string; const Value: string);
|
|---|
| 30 | begin
|
|---|
| 31 | inherited Values[Index] := Value;
|
|---|
| 32 | end;
|
|---|
| 33 |
|
|---|
| 34 | procedure TAssociativeArray.AddKeyValue(Key, Value: string);
|
|---|
| 35 | begin
|
|---|
| 36 | Add(Key + NameValueSeparator + Value);
|
|---|
| 37 | end;
|
|---|
| 38 |
|
|---|
| 39 | constructor TAssociativeArray.Create;
|
|---|
| 40 | begin
|
|---|
| 41 | NameValueSeparator := '|';
|
|---|
| 42 | end;
|
|---|
| 43 |
|
|---|
| 44 | destructor TAssociativeArray.Destroy;
|
|---|
| 45 | begin
|
|---|
| 46 | inherited;
|
|---|
| 47 | end;
|
|---|
| 48 |
|
|---|
| 49 | function TAssociativeArray.GetAllValues: string;
|
|---|
| 50 | var
|
|---|
| 51 | I: Integer;
|
|---|
| 52 | begin
|
|---|
| 53 | Result := '';
|
|---|
| 54 | for I := 0 to Count - 1 do begin
|
|---|
| 55 | Result := Result + Names[I] + '=' + ValuesAtIndex[I] + ',';
|
|---|
| 56 | end;
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | function TAssociativeArray.GetValues(Index: string): string;
|
|---|
| 60 | begin
|
|---|
| 61 | Result := inherited Values[Index];
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | function TAssociativeArray.GetValuesAtIndex(Index: Integer): string;
|
|---|
| 65 | begin
|
|---|
| 66 | Result := inherited Values[Names[Index]];
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | end.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.