source: branches/DirectWeb/UAssociativeArray.pas

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