Rev 90 | Rev 92 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 90 | Rev 91 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit AsciiTable; |
1 | unit AsciiTable; |
2 | 2 | ||
3 | (* |
3 | (* |
4 | * ASCII Table and CSV Generator Delphi Unit |
4 | * ASCII Table and CSV Generator Delphi Unit |
5 | * Revision 2022-07-09 |
5 | * Revision 2022-07-10 |
6 | * |
6 | * |
7 | * (C) 2022 Daniel Marschall, HickelSOFT, ViaThinkSoft |
7 | * (C) 2022 Daniel Marschall, HickelSOFT, ViaThinkSoft |
8 | * Licensed under the terms of Apache 2.0 |
8 | * Licensed under the terms of Apache 2.0 |
9 | *) |
9 | *) |
10 | 10 | ||
Line 49... | Line 49... | ||
49 | objLine := TVtsAsciiTableLine.Create; |
49 | objLine := TVtsAsciiTableLine.Create; |
50 | objLine.SetVal(0, 'Asparagus (white)', taLeftJustify); |
50 | objLine.SetVal(0, 'Asparagus (white)', taLeftJustify); |
51 | objLine.SetVal(1, '999', taRightJustify); |
51 | objLine.SetVal(1, '999', taRightJustify); |
52 | VirtTable.Add(objLine); |
52 | VirtTable.Add(objLine); |
53 | 53 | ||
- | 54 | VirtTable.AddSeparator; |
|
- | 55 | VirtTable.AddSumLine; |
|
- | 56 | ||
54 | // Create ASCII table |
57 | // Create ASCII table |
55 | Memo1.Clear; |
58 | Memo1.Clear; |
56 | VirtTable.GetASCIITable(Memo1.Lines); |
59 | VirtTable.GetASCIITable(Memo1.Lines); |
57 | 60 | ||
58 | // Save ASCII table |
61 | // Save ASCII table |
Line 78... | Line 81... | ||
78 | const |
81 | const |
79 | VTS_ASCII_TABLE_COLS = 10; |
82 | VTS_ASCII_TABLE_COLS = 10; |
80 | 83 | ||
81 | type |
84 | type |
82 | TVtsAsciiTableLine = class(TObject) |
85 | TVtsAsciiTableLine = class(TObject) |
- | 86 | private |
|
- | 87 | IsSumLine: boolean; |
|
- | 88 | //IsSeparator: boolean; |
|
83 | public |
89 | public |
84 | Cont: array[0..VTS_ASCII_TABLE_COLS-1] of string; |
90 | Cont: array[0..VTS_ASCII_TABLE_COLS-1] of string; |
85 | Align: array[0..VTS_ASCII_TABLE_COLS-1] of TAlignment; |
91 | Align: array[0..VTS_ASCII_TABLE_COLS-1] of TAlignment; |
86 | PadChar: array[0..VTS_ASCII_TABLE_COLS-1] of char; |
92 | PadChar: array[0..VTS_ASCII_TABLE_COLS-1] of char; |
87 | procedure Clear; |
93 | procedure Clear; |
Line 89... | Line 95... | ||
89 | end; |
95 | end; |
90 | 96 | ||
91 | TVtsAsciiTableAnalysis = record |
97 | TVtsAsciiTableAnalysis = record |
92 | MaxLen: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
98 | MaxLen: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
93 | Used: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
99 | Used: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
94 | Width: integer; |
100 | Sum: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
95 | end; |
101 | end; |
96 | 102 | ||
97 | TVtsAsciiTable = class(TObjectList{<TVtsAsciiTableLine>}) |
103 | TVtsAsciiTable = class(TObjectList{<TVtsAsciiTableLine>}) |
98 | private |
104 | private |
99 | function GetItem(Index: Integer): TVtsAsciiTableLine; |
105 | function GetItem(Index: Integer): TVtsAsciiTableLine; |
Line 104... | Line 110... | ||
104 | procedure SaveASCIITable(filename: string; spaceBetween: integer=3); |
110 | procedure SaveASCIITable(filename: string; spaceBetween: integer=3); |
105 | procedure GetCSV(sl: TStrings); |
111 | procedure GetCSV(sl: TStrings); |
106 | procedure SaveCSV(filename: string); |
112 | procedure SaveCSV(filename: string); |
107 | 113 | ||
108 | procedure AddSeparator; |
114 | procedure AddSeparator; |
- | 115 | procedure AddSumLine; |
|
109 | 116 | ||
110 | // Just a little bit type-safe... The rest stays TObject for now |
117 | // Just a little bit type-safe... The rest stays TObject for now |
111 | function Add(AObject: TVtsAsciiTableLine): Integer; reintroduce; |
118 | function Add(AObject: TVtsAsciiTableLine): Integer; reintroduce; |
112 | property Items[Index: Integer]: TVtsAsciiTableLine read GetItem write SetItem; |
119 | property Items[Index: Integer]: TVtsAsciiTableLine read GetItem write SetItem; |
113 | procedure Insert(Index: Integer; AObject: TVtsAsciiTableLine); reintroduce; |
120 | procedure Insert(Index: Integer; AObject: TVtsAsciiTableLine); reintroduce; |
Line 125... | Line 132... | ||
125 | procedure TVtsAsciiTable.AddSeparator; |
132 | procedure TVtsAsciiTable.AddSeparator; |
126 | begin |
133 | begin |
127 | Inherited Add(nil); |
134 | Inherited Add(nil); |
128 | end; |
135 | end; |
129 | 136 | ||
- | 137 | procedure TVtsAsciiTable.AddSumLine; |
|
- | 138 | var |
|
- | 139 | objLine: TVtsAsciiTableLine; |
|
- | 140 | j: Integer; |
|
- | 141 | analysis: TVtsAsciiTableAnalysis; |
|
- | 142 | begin |
|
- | 143 | objLine := TVtsAsciiTableLine.Create; |
|
- | 144 | objLine.IsSumLine := true; |
|
- | 145 | analysis := GetAnalysis; |
|
- | 146 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
|
- | 147 | begin |
|
- | 148 | if analysis.Sum[j] <> 0 then |
|
- | 149 | objLine.SetVal(j, IntToStr(analysis.Sum[j]), taRightJustify, ' '); |
|
- | 150 | end; |
|
- | 151 | Inherited Add(objLine); |
|
- | 152 | end; |
|
- | 153 | ||
130 | function TVtsAsciiTable.GetAnalysis: TVtsAsciiTableAnalysis; |
154 | function TVtsAsciiTable.GetAnalysis: TVtsAsciiTableAnalysis; |
131 | var |
155 | var |
132 | j: Integer; |
156 | j: Integer; |
133 | i: Integer; |
157 | i: Integer; |
134 | objLine: TVtsAsciiTableLine; |
158 | objLine: TVtsAsciiTableLine; |
135 | len: Integer; |
159 | len: Integer; |
- | 160 | itmp: integer; |
|
136 | begin |
161 | begin |
137 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
162 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
138 | begin |
163 | begin |
139 | result.MaxLen[j] := 0; |
164 | result.MaxLen[j] := 0; |
140 | result.Used[j] := false; |
165 | result.Used[j] := false; |
- | 166 | result.Sum[j] := 0; |
|
141 | end; |
167 | end; |
142 | for i := 0 to Self.Count-1 do |
168 | for i := 0 to Self.Count-1 do |
143 | begin |
169 | begin |
144 | objLine := Self.items[i] as TVtsAsciiTableLine; |
170 | objLine := Self.items[i] as TVtsAsciiTableLine; |
145 | if objLine <> nil then |
171 | if objLine <> nil then |
146 | begin |
172 | begin |
147 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
173 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
148 | begin |
174 | begin |
149 | len := Length(objLine.Cont[j]); |
175 | len := Length(objLine.Cont[j]); |
- | 176 | if TryStrToInt(objLine.Cont[j], itmp) then |
|
- | 177 | result.Sum[j] := result.Sum[j] + itmp; |
|
150 | if len > result.MaxLen[j] then |
178 | if len > result.MaxLen[j] then |
151 | result.MaxLen[j] := len; |
179 | result.MaxLen[j] := len; |
152 | if len > 0 then |
180 | if len > 0 then |
153 | result.Used[j] := true; |
181 | result.Used[j] := true; |
154 | end; |
182 | end; |
Line 257... | Line 285... | ||
257 | //sl.Clear; |
285 | //sl.Clear; |
258 | for i := 0 to Self.Count-1 do |
286 | for i := 0 to Self.Count-1 do |
259 | begin |
287 | begin |
260 | objLine := Self.items[i] as TVtsAsciiTableLine; |
288 | objLine := Self.items[i] as TVtsAsciiTableLine; |
261 | if objLine = nil then continue; |
289 | if objLine = nil then continue; |
- | 290 | if objLine.IsSumLine then continue; |
|
262 | sLine := ''; |
291 | sLine := ''; |
263 | firstcol := true; |
292 | firstcol := true; |
264 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
293 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
265 | begin |
294 | begin |
266 | if not analysis.Used[j] then continue; |
295 | if not analysis.Used[j] then continue; |