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
BiDiModeproperty. It's best to do it this way so that the VCL is aware that you want right-to-left. You need to change theBiDiModeproperty 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.BiDiModesomewhere 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
BiDiModeorParentBiDiModein any .dfm file. If you have simply remove those lines from your .dfm file and that will allow the single application wideApplication.BiDiModesetting to control everything.Your approach of setting
GWL_EXSTYLEis problematic. The VCL is in control of that setting and if you do need to change it, doing so inTForm.OnShowwill lead to strange bugs. Sometimes windows need to be re-created and when this happens your code to setGWL_EXSTYLEwill 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.CreateParamsfor the component. However, in this case the VCL has direct support for BiDi and that is the best solution.