-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArrayAssoc.pas
More file actions
124 lines (102 loc) · 2.31 KB
/
Copy pathArrayAssoc.pas
File metadata and controls
124 lines (102 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
unit ArrayAssoc;
{$WARNINGS OFF}
{$HINTS OFF}
interface
uses
System.Classes, System.SysUtils, System.Generics.Collections,
System.RTLConsts;
type
TArray = class(TStringList)
private
function GetValues(Index: string): string;
function GetValuesAtIndex(Index: Integer): string;
procedure SetValues(Index: string; const Value: string);
public
constructor Create;
destructor Destroy; override;
function ToFilter: string;
function ToString: string;
procedure AddKeyValue(Key, Value: string);
property ValuesAtIndex[Index: Integer]: string read GetValuesAtIndex;
property Values[Index: string]: string read GetValues
write SetValues; default;
end;
{ TRows em Desuso }
type
TRows = class(TList)
private
function GetData(Index: Integer): TArray;
procedure SetData(Index: Integer; const Value: TArray);
public
property Data[Index: Integer]: TArray read GetData write SetData; default;
destructor Destroy; override;
end;
implementation
{ TArray }
procedure TArray.AddKeyValue(Key, Value: string);
begin
Add(Key + NameValueSeparator + Value);
end;
constructor TArray.Create;
begin
NameValueSeparator := '|';
end;
destructor TArray.Destroy;
begin
inherited;
end;
function TArray.ToFilter: string;
var
I: Integer;
begin
Result := '';
for I := 0 to Count - 1 do
begin
Result := Result + Names[I] + ' ' + ValuesAtIndex[I] + ' ';
end;
end;
function TArray.ToString: string;
var
I: Integer;
Return: String;
begin
Return := '';
for I := 0 to Count - 1 do
begin
Return := Return + ValuesAtIndex[I];
end;
Return := Copy(Return, 1, Length(Return) - 1);
Result := Return;
end;
function TArray.GetValues(Index: string): string;
begin
Result := inherited Values[Index];
end;
function TArray.GetValuesAtIndex(Index: Integer): string;
begin
Result := inherited Values[Names[Index]];
end;
procedure TArray.SetValues(Index: string; const Value: string);
begin
inherited Values[Index] := Value;
end;
{ TRows }
destructor TRows.Destroy;
var
I: Integer;
begin
for I := 0 to Count - 1 do
Data[I].Free;
inherited;
end;
function TRows.GetData(Index: Integer): TArray;
begin
Result := Items[Index];
end;
procedure TRows.SetData(Index: Integer; const Value: TArray);
begin
Items[Index] := Value;
end;
{$WARNINGS ON}
{$HINTS ON}
end.