Delphi, what is the fastest way to access records in TcxGrid or TDataSet

I use Delphi 2007 and TcxGrid to display the contents of a file library. The database stores information about the file type, name, path and extension.

When testing, I load 1700 records into the grid via TDataSet. I also take up grid space for three more fields that still need to be calculated. They are, if the files exist, the file size and date are changed.

My goal is to show the user all the saved information (which works fine and fast), and then find information for the other three data fields in the background stream and then paste them into TcxGrid. This question has little if nothing to do with the thread I am doing. His work is wonderful.

My problem is that access to the fields in the grid that is already built has a huge decline when accessing it. I tried two different ways ...

  • Grid.DataController.Values ​​[RecordIndex, FieldIndex] - but this is an option, and I suspect that is why it is so slow

  • Grid.DataController.DataSet.FindFirst Grid.DataController.DataSet.FindNext Grid.DataController.DataSet.Fields [FieldIndex] But using this search method is as slow as the first method I tried. Localization and movement are also slow.

In short, What is the fastest way to access records?

+3
source share
4 answers

The update code, which was supposed to be at the beginning / end of the update, was my big problem.

Lieven , . , .

, , .

+1

, TcxGridDBTableView TcxGridTableView?

, db TcxGridTableView TcxBandedGridTableView

View.DataController.Values ​​[RecordIndex, FieldIndex] .

db, -db DataController SQL- .

: 

class procedure TForm1.FillView(const View: TcxGridBandedTableView; const Sql: string);
var
  Reader: TMyOrmDataReader;
  i: Integer;
begin
  Assert(Assigned(View), 'View is not assigned parameter.');
  with View.DataController do
  begin
    BeginFullUpdate;
    try
      Reader := TMyOrm.GetDataReader(SQL);
      try
        i := 0;
        RecordCount := 50 * 1000; // make it something big in order to avoid constant resizing by 1
        while Reader.Read do
        begin
          // Fill the view
         Values[i,  0] := Reader.GetInt32(0);
         Values[i,  1] := Reader.GetString(1);
         Inc(i);
        end;
        RecordCount := i - 1;
      finally
        Reader.Free;
      end;
    finally
      EndFullUpdate;
    end;
  end;
end;

, :

View1.DataController.Values[View1.DataController.FocusedRecordIndex, View1Column1.Index].AsString
+2

/ , , datbound.

+1
source

I know this is an old thread, but I mentioned that switching the grid to provider mode is another way to increase the download speed, because it actually turns the loading of the grid into a virtual operation. (Records are not loaded until they are needed for display or other access to the data.) After that, the DataController caches them, so the access loads very quickly.

+1
source

Source: https://habr.com/ru/post/1772697/


All Articles