TMSFMXGrid livebinding TClientDataSet

I have successfully converted a VCL project using Mida Converter to FMX.  It uses MyBase local database binary *.cds files and loads them into the grid.  In VCL the largest file only takes about 3 seconds (the Canada file which has 309,000 records), but in the FMX version using livebindings it takes about 220 seconds.  Is there any way to speed up the process?  I'm not using LoadFromFile(), but do this in code:


  cdsCountry.Close; // this allows for a fresh search
  cdsCountry.FileName := FormOptions.EditDataPath.Text + '' + CountryFile;
  cdsCountry.Open;
  cdsCountry.LogChanges := False; // faster and consumes less memory

  cdsCountry.Filter := 'Column_2 = ' + QuotedStr(FCity); // assume world location first
  cdsCountry.Filtered := True; // start filtering
  if (cdsCountry.RecordCount > 1) then...

Hi, 


Probably, the Mida Converter converted the VCL grid to a TTMSFMXGrid, but we have recently introduced a TTMSFMXLiveGrid for larger datasets. Please replace the TTMSFMXGrid instance with a TTMSFMXLiveGrid for faster data loading.

Kind Regards, 
Pieter

Pieter Scheldeman2015-02-06 13:01:22

Thanks Pieter, that fixed it.  Running fast now (no more than 4 seconds on the largest file).

The TMSFMXLiveGrid doesn't seem to know how to focus the result in a locate request on the ClientDataSet.  In the VCL version the code is like this:


if cdsCountry.Locate('Column_2', FCity, [loCaseInsensitive, loPartialKey]) then...

It loads the entire file but without selecting the first result.

Do I have to do a loop on the second column using Cells[] to highlight this?

To be more precise, it does select the first result, but the scrollbar is set all the way to the top.  In a list of typically 30,000 records this is not ideal.  Is there a way to set the scrollbar position in the grid to highlight the result in the middle of the viewscreen?

When I press the search button successive times I get different results.  The first time it sets up the list in alphabetical descending order, next it does it in ascending order, then it does the locate and it cycles like this each time I click the search button.  So I set the Sorting.Mode to gsmNone, but no luck - still the same cycle.

Hi, 


Could you perhaps send us a sample that demonstrates this issue, so we can investigate this here and look for a solution?

Kind Regards,
Pieter

OK. Where do I send it?

You can send the sample to mailto:help@tmssoftware.com

Right now the locate is working, but the sort.mode := gsmNormal is not.  I have 2 grids using sort in the project and one works and the other doesn't and I'm not sure why.  Tried to make sure that both use identical options.

Hi, 


Sorting in combination with LiveBindings is not supported out of the box. You need to sort the dataset manually. The event OnCanSortColumn can be used to accomplish this. The code should look similar to the code below:
procedure TForm1.TMSFMXGrid1CanSortColumn(Sender:
TObject; ACol: Integer;
  var Allow:
Boolean);
begin
  Allow := False;
//Sort data set
end;

Kind Regards, 
Pieter 

The strange thing though is that it did work at first and now it doesn't.  The live bindings were there from the beginning from the Mida converter.  I changed some properties but I didn't write any code to sort manually yet.

I think I found the problem, one is using TFMXLiveGrid (doesn't work) and the other is using TFMXGrid (does work).  Do you have an example of an OnCustomCompare so I can do a sort on a column alphabetically or numer?  I see the TSortFormat for each column.

Hi, 


Only direct dataset sorting works, as explained in the previous. From the first version, sorting wasn't supported in either TTMSFMXLiveGrid or TTMSFMXGrid. Please use the above code and manually sort the dataset. Some datasets have a Sort procedure to accomplish this, some need to execute an SQL statement.

Kind Regards, 
Pieter

OK. Thanks!