procedure TMainForm.btnExecuteClick(Sender: TObject);
var
TempStart, TempEnd: TTime;
TempSQL: string;
TempDataSet: TDataSet;
i, j: Word;
begin
Grid.BeginUpdate;
Grid.ClearRows;
Grid.Columns.Clear;
try
TempSQL := memoSQLCommand.Text;
TempDataSet := ExecuteQuery(TempSQL, False);
if TempDataSet.FieldCount > 0 then
begin
for i := 0 to TempDataSet.FieldCount - 1 do
AddGridCol(Grid, False, True , Grid.Columns.Count, TNxTextColumn, TempDataSet.Fields[i].FieldName, 80, True, taLeftJustify);
end;
TempStart := Now;
if TempDataSet.RecordCount > 0 then
begin
Grid.AddRow();
Grid.AddRow(TempDataSet.RecordCount - 1);
j := 0;
while not TempDataSet.Eof do
begin
for i := 0 to TempDataSet.FieldCount - 1 do
Grid.Cells[i, j] := TempDataSet.Fields[i].AsString;
TempDataSet.Next;
Inc(j);
end;
end;
TempEnd := Now;
finally
TempDataSet := nil;
FreeAndNil(TempDataSet);
end;
Grid.EndUpdate;
ShowMessage(FormatDateTime('s.zzzz', TempEnd - TempStart));
end;
AddGridCol is a simple procedure to add a column to the NextGrid with some properties at runtime.
Grid.AddRow();
Grid.AddRow(TempDataSet.RecordCount - 1);
Notice the part above. If I do not do this, there will be an "out of bounds" error.
With this code, I could populate the grid with 29 and 8,000 records at around 4.250 seconds. I think it's a bit slow, any suggestions to improve speed will be much appreciated. Thanx in advance