Rev 91 | Rev 93 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 91 | Rev 92 | ||
---|---|---|---|
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-10 |
5 | * Revision 2022-07-11 |
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 88... | Line 88... | ||
88 | //IsSeparator: boolean; |
88 | //IsSeparator: boolean; |
89 | public |
89 | public |
90 | Cont: array[0..VTS_ASCII_TABLE_COLS-1] of string; |
90 | Cont: array[0..VTS_ASCII_TABLE_COLS-1] of string; |
91 | Align: array[0..VTS_ASCII_TABLE_COLS-1] of TAlignment; |
91 | Align: array[0..VTS_ASCII_TABLE_COLS-1] of TAlignment; |
92 | PadChar: array[0..VTS_ASCII_TABLE_COLS-1] of char; |
92 | PadChar: array[0..VTS_ASCII_TABLE_COLS-1] of char; |
- | 93 | DoSum: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
|
93 | procedure Clear; |
94 | procedure Clear; |
94 | procedure SetVal(index: integer; ACont: string; AAlign: TAlignment=taLeftJustify; APadChar: char=' '); |
95 | procedure SetVal(index: integer; ACont: string; AAlign: TAlignment=taLeftJustify; |
- | 96 | APadChar: char=' '; ADoSum: boolean=false); |
|
95 | end; |
97 | end; |
96 | 98 | ||
97 | TVtsAsciiTableAnalysis = record |
99 | TVtsAsciiTableAnalysis = record |
98 | MaxLen: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
100 | MaxLen: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
99 | Used: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
101 | Used: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
Line 137... | Line 139... | ||
137 | procedure TVtsAsciiTable.AddSumLine; |
139 | procedure TVtsAsciiTable.AddSumLine; |
138 | var |
140 | var |
139 | objLine: TVtsAsciiTableLine; |
141 | objLine: TVtsAsciiTableLine; |
140 | j: Integer; |
142 | j: Integer; |
141 | analysis: TVtsAsciiTableAnalysis; |
143 | analysis: TVtsAsciiTableAnalysis; |
- | 144 | found: boolean; |
|
142 | begin |
145 | begin |
143 | objLine := TVtsAsciiTableLine.Create; |
146 | objLine := TVtsAsciiTableLine.Create; |
144 | objLine.IsSumLine := true; |
147 | objLine.IsSumLine := true; |
145 | analysis := GetAnalysis; |
148 | analysis := GetAnalysis; |
- | 149 | found := false; |
|
146 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
150 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
147 | begin |
151 | begin |
148 | if analysis.Sum[j] <> 0 then |
152 | if analysis.Sum[j] <> 0 then |
- | 153 | begin |
|
149 | objLine.SetVal(j, IntToStr(analysis.Sum[j]), taRightJustify, ' '); |
154 | objLine.SetVal(j, IntToStr(analysis.Sum[j]), taRightJustify, ' '); |
- | 155 | found := true; |
|
- | 156 | end; |
|
150 | end; |
157 | end; |
- | 158 | if found then |
|
151 | Inherited Add(objLine); |
159 | Inherited Add(objLine) |
- | 160 | else |
|
- | 161 | objLine.Free; |
|
152 | end; |
162 | end; |
153 | 163 | ||
154 | function TVtsAsciiTable.GetAnalysis: TVtsAsciiTableAnalysis; |
164 | function TVtsAsciiTable.GetAnalysis: TVtsAsciiTableAnalysis; |
155 | var |
165 | var |
156 | j: Integer; |
166 | j: Integer; |
Line 171... | Line 181... | ||
171 | if objLine <> nil then |
181 | if objLine <> nil then |
172 | begin |
182 | begin |
173 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
183 | for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
174 | begin |
184 | begin |
175 | len := Length(objLine.Cont[j]); |
185 | len := Length(objLine.Cont[j]); |
176 | if TryStrToInt(objLine.Cont[j], itmp) then |
186 | if TryStrToInt(objLine.Cont[j], itmp) and objLine.DoSum[j] then |
177 | result.Sum[j] := result.Sum[j] + itmp; |
187 | result.Sum[j] := result.Sum[j] + itmp; |
178 | if len > result.MaxLen[j] then |
188 | if len > result.MaxLen[j] then |
179 | result.MaxLen[j] := len; |
189 | result.MaxLen[j] := len; |
180 | if len > 0 then |
190 | if len > 0 then |
181 | result.Used[j] := true; |
191 | result.Used[j] := true; |
Line 358... | Line 368... | ||
358 | Cont[i] := ''; |
368 | Cont[i] := ''; |
359 | end; |
369 | end; |
360 | end; |
370 | end; |
361 | 371 | ||
362 | procedure TVtsAsciiTableLine.SetVal(index: integer; ACont: string; |
372 | procedure TVtsAsciiTableLine.SetVal(index: integer; ACont: string; |
363 | AAlign: TAlignment=taLeftJustify; APadChar: char=' '); |
373 | AAlign: TAlignment=taLeftJustify; APadChar: char=' '; ADoSum: boolean=false); |
364 | begin |
374 | begin |
365 | Self.Cont[index] := ACont; |
375 | Self.Cont[index] := ACont; |
366 | Self.Align[index] := AAlign; |
376 | Self.Align[index] := AAlign; |
367 | Self.PadChar[index] := APadChar; |
377 | Self.PadChar[index] := APadChar; |
- | 378 | Self.DoSum[index] := ADoSum; |
|
368 | end; |
379 | end; |
369 | 380 | ||
370 | end. |
381 | end. |