Recent

Author Topic: from Delphi: TDBGrid.ColumnCell?  (Read 931 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
from Delphi: TDBGrid.ColumnCell?
« on: September 10, 2022, 05:35:54 pm »
I use the above event in Delphi from wich I migrate and its functionality is quite important to me.
What can I use in Lazarus?

How to color a DBGrid and its elements by code?
Thanks!
« Last Edit: September 10, 2022, 06:13:00 pm by Nicole »

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: from Delphi: TDBGrid_TradesDrawColumnCell?
« Reply #1 on: September 10, 2022, 06:03:37 pm »
DBGrid from LCL has OnDrawColumnCell event.
https://lazarus-ccr.sourceforge.io/docs/lcl/dbgrids/tcustomdbgrid.ondrawcolumncell.html

You can also use OnPrepareCanvas event to set cell background color or font.
https://lazarus-ccr.sourceforge.io/docs/lcl/dbgrids/tcustomdbgrid.onpreparecanvas.html

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: from Delphi: TDBGrid.ColumnCell?
« Reply #2 on: September 10, 2022, 06:16:18 pm »
Thank you for the answer and the link. I find it documented, that there is such an event.
Unfortunately, this seems not to be true for me (Lazarus 2.2.).

- I drop a DBGrid to the form
- select the object inspector and there "events" (not sure if the translation to English is ok)

There I cannot see an OnDrwawColumnCell.

Where is the mistake?

korba812

  • Sr. Member
  • ****
  • Posts: 391
Re: from Delphi: TDBGrid.ColumnCell?
« Reply #3 on: September 10, 2022, 06:32:18 pm »
I have OnDrawColumnCell event in Lazarus 2.2. Maybe you have some content in filter field (above property/event list, marked in red in screenshot)?

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: from Delphi: TDBGrid.ColumnCell?
« Reply #4 on: September 10, 2022, 06:48:53 pm »
You may try looking into JediVCL port to LCL. Some components were ported, far from all but some were.
MAYBE their extended DBGrid too (there are two, TJvDBGrid and TJvUltimDBGrid).

I remember in Delphi using those exactly because VCL TDBGrid gave too little of control.

Nicole

  • Hero Member
  • *****
  • Posts: 970
[solved] from Delphi: TDBGrid.ColumnCell?
« Reply #5 on: September 10, 2022, 07:52:05 pm »
Thank you so much for the hints!

It is most strange: Suddenly it is there. And this was no filter and no mistake. I made an unit, holding nothing but a test DBGrid.  I looked carefully for the event. Was not there in both the units, neither the problem- nor the test unit. Now I see in in both DBGrids.

Probably a meanwhile restart of Lazarus made the difference.

This Jedi thing:
What does it have more?
Everybody talks about Jedi, but somehow I was not too happy if I tried anything.

I discovered Tony's DynamicGrid (from IBX) and used it in some cases.
What I love there, is, that I may sort colums by mouse-click as in Excel.

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: from Delphi: TDBGrid.ColumnCell?
« Reply #6 on: September 10, 2022, 08:08:28 pm »
Another possible case is when you do a shift-click or ctrl-click and you end up having two or more selected components. Then some properties owould be hidden (like .Name) and especialyl many would be hidden when components selected were of different types. Like a components and a form or panel its parent getting selected together.

Today JediVCL is largely a cemetery of abandoned projects, thrown there to die or survive. But eventually there were thrown too much. more than devs could refactor and consume.

Still, many parts of JCL+JVCL are rather good, just remember it is a patchwork...

I am on the fence what is better - a library hastily renamed and non-integrated and thrown into the dusty corner of it, ot a library that ceased to exist and you would not find it even if you knew it existed. Like one day Chromis.IPC just went offline and gone :-)

IBX is commercial library sponsored by everyone who buys Delphi. JVCL was not... When i dropped mantaining Delphi 5 compatibility there was a number of complains, but none of complainers said "okay, now i do it".  FLOSS Delphi libraries are dying, both because of developers and of Embarcadero themselves.

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: [solved] from Delphi: TDBGrid.ColumnCell?
« Reply #7 on: September 10, 2022, 08:43:40 pm »
What I love there, is, that I may sort colums by mouse-click as in Excel.

I wonder if that grid is intimately tires to IBX and interbase, or works with any information sources.

I did it with JvUltimGrid + UnifiedIB data acess.

The SQL query was modified and re-opened.
Took some coding, especially around corners, not documentedin VCL and cut in both grid and db lib. Specifically, it did not like when the query was changed in the middle of opening process, whe nthe windows was reading persisted customizations (the state user closed the window in last time).

As for the "i do it myself" - it can be both bad and good. It can be not very manageable and IF problem emerges it might be a blocker.

How should this query implement that sorting? Would it close the query, change SQL text and re-open it? Then what if it would make wrong edits to SQL text? or if SQL query has no immediate way to sort it (like UNIONs) ? Or other parts of the program did not expect anyone changing their query? Ot the changed query now is very slow and causes heavy load on the SQL engine ?

Also, when you open the same query again - the data might be different from results of the first opening. While refreshing is arguably good thing, it also might be confusing.

Or it was no SQL at all but some ORM, how to add sorting command then ? Object dataset (TList<TObject> with TDataSet interface to published properties) ?
DX's QuantumGrid comes with a number of adapters to different data sources and number of settings in them. Hopefully you would learn all those options :-)

Another way is to load the whole database into memory and sort it there. But, is it always possible? What if you run the program on a computer with 512MB memory (it was huge amount not so long ago) and the server is over the ocean and connection goes through slow 3G mobile phone? You click a header in a grid with like 40 rows (out of an actually large database) and expect nigh instant reaction. But the grid then starts sucking in the whole query. One hour later the program, after having downloaded 3 GB of data (your mobile provide is happy to make monthly bill to you), crashes by out-of-memory.

If you opt for this way of sorting, you better use some TMemoryTable or TClientDataSet - some component explicitly sayins all the results are in memory. So you would at least remeember it.

QuanmtumGrid really was very flexible, it supports sorting both locally after read-all and on-server by re-opening modified query. If there were a fitting adapter with fitting features. After yoiu learn how to choosethe adapter and how to set it up.

============

Oh, and BTW, can you mark some row in that grid, so their sorting would only be in one direction, not reversed one. So when a user makes multi-column sorting for other clumns he would be able to select ascendign or descending sort, but for these few the sorting would be always ascending or always descending ?

This was a very simple requirement and i was sure this uber-expensive uber-flexible grid from DevExpress has it. LOL. Eventually i had to patch DevExpress Quantum grid to have such a simple thing. When i asked vendor - they answered with a list of internal methods, that i had to cut out of their sources, modify them, and use my modified copy by calling from some grid's events instead of.
Basically, they just traced all the sorting sequence and gave me the list of methods that were used in it. Of help...

----

Basically, as long as you only need basic things - it is okay to use "out of the box" super-automated libraries. If you never would need anything above that, or if you sell it off early and if later comes a need to work with several years of accumulated data - it would be someone else's problem not yours. But you may happen on the other side too...

Othertimes, however, when you see some smartie automation you start thinking "in which condition it can break my program and render me responsible for their code". Especially if it was some other person which made some years ago that automated solution, of dozen grids and clientdatasets, connected via properties and almost no code, codeless programmer, trendy. It really worked great for 5 years, then it stopped. Maybe data accumulated too much, maybe some update was not ideally compatible. But all the properties are still there as they were, yet the magic does not happen. And you are ordered to fix it in few days, because the business can not do work.

 

TinyPortal © 2005-2018