When I use SetWindowLong command to change direction of treeview, popupmenu on its node dose not show. Full Code is here :
Procedure SetWinControlBiDi(Control: TTreeView);
var
ExStyle: Longint;
begin
ExStyle := GetWindowLong(Control.Handle, GWL_EXSTYLE);
SetWindowLong(Control.Handle, GWL_EXSTYLE, ExStyle or WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT );
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
SetWinControlBiDi(TreeView1);
end;
The standard way to do this is to use the Delphi
BiDiMode
property. It's best to do it this way so that the VCL is aware that you want right-to-left. You need to change theBiDiMode
property on the popup menu too.Now, the correct way to do this is not to change the properties on the individual components. Doing it that way is laborious and very error prone. Set
Application.BiDiMode
somewhere in your application's initialization and the change will propagate through to all your components.For example you can make the change in your application's .dpr file:
You need to make sure that you have not modified any component's
BiDiMode
orParentBiDiMode
in any .dfm file. If you have simply remove those lines from your .dfm file and that will allow the single application wideApplication.BiDiMode
setting to control everything.Your approach of setting
GWL_EXSTYLE
is problematic. The VCL is in control of that setting and if you do need to change it, doing so inTForm.OnShow
will lead to strange bugs. Sometimes windows need to be re-created and when this happens your code to setGWL_EXSTYLE
will not run and your tree view will revert to left-to-right. If you do need to modify the window styles then you need to overrideTWinControl.CreateParams
for the component. However, in this case the VCL has direct support for BiDi and that is the best solution.