1,8 → 1,11 |
unit AsciiTable; |
|
// Download: |
// https://github.com/danielmarschall/delphiutils/blob/master/Units/AsciiTable.pas |
|
(* |
* ASCII Table and CSV Generator Delphi Unit |
* Revision 2022-07-15 |
* Revision 2023-12-08 |
* |
* (C) 2022 Daniel Marschall, HickelSOFT, ViaThinkSoft |
* Licensed under the terms of Apache 2.0 |
21,6 → 24,7 |
objLine: TVtsAsciiTableLine; |
begin |
VirtTable := TVtsAsciiTable.Create(true); |
try |
VirtTable.Clear; |
|
// Create Test data |
67,9 → 71,10 |
|
// Save CSV |
VirtTable.SaveCSV('Order.csv'); |
|
VirtTable.Free; |
finally |
FreeAndNil(VirtTable); |
end; |
end; |
|
} |
|
99,7 → 104,7 |
TVtsAsciiTableAnalysis = record |
MaxLen: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
Used: array[0..VTS_ASCII_TABLE_COLS-1] of boolean; |
Sum: array[0..VTS_ASCII_TABLE_COLS-1] of integer; |
Sum: array[0..VTS_ASCII_TABLE_COLS-1] of extended; |
end; |
|
TVtsAsciiTable = class(TObjectList{<TVtsAsciiTableLine>}) |
125,6 → 130,9 |
|
implementation |
|
uses |
Math; |
|
{ TVtsAsciiTable } |
|
function TVtsAsciiTable.Add(AObject: TVtsAsciiTableLine): Integer; |
152,7 → 160,7 |
begin |
if analysis.Sum[j] <> 0 then |
begin |
objLine.SetVal(j, IntToStr(analysis.Sum[j]), taRightJustify, ' '); |
objLine.SetVal(j, FloatToStr(RoundTo(analysis.Sum[j],2)), taRightJustify, ' '); |
found := true; |
end; |
end; |
159,7 → 167,7 |
if found then |
Inherited Add(objLine) |
else |
objLine.Free; |
FreeAndNil(objLine); |
end; |
|
function TVtsAsciiTable.GetAnalysis: TVtsAsciiTableAnalysis; |
168,7 → 176,7 |
i: Integer; |
objLine: TVtsAsciiTableLine; |
len: Integer; |
itmp: integer; |
itmp: extended; |
begin |
for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
begin |
184,7 → 192,7 |
for j := 0 to VTS_ASCII_TABLE_COLS-1 do |
begin |
len := Length(objLine.Cont[j]); |
if TryStrToInt(objLine.Cont[j], itmp) and objLine.DoSum[j] then |
if TryStrToFloat(RoundTo(objLine.Cont[j],2), itmp) and objLine.DoSum[j] then |
result.Sum[j] := result.Sum[j] + itmp; |
if len > result.MaxLen[j] then |
result.MaxLen[j] := len; |