How TDBGrid works lazarus / 16-Databases ---------------------------------------------------------------------- aradeonas · 2016-05-05 13:22 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. ---------------------------------------------------------------------- HeavyUser · 2016-05-08 21:10 Quote from: aradeonas on May 05, 2016, 03:22:46 pmHi, 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. 1) TDBGrid does not have any data internally at all it relies in the presence of the TDataset to provide the data. for every paint it asks the underline dataset for the string to paint. There are a lot more going on like monitoring the dataset for changes and issuing refresh/repaint/invalidate commands as needed, changing the state of the dataset as needed to accomplish its goals etc but I guess is not what you are looking for. You could say that TDBGrid is a "typed virtual grid" well, virtual because it does not keep any of the data internally and typed because it uses a specific interface to retrieve data. What exactly forced you to take such a radical approach? Writing a grid is a huge task so I assume the need for change must be enormous. ---------------------------------------------------------------------- aradeonas · 2016-05-09 05:34 Thanks for the explanation. I dont want to make another TDBGrid, I just like it's behavior and want to have it in somewhere else. I need to have a way to scroll data in Dataset and read them without calling it AfterScroll event or any changes to it's state. For example I want to know and draw record 1000 to 1100 without changing RecNo to 1000. I can use TDataLink but it seems to has only BufferCount property that copy all data to it's buffer and I dont want to otherwise I should store all records to buffer and it not seems good when you got data in Dataset itself. ---------------------------------------------------------------------- HeavyUser · 2016-05-09 15:24 Quote from: aradeonas on May 09, 2016, 07:34:57 amThanks for the explanation. I dont want to make another TDBGrid, I just like it's behavior and want to have it in somewhere else. I need to have a way to scroll data in Dataset and read them without calling it AfterScroll event or any changes to it's state. For example I want to know and draw record 1000 to 1100 without changing RecNo to 1000. I can use TDataLink but it seems to has only BufferCount property that copy all data to it's buffer and I dont want to otherwise I should store all records to buffer and it not seems good when you got data in Dataset itself. Well a dataset is considered what is known as a client side cursor in sqlserver. In order to make sure that all attached controls show the same thing it does not allow multiple records accessed at the same time this has to do with data persistence across views making it a no brainer to use in multiview situations where scrolling to a specific record allows a number of secondary controls to refresh as needed (master detail anyone?) but it makes it a bit counter intuitive to use on cases where a single dataset must be used for unrelated tasks eg multiple comboboxies on an edit form that choose from the same table for different purposes (eg, background and foreground color, departure and arrival airports/ports) etc. The proper way to solve this is to break the dataset in to two distinct interweaven objects. 1) the data container 2) the cursor logic. in that way you can have multiple cursors accessing the data propagating the container's events to the attached data aware controls. This is more complicated than a first view might imply. for example can multiple cursor have a write lock on different records or even the same one? Can those cursors exist in threads outside the data container's thread? should a post on the cursor force all cursors attached to the same data container to propagate the event in its attached controls? Under what conditions? As you can see this gets complicated fast even removing multithread support from the requirements it has to have some sort of safety feature build in to avoid data corruption. All in all a worthy goal and if implemented correctly a very powerful, client side, in memory, database but it requires a lot of time and effort. So if you want to have a go at it start by extending an existing dataset and see how that goes. ---------------------------------------------------------------------- aradeonas · 2016-05-09 16:19 Too complicated for such a simple task. I though TDataset as a data array and think something like DisbaleScrolling for example and do the stuff and EnableScrooling so between this disable and enable I can do read data without need to worry about changing things otherwise I need to change some exciting dataset to get this feature . ---------------------------------------------------------------------- HeavyUser · 2016-05-09 16:50 Oh, sorry I got sidetracked (to put it mildly), In that case simple call dataset.disablecontrols, all controls will remain frozen in time (aka they will not receive any events) and you can do what ever you want. When you finish processing call Dataset.enablecontrols to refresh all controls to the current state of the dataset. ---------------------------------------------------------------------- aradeonas · 2016-05-09 17:04 I tried that before but it is not as fast as increasing TDataLink.BufferCount . I dont get why when all data are in memory I cant use a fast way to access them and I should copy them to a buffer to access them. ---------------------------------------------------------------------- HeavyUser · 2016-05-09 18:06 Sorry I have never used TDatalink. My understanding is that it is used to allow a memory dataset to retrieve data from any provider and I was never interested to add one more access layer so I stayed away from it. I might have to reassess my position. ---------------------------------------------------------------------- aradeonas · 2016-05-09 18:09 Thanks for your input HeavyUser.