2

I am having the strangest of issues with Delphi's DBGrid.

I noticed that Sometimes, and I mean only sometimes (It is completely random) when I load rows into a delphi DBGrid, the grid does not show the data.

It instead shows a couple of compressed rows, basically the delphi rows are so narrow in height that the information cannot even be read.

What would be the cause of this? And how can one fix it?

Update

I have finally been able to catch the rows do it myself to get an image. As you can see, the rows are technically showing as 1 is selected. But it is asif they are being compressed very close together so that it apears to be empty...

Please see the image below: image of rows compressed

ANY IDEAS would be awesome as to what is causing this, and how to prevent it...

Marcel
  • 874
  • 1
  • 14
  • 28
  • 3
    How can we reproduce this issue? – Ken White Nov 03 '16 at 20:52
  • @KenWhite That is exactly the issue. It seems to be completely random. It has happened to me a couple of times only, while my clients see it everyday almost.... I did read about it a couple of years ago. But I cannot find the resources anymore :(.... All I have is a DBGrid connected to a Datasource connected to a ZQuery and this is connected to a ZConnection – Marcel Nov 03 '16 at 20:54
  • What @KenWhite says. I suggest you add a button to your form to click when this condition occurs that a) takes a snapshot of your form so that readers can see the symptoms for themselves and b) captures the content of your dataset in a TClientDataSet, so that you can see if reloading the same data provokes the error. You will find how to do both of these in other SO Q&As if you don't already know. – MartynA Nov 03 '16 at 20:55
  • @MartynA I will try and get a snapshot. But I think i should mention, if you reload the query, meaning you just set the ZQuery to active false and active true, but keep all the same variables the next time the DBGrid will load properly – Marcel Nov 03 '16 at 20:57
  • 1
    We've got 40+ production applications in use daily, and we've never encountered this issue. Not even once, and when I say *in use* I mean all day every day by 50+ users running multiple instances of several of the apps. Without some information to use to help you, it's going to be extremely difficult. What specific version of Delphi are you using? The DBGrid sets a specific, fixed row height unless your code or changing the RowHeight property in the Object Inspector alters it, so it's not a VCL issue. – Ken White Nov 03 '16 at 21:03
  • @KenWhite honestly, I have several delphi apps also used every day and only this one has this happened with. I am using Delphi XE7 But I am looking for a screenshot now for you :) – Marcel Nov 03 '16 at 21:25
  • It also helps if you describe and/or show code of the things happening around that moment. *when I load rows* is too vague. – Jan Doggen Nov 04 '16 at 09:57
  • Mostly such things are caused by OnDrawDatacell or Ondrawcolumcell if it is a problem of your code. A possible cause could also be graphic driver, screens etc. The only help is to look for distinctions: are there computer where it arises sometimes and are there computer where it never happened. Then look for the distiction between both groups. – Christine Ross Nov 04 '16 at 12:19
  • I would suspect memory overwrite with some data because of the randomness. First I would enable `Range checking` (and `Overflow checking`) in Project options - Delphi compiler - Compiling (they are disabled by default). And make sure they are on for both `Release configuration` and `Debug configuration`. Hopefully either triggers, to give you something to chase. – Tom Brunberg Nov 04 '16 at 16:13
  • I'm also having this problem. Will try to investigate. Delphi version: RX / 10.3 – Ignas Apr 03 '19 at 11:41

1 Answers1

0

This problem occured to me, too. And I think I have solved.

In my situation I was calling ADOQuery.Open(); inside TThread, and this ADOQuery was bound to DataSource and it was bound to DBGrid. I suspected there may be something with execution in a secondary thread, so I played a little with ADOQuery.

Here's what I did that solved my problem. Before calling ADOQuery.Open() and before starting a new thread, I did DataSource.DataSet := nil;. I assign Thread.OnTerminate := RefreshGridFinished;. Then I start that new TThread with some procedure in which ADOQuery.Open(); eventually is called. Then, when TThread finishes, I have this handler, which will assign fetched and full ADOQuery aka DataSet to DataSource:

procedure TMyForm.RefreshGridFinished(Sender: TObject);
begin
  TThread.Synchronize(TThread(Sender),
    procedure
    begin
      DataSource.DataSet := ADOQuery; // I assign fetched dataset
    end);

  if TThread(Sender).FatalException <> nil then
  begin
    Exit;
  end;

  Thread := nil; // Class field
end;
Ignas
  • 389
  • 2
  • 13