Re: [Lazarus] How TDBGrid works
> The data will be dupplicated. Yes and it is bad but as I said it is good for even couple thousand record. Regards, Ara -- http://www.fastmail.com - A fast, anti-spam email service. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Sunday 08 May 2016 08:44:37 Aradeonas wrote: > A simple way is to make BufferCount=RecordCount so all record will be in > buffer, it will be fast and easy to use and good for even couple of > thousands records but not a real solution. > The data will be dupplicated. Martin -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
A simple way is to make BufferCount=RecordCount so all record will be in buffer, it will be fast and easy to use and good for even couple of thousands records but not a real solution. Regards, Ara -- http://www.fastmail.com - Email service worth paying for. Try it for free -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Sunday 08 May 2016 04:31:29 Jesus Reyes A. wrote: > En Sat, 07 May 2016 01:26:38 -0500, Martin Schreiber > > escribió: > > On Friday 06 May 2016 23:20:41 Aradeonas wrote: > >> Thanks. > >> > >> So what is the best way to provide those 100 to 1100 record at least > >> without Dataset calling AfterScroll event? > >> I want to not make any event while scrolling my custom Grid so other > >> connected DB controls change their values otherwise while Im scrolling > >> my custom grid it will cause calling all connected DB controls to update > >> their values. > >> I hope it is more clear now. > > > > If the wanted record is in window of TDataLink.FirstRecord..FirstRecord + > > BufferCount - 1 you can temporarily switch the record which supplies the > > field data by setting TDatalink.ActiveRecord which doesn't fire any > > events. I > > assume you know that. ;-) > > See for example the MSEgui functions TGridDatalink.GetDisplay*Buffer(), > > BeginGridRow() and EndGridRow(). > > https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/m > >sedbedit.pas > > Good luck by trying that while FirstRecord is "pointing" to record 1000 > AND keeping RecNo at 1, maybe I misunderstood something. > Then the "wanted record" is *not* in in window of TDataLink.FirstRecord..FirstRecord + BufferCount - 1 a dataset with direct data access like TMSEBufDataset or the problematic DisableControls()/EnableControls() trick is necessary. Martin -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
En Sat, 07 May 2016 01:26:38 -0500, Martin Schreiber escribió: On Friday 06 May 2016 23:20:41 Aradeonas wrote: Thanks. So what is the best way to provide those 100 to 1100 record at least without Dataset calling AfterScroll event? I want to not make any event while scrolling my custom Grid so other connected DB controls change their values otherwise while Im scrolling my custom grid it will cause calling all connected DB controls to update their values. I hope it is more clear now. If the wanted record is in window of TDataLink.FirstRecord..FirstRecord + BufferCount - 1 you can temporarily switch the record which supplies the field data by setting TDatalink.ActiveRecord which doesn't fire any events. I assume you know that. ;-) See for example the MSEgui functions TGridDatalink.GetDisplay*Buffer(), BeginGridRow() and EndGridRow(). https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/msedbedit.pas Good luck by trying that while FirstRecord is "pointing" to record 1000 AND keeping RecNo at 1, maybe I misunderstood something. Jesus Reyes A. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Saturday 07 May 2016 11:03:28 Aradeonas wrote: > > > A possible workaround could be to call TDataset.DisableControls(), to > > fetch the needed records and to restore the DB cursor position before > > calling EnableControls(). I fear it is not efficient and has > > sideeffects. > > What side effects do you think about? > Maybe changed record buffer window which could trigger recentering of grids. You must try it, the buffer and scrolling system is complicated... Martin -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
> The easy one is probably to make two independent connections to the > database. More elaborated solutions would be for example copy all said > records to a memdataset and only connect that to a dbgrid, OR put the > records in a non-dataset enabled component, like a TDrawGrid or > TStringGrid, browsing that will not trigger any dataset events so > other db controls will be unaffected, etc. The problem here is I think > synchronizing stuff, you will have a funny time getting the updates to > those records into the original source. Jesus I'm afraid your way is not memory efficent. > If the wanted record is in window of > TDataLink.FirstRecord..FirstRecord + BufferCount - 1 you can > temporarily switch the record which supplies the field data by setting > TDatalink.ActiveRecord which doesn't fire any events. I assume you > know that. ;-) See for example the MSEgui functions > TGridDatalink.GetDisplay*Buffer(), BeginGridRow() and EndGridRow(). > https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/msedbedit.pas > If the wanted records are anywhere in the dataset you need a dataset > with random row data access. TMSEBufDataset supports it, please see > the TMSEBufDataset.Current* properties. > https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/msebufdataset.pas > The MSEgui dropdownlist DB-edits use this approach for lookups if > Dropdown.OptionsDB odb_directdata is set. Glad to hear from you Martin. Happy to see MSE support this and I will look it up. > A possible workaround could be to call TDataset.DisableControls(), to > fetch the needed records and to restore the DB cursor position before > calling EnableControls(). I fear it is not efficient and has > sideeffects. What side effects do you think about? Regards, Ara -- http://www.fastmail.com - IMAP accessible web-mail -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Friday 06 May 2016 23:20:41 Aradeonas wrote: > Thanks. > > So what is the best way to provide those 100 to 1100 record at least > without Dataset calling AfterScroll event? > I want to not make any event while scrolling my custom Grid so other > connected DB controls change their values otherwise while Im scrolling > my custom grid it will cause calling all connected DB controls to update > their values. > I hope it is more clear now. > If the wanted record is in window of TDataLink.FirstRecord..FirstRecord + BufferCount - 1 you can temporarily switch the record which supplies the field data by setting TDatalink.ActiveRecord which doesn't fire any events. I assume you know that. ;-) See for example the MSEgui functions TGridDatalink.GetDisplay*Buffer(), BeginGridRow() and EndGridRow(). https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/msedbedit.pas If the wanted records are anywhere in the dataset you need a dataset with random row data access. TMSEBufDataset supports it, please see the TMSEBufDataset.Current* properties. https://gitlab.com/mseide-msegui/mseide-msegui/raw/master/lib/common/db/msebufdataset.pas The MSEgui dropdownlist DB-edits use this approach for lookups if Dropdown.OptionsDB odb_directdata is set. A possible workaround could be to call TDataset.DisableControls(), to fetch the needed records and to restore the DB cursor position before calling EnableControls(). I fear it is not efficient and has sideeffects. Martin -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
En Fri, 06 May 2016 16:20:41 -0500, Aradeonas escribió: Thanks. So what is the best way to provide those 100 to 1100 record at least without Dataset calling >AfterScroll event? I want to not make any event while scrolling my custom Grid so other connected DB controls change >their values otherwise while Im scrolling my custom grid it will cause calling all connected DB >controls to update their values. I hope it is more clear now. Regards, Ara The easy one is probably to make two independent connections to the database. More elaborated solutions would be for example copy all said records to a memdataset and only connect that to a dbgrid, OR put the records in a non-dataset enabled component, like a TDrawGrid or TStringGrid, browsing that will not trigger any dataset events so other db controls will be unaffected, etc. The problem here is I think synchronizing stuff, you will have a funny time getting the updates to those records into the original source. Jesus Reyes A. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
Thanks. So what is the best way to provide those 100 to 1100 record at least without Dataset calling AfterScroll event? I want to not make any event while scrolling my custom Grid so other connected DB controls change their values otherwise while Im scrolling my custom grid it will cause calling all connected DB controls to update their values. I hope it is more clear now. Regards, Ara -- http://www.fastmail.com - A fast, anti-spam email service. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Fri, 06 May 2016 15:07:18 -0500, Aradeonas wrote: Thanks, It seems I should explain better. For RecordCount you are right and it seems DBGrid doesn't know correct number either otherwise it should has a better scroll size. I want to do something like DBGrid and for that I want to get only a part of data for example record 1000 to 1100 and for that I can >set BufferCount to 100 but in this case I should navigate dataset to record 1000 to get these value but I prefer to not change RecNo >and use something like DataLink's ActiveRecord that changes record you want without changing RecNo of Dataset. You can't, there is no way using TDataset facilities. But anyway, changing ActiveRecord *should* change RecNo (provided that RecNo is reliable, it definitively is not if Dataset.IsSequenced=false OR dataset is filtered), if it's not then you found a bug. So if I have 1 Dataset that is fully load all 1500 record can I just print records from 1000 to 1100 without changing RecNo? Regards, Ara Jesus Reyes A.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
Thanks, It seems I should explain better. For RecordCount you are right and it seems DBGrid doesn't know correct number either otherwise it should has a better scroll size. I want to do something like DBGrid and for that I want to get only a part of data for example record 1000 to 1100 and for that I can set BufferCount to 100 but in this case I should navigate dataset to record 1000 to get these value but I prefer to not change RecNo and use something like DataLink's ActiveRecord that changes record you want without changing RecNo of Dataset. So if I have 1 Dataset that is fully load all 1500 record can I just print records from 1000 to 1100 without changing RecNo? Regards, Ara -- http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
On Fri, 06 May 2016 13:44:46 -0500, Aradeonas wrote: Jesus,In that demo if I set BufferCount to 9 always get 9 records and even Query.RecordCount will be 9 even result is more. How can I get real count? I can get count before setting the link but is it the best way? DbGrid does not do that, and it doesn't have to. And the best way would depend, I guess, on the specific situation and what set of components are being used. How can I move or scroll link without moving Query? I want to scroll the grid and get new data without changing RecNo. In your example if I only got 9 record for example but I want for example 20th record. Not sure if I understand the part on "moving the query", but using TDataset derived components, and without using the basic MoveBy, Locate, first, last, next or prev you can't. Some dataset descendants may have some properties that help at some cost, for example y you set PacketRecords:=-1 then sqldb will load all the records and in this case RecordCount may be reliable, that is if dataset is not filtered (or that seems to indicate the relevant documentation). Some datasets may actually return a valid record count, probably TDbf is in this case. In any case without using the mentioned basic operations you can't select records. Regards, Ara Jesus Reyes A.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
Jesus, In that demo if I set BufferCount to 9 always get 9 records and even Query.RecordCount will be 9 even result is more. How can I get real count? I can get count before setting the link but is it the best way? How can I move or scroll link without moving Query? I want to scroll the grid and get new data without changing RecNo. In your example if I only got 9 record for example but I want for example 20th record. Regards, Ara -- http://www.fastmail.com - Accessible with your email software or over the web -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
Thanks for the explanation, with your demo its more clear to me. Regards, Ara -- http://www.fastmail.com - Choose from over 50 domains or use your own -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How TDBGrid works
En Thu, 05 May 2016 16:53:00 -0500, Aradeonas escribió: Hi, I'm curious about how TDBGrid now what to show in a column as value. I mean if I want to make a custom grid simple solution si going from first to last of TDataset and read columns value. I Browsed TDBGrid code lately but sadly I couldnt find how it works to get data without (as I think) browsing and changing TDataset records. Regards, Ara --http://www.fastmail.com - Send your email first class DBGrid does not read all records from first to last in order to show them, it only "specify" how many records it can show at the same time, it does this using a data link, TComponentDatalink, which is just a TDatalink with some custom dataset events for easy hooking, a data link is an intermediary between the grid and the dataset. So once the amount of records is set, the grid uses a datalink property: ActiveRecord in order to select which record from the ones it has reserved is the active record, then DbGrid maps this active record to the grid.Row property, the grid.Col property is mapped to a field index and using the standard dataset properties like Fields[i] or the field associated to a column which is again just taken from the dataset. The dataset is in charge all the time in keeping the reserved records up to date, the grid just shows the values it finds in the records. The starting point when the records are shown in DbGrid is procedure TCustomDBGrid.DrawAllRows; there the ActiveRecord is selected, DrawAllRows eventually ends calling individual cells for each row which does DefaultDrawCell and several others. In bug report http://bugs.freepascal.org/view.php?id=29764 I put an example of using TDatalink with multiple records and without DbGrid in a console program. Hope that helps. Jesus Reyes A.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] How TDBGrid works
Hi, I'm curious about how TDBGrid now what to show in a column as value. I mean if I want to make a custom grid simple solution si going from first to last of TDataset and read columns value. I Browsed TDBGrid code lately but sadly I couldnt find how it works to get data without (as I think) browsing and changing TDataset records. Regards, Ara -- http://www.fastmail.com - Send your email first class -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus