Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh to DBGrid and cursor points to the same record.

Status
Not open for further replies.

mlara

Programmer
Oct 22, 2001
32
CO
Hi!

I have an important question. I do a query to a Firebird database. I use the MDO (Mercury Database Objects) components for access the database. When I do click over the title of each column, I change the clause 'ORDER BY' and re-open the query. Then I execute the method 'Locate' to position the cursor. The problem is that when I execute this method, the component (TMDOQuery) scroll by all records so far the record searched. This operation takes several seconds (sometimes a lot of seconds). I don't want use the component TClientDataSet. The objetive is finds a solution as it does the IBExpert program. This program order the results and manteins the cursor on the same location.

How can I do it?

Maybe the problem is in use the method 'Locate', but I too want search records in a dbgrid. When the grid has a lot of records (more than 1000), the quest causing a lot of 'Fetch Next', and takes a lot of time.

I must solve this problem, using forced a dbgrid.
 
Use a bookmark:

Code:
var
  Bookmark:TBookmark;

  YourTable.DisableControls;
  try
    Bookmark := YourTable.GetBookmark;

    <do some processing here>

    YourTable.GotoBookmark(Bookmark);
  finally
    YourTable.EnableControls;
    YourTable.FreeBookmark(Bookmark);
  end;
 
No, the use of Bookmarks is not appropriate. A bookmark contains a position of record. When I change the clause 'ORDER BY' and re-open the query, the records changes the order, and the bookmark brings me to another record.
 
If the locate will cause scrolling then you'll need to use the disable/enable controls methods to at least prevent the grid from expending all the effort of drawing the records moving past.
 
Of course, I execute the method DisableControls, then the control dbgrid don't show the records while but do it (All the 'Fetch next' neccesary). Then the problem consists in these:

When I execute the method 'Locate' the control (TMDOQuery based in TIBQuery) scroll by all records do it one by one. This procedure take a lot of time and no is appropriate. For best explai, the code is:

procedure TForm.DBGridTitleClick(Column: TColumn);
var
ColumnName: string;
CodigoInt: Integer;
begin
// Current record
CodigoInt := Query.FieldByName('CodigoInt').AsInteger;

// Change the clause 'ORDER BY'
Query.SQL[Query.SQL.Count-1] := 'ORDER BY ' + ColumnName;

// Re-Open the query
Query.DisableControls;
Actualizar(CodigoInt); // another procedure
Query.EnableControls;
end;

procedure TForm.Actualizar(CodigoInt: Integer);
begin
// Open
Query.Open;

// Current record
if CodigoInt <> -1 then
Query.Locate('CodigoInt', CodigoInt, []); // Here is the problem.
end;


Thanks for your comments.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top