Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure GridColAutoSize( Grid:TStringGrid );
var
nCol, nRow, nWidth, nMaxWidth: integer;
begin
with Grid as TStringGrid do
begin
for nCol := 0 to ColCount - 1 do
begin
nMaxWidth := 0;
for nRow := 0 to RowCount - 1 do
begin
nWidth := Canvas.TextWidth( Cells[nCol,nRow] );
if nWidth > nMaxWidth then nMaxWidth := nWidth;
end; {for nRow}
ColWidths[nCol] := nMaxWidth + 7;
end; {for nCol}
end; {with Grid}
end;
procedure TForm1.Button1Click(Sender: TObject);
var
oFileStrings:TStringList;
oRowStrings:TStringList;
i:integer;
begin
oFileStrings := TStringList.Create;
oRowStrings := TStringList.Create;
try
StringGrid1.FixedCols := 1;
StringGrid1.FixedRows := 1;
StringGrid1.RowCount := 2;
StringGrid1.ColCount := 2;
oFileStrings.LoadFromFile('c:\test.csv');
StringGrid1.RowCount := oFileStrings.Count;
for i := 0 to oFileStrings.Count - 1 do
begin
oRowStrings.Clear;
oRowStrings.CommaText := oFileStrings[i];
oRowStrings.Insert(0,IntToStr(i));
if oRowStrings.Count > StringGrid1.ColCount then
StringGrid1.ColCount := oRowStrings.Count;
StringGrid1.Rows[i].Assign(oRowStrings);
end;
StringGrid1.Cells[0,0] := '';
GridColAutoSize( StringGrid1 );
finally
oFileStrings.Free;
oRowStrings.Free;
end;
end;
end.