Add new comment

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.
TDBGrid Bug 
By doing some searches using Google and Quality Central I didn’t find any mention to this bug, well! maybe this indicates that Delphi doesn’t have many fans in Arabic or Hebrew regions, the languages that use right to left writing, also 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, and 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 Embaracadero, I can post about this Later but now let us go back to the Bug. 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 entire ClientRect like in the old version, and using the API function BeginPaint in TDBgrid seams doesn’t work with RightToLeft mode, so here is my quick solution, maybe 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.


private
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 :)

 

Articles Categories: