function Min(const A,B:Integer):Integer;inline;
begin
if A<B then Result := A else Result := B;
end;
procedure SetupGrid(const aGrid:TStringGrid; aColumnNumber, aRowNumber:Integer;aColumnTitles:array of String);
begin
aGrid.FixedCols := 1;
aGrid.FixedRows := 1;
aGrid.RowCount := aRowNumber +1; //one extra row for the column headers
aGrid.ColCount := aColumnNumber+1;//one extra column for the row fixed cell
aGrid.ColWidths[0] := 10;
for vCntr := 1 to Min(High(aColumnTitles)+1,aColumnNumber) do begin // column 0 is a fixed column the gray cells you see on the left.
//row 0 = fixed row the column titles the gray cell you see on top.
aGrid.Cells[vCntr,0] := aColumnTitles[vCntr-1]; //column 1 get title at index 0, column 2 get title at index 1 .... column N gets title at index N-1
end;
end;
procedure AppendRow(const aGrid:TStringGrid; const aRowData:Array of String);
var
vLastRow , vCntr: Integer;
begin
aGrid.RowCount := aGrid.RowCount +1 ;
vLastRow := aGrid.RowCount -1;// rows and columns are 0 based arrays so column 1 is at index 0, column 2 at index 1 .... column N at N-1.
for vCntr := 1 to Min(High(aRowData),aGrid.ColCount) do begin
aGrid.Cells[vCntr,vLastRow] := aRowData[vCntr-1];
end;
end;
Procedure DemoGridSetup(const aGrid:TStringGrid);
begin // grid to set Columns Rows Titles of columns
SetupGrid(aGrid, 5, 0, ['Airport','RunWay','Longtitude','Latitude','Elevation']);
// ['Airport', 'RunWay','Longtitude','Latitude','Elevation']
AppendRow(['NewYork', 'Bride', '1', '2', '0']);
AppendRow(['Manhatan','Teen', '1.43', '1.23', '23']);
AppendRow(['Chicago', 'Texan', '1.53334', '1.25456', '3']);
AppendRow(['Phoenix', 'Gates', '1.52546', '1.278997', '1.5']);
end;