Lazarus

Programming => Widgetset => Cocoa => Topic started by: xinyiman on June 06, 2019, 09:29:16 am

Title: Extended DBGrid
Post by: xinyiman on June 06, 2019, 09:29:16 am
Hi guys, I'm extending the dbgrid to get a smarter grid that allows me to have filters in the columns and other features. I'm at the beginning and the project is still at the beginning. But I have already encountered a problem. If you compile my project and run it you will see that it loads two lines in the grid, then if you click on the Click Me button you will notice that the grid redraw is wrong, the size of the row containing the titles and filters gets smaller. Then, if you click with the mouse on any point on the grid, it redraws correctly. I don't understand why I have to click to see right. If you look at the images I attach you will understand what I mean.

Title: Re: Extended DBGrid
Post by: xinyiman on June 06, 2019, 09:41:31 am
To simplify the problem occurs when I close and reopen the dataset that populates the grid. If you create a button2 and put the following code in it

     Self.Q_Persone.Close;
     Self.Q_Persone.Open; 

you will see that you replicate the error. But I don't understand why. Is it a bug in the dbgrid? Or do I have a problem with my code? Do you miss anything?
Title: Re: Extended DBGrid
Post by: xinyiman on June 06, 2019, 02:43:39 pm
Has anyone managed to reproduce the problem?
Title: Re: Extended DBGrid
Post by: nouzi on June 06, 2019, 06:02:21 pm
error  sql query is empty
Title: Re: Extended DBGrid
Post by: xinyiman on June 06, 2019, 10:42:46 pm
error  sql query is empty

Impossible, I rediscovered it and it doesn't give me the error you say.
Title: Re: Extended DBGrid
Post by: rvk on June 06, 2019, 10:46:13 pm
On Windows 10 it works fine.
Title: Re: Extended DBGrid
Post by: xinyiman on June 06, 2019, 10:55:10 pm
Problem only on Mac cocoa
Title: Re: Extended DBGrid
Post by: VTwin on June 07, 2019, 02:07:18 am
Problem only on Mac cocoa

What version of Lazarus are you using? 1.8.0?
Title: Re: Extended DBGrid
Post by: xinyiman on June 07, 2019, 07:32:09 am
Problem only on Mac cocoa

What version of Lazarus are you using? 1.8.0?
2.1.0
Title: Re: Extended DBGrid
Post by: xinyiman on June 07, 2019, 12:28:13 pm
Look at the example below. Click the "click me" button and then the "click me 2" button. If you see the click me 2 performs an operation that I also perform in the click me. I don't understand why clicking on "click me 2" works.
Title: Re: Extended DBGrid
Post by: rvk on June 07, 2019, 12:45:37 pm
I don't understand why clicking on "click me 2" works.
Because you do a whole lot more in "Click me".

So what is the problem.
Why not just step through all the things you do in "Click me" and see where the problems lies.
Title: Re: Extended DBGrid
Post by: xinyiman on June 07, 2019, 01:34:04 pm
I can't understand what's wrong. First because on windows and linux it works but only on mac no, second because it seems that any subsequent iteration with the grid on click me redraws the grid itself correctly. And I don't understand what prevents him from doing it directly in the click me button.
Title: Re: Extended DBGrid
Post by: xinyiman on June 07, 2019, 10:19:50 pm
Ok, I modified the program slightly. Ignore the click me button and the click me2 button. After loading, first click the Button3 button and you will see that I only do a DataSet.Close and a DataSet.Open and a DataSet.Refresh (and so far the problem presents itself). Then press the button4 button and you will see that the problem is solved. But it doesn't make sense, because in button4 I only do a DataSet.refresh. I would like to know which user writes cocoa widgets so as to ask him directly how to solve.
Title: Re: Extended DBGrid
Post by: VTwin on June 09, 2019, 02:40:24 am
I would like to know which user writes cocoa widgets so as to ask him directly how to solve.

Not sure about DBGrid, but most likely skalogryz.
Title: Re: Extended DBGrid
Post by: xinyiman on June 09, 2019, 10:42:50 pm
I would like to know which user writes cocoa widgets so as to ask him directly how to solve.

Not sure about DBGrid, but most likely skalogryz.
I do not understand what you mean. what is skalogryz?!
Title: Re: Extended DBGrid
Post by: rvk on June 09, 2019, 10:49:31 pm
I would like to know which user writes cocoa widgets so as to ask him directly how to solve.
Not sure about DBGrid, but most likely skalogryz.
I do not understand what you mean. what is skalogryz?!
You asked for a user.
skalogryz is a forum-user.
Check his profile.
https://forum.lazarus.freepascal.org/index.php?action=profile;u=13884
Quote
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz
Title: Re: Extended DBGrid
Post by: xinyiman on June 10, 2019, 08:11:48 am
thanks a lot
Title: Re: Extended DBGrid
Post by: xinyiman on June 10, 2019, 07:05:55 pm
Example done for skalogryz. See attachment
Title: Re: Extended DBGrid
Post by: skalogryz on June 10, 2019, 07:53:57 pm
so what's happening is that on the initial drawing your first row height is 21 pixels. (which is a default row height).
On the consequent drawing, the desired 42-pixels height is picked up.

You don't really need to do ".Refresh" of any kind. You can just simply resize the form to see the height of the top row to change.

What you're looking into is resetting the height of the first row before (the first) drawing.
Currently, the height is adjusted in DrawCell() method, and that's too late. (as drawing is already in progress)
Title: Re: Extended DBGrid
Post by: xinyiman on June 11, 2019, 08:09:50 am
so what's happening is that on the initial drawing your first row height is 21 pixels. (which is a default row height).
On the consequent drawing, the desired 42-pixels height is picked up.

You don't really need to do ".Refresh" of any kind. You can just simply resize the form to see the height of the top row to change.

What you're looking into is resetting the height of the first row before (the first) drawing.
Currently, the height is adjusted in DrawCell() method, and that's too late. (as drawing is already in progress)

So in which event do you advise me to move the definition of the title height?
Title: Re: Extended DBGrid
Post by: skalogryz on June 11, 2019, 02:40:10 pm
So in which event do you advise me to move the definition of the title height?
there are two places that can work
1) whenever you change a filter setting (as filters are the reason for the height to be different). If filter change, you'd need to review if the height needs to be any different than default height.
2) in the very most beginning of the paint. Before you pass the paint to TDBGrid, you need to adjust heights according to the current filter settings.

Approach #1 is better, than approach #2. Both of them would be doing the same thing (checking if height needs to be different).
But approach #1 would only do it when the height can actually change.
Approach #2 would do it every time the control paints. And that is a little of overhead.