简体   繁体   中英

Delphi DBGrid showing compressed rows

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: 压缩行的图像

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM