TDBGrid bdRightToLeft bug fixed
I am still using Delphi2006 for my database projects, but two days ago I’ve started a small Database App in Delphi2009, and it was a shock when I discovered that there is an obvious bug in TDBGrid in Delphi2009, Delphi2009 Update1 and Delphi2007, this bug will be “visible” if you change the BiDiMode property of TDBGrid to bdRightToLeft.
-Start a new vcl Application
-add a DBGrid and assign it to a DataSource and let it has some records.
-change BiDiMode property of the DBgrid to bdRightToLeft.
-run the application.
-try to move the form that contains the DBgrid beneath any other window or the Taskbar and you will notice the mess in the DBgrid canvas and may be you will see something like this.
By doing some searches on google and Quality Central I didn’t find any mention to this bug, well.. may be this indicates that Delphi doesn’t have many fans in Arabic or Hebrew region, the languages that use right to left writing, either I think CodeGear “itself” doesn’t have much interest in Arabic market, and we “as Arabic Developers” understand that, because of the troubles in the software industry in Arabic region, I hope not in software industry only
even I think Gulf market (which is dominated now by Oracle tools and Java) could be a good opportunity for CodeGear and Embarcadero, I can post about this latter but now let us go back to the Bug.
I spent some time searching for the reason of this bug, actually TGrid and TCustomDBGrid are a little complicated, besides it’s hard to debug this kind of bugs, but obviously it’s a paint issue, and at last (after few hours) here is the reason and solution:
In Delphi2007 and Delphi2009 CodeGear implements a new version of TWinControl.WMPaint procedure, in this new version we paint only the update region instead of painting the whole ClientRect like in the old version, and using of the API function BeginPaint in case of TDBgrid seams doesn’t work with right to left mode, so here is my quick solution, may be it’s not the perfect one but it works.
My solution is to (re)implement the WMPaint procedure (WM_PAINT message) in TCustomDBGrid class and make the update region equal to the client rectangle (like the old versions), especially I didn’t notice this bug in other TWinControl descendants.
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
.
.
.
procedure TCustomDBGrid.WMPaint(var Message: TWMPaint);
var
Rect: Trect;
begin
if UseRightToLeftAlignment then
Begin
Rect.TopLeft := ClientRect.TopLeft;
Rect.BottomRight := ClientRect.BottomRight;
InvalidateRect(Handle,@Rect,false);
End;
Inherited;
end;
I've QC'd this bug in #70075.
this is a quick solution but any other suggestions are welcomed.
Merry Christmas every one 
{ Arabic Programmer; }
Comments
I've mentioned it in QC
I've mentioned it in QC #69465.
BTW, Arabic and Hebrew are not the only right-to-left languages in the world.
Regards
I've checked QC #69465,
I've checked QC #69465, actually you are right it works well with ADO DataSets !
Thank you very much
Thank you very much
another workaround
The bug is in double-buffering code in TWinControl.WMPaint. The workaround is to disable double-buffering for the dbgrid: DBGrid1.DoubleBuffered := false.
If you use the grid with TClientDataSet, you can set dataset's ObjectView property to false since it also disables double-buffering (unlike DoubleBuffered, ObjectView can be changed in design time).
Thank you very much!
Hi,
I'm a chinese programer.
I'm implement a arabic soft.
Thanks for your ids!
Br,
Tag
btw,I used 'GetUpdateRect(Handle, rc, False);'
but it 's not work.
Post new comment