2
votes

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...

1
How can we reproduce this issue?Ken White
@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 ZConnectionMarcel
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
@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 properlyMarcel
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

1 Answers

0
votes

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;