TAdvStringGrid

Example 50 : (ab)using TAdvStringGrid for console type sort / file conversion apps

Sometimes it's great when the boss walks in and gives some specifications for a small application, you can call him back within 10 minutes with a solution.

Today is such a day and the boss walks in asking for an application that will give him sorted HTML files resulting from CSV files sent by the customer. As this should be processed automatically from an existing script, this should be a console application. Time to fire up Delphi, create an instance of TAdvStringGrid, load the CSV file, sort it and save it as HTML. Compile & done. Here is the result:

program asg50;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  AdvGrid;

var
  asg: TAdvStringGrid;
  c,err: Integer;

begin
  if ParamCount <> 3 then
    writeln('Use : ASG50 "Sort column" "Input CSV-filename" "Output HTML-filename"')
  else
  begin
    val(paramstr(1),c,err);

  if err= 0 then
  begin

    asg := TAdvStringGrid.Create(nil);

    asg.SaveFixedCells := False;
    asg.LoadFromCSV(paramstr(2));
    asg.SortSettings.AutoFormat := False;
    asg.SortSettings.Column := c;

    asg.QuickSort(c,1,asg.RowCount - 1);

    asg.SaveToHTML(paramstr(3));

    asg.Free;
  end
  else
  begin
     writeln('Use : ASG50 "SortColumn" "Input CSV-filename" "Output CSV-filename"');
     writeln('with SorColumn valid zero based column index');
  end;

end;


end.


Delphi project & source files for downloading included in the main demos distribution for Delphi.