Recent

Author Topic: Emulating Delphi behavior with BiDiMode  (Read 5506 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Emulating Delphi behavior with BiDiMode
« on: June 24, 2011, 01:32:30 pm »
In Delphi (D6) if you set "BiDiMode:= bdRightToLeft" on some Edit Controls, and "BiDiMode:= bdLeftToRight" on other controls and add the following code, Entering an Edit Control will automatically load the correct keyboard language for each control.  You can override the language manually when needed. 

--------------
const
  LangHeb = $40D;

initialization
  with Application do begin
    NonBiDiKeyboard:= IntToHex(GetUserDefaultLangId,8);
    BiDiKeyboard:= IntToHex(LangHeb,8);
    SysLocale.MiddleEast:= True;
  end;
--------------

I am trying to find an elegant way to do this in Lazarus (Windows only).  I have tried "ActivateKeyboardLayout" in the "OnEnter" event of each control and it works, but it is a long way from the elegance and ease of Delphi.  I also tried setting "TForm.KeyPreview:= True" and loading the language according to "TForm.ActiveControl.BiDiMode" in the "OnKeyUp" event of TForm, but this does not allow the user to override manually.

If anyone has some ideas, I would like to hear them.  I would be glad to share any BiDi code that I have with anyone working with Right To Left languages.
« Last Edit: June 27, 2011, 04:11:05 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Emulating Delphi behavior with BiDiMode
« Reply #1 on: June 27, 2011, 06:25:09 pm »
So far the best I have been able to come up with is to call this routine in the "OnEnter" event for each Edit Control.  It does allow the user to manually override language, but I don't think it is very elegant.  Of course it is only for Windows.  Any input would be welcomed.

const
  LangHeb = $40D;

var
  NonBiDiKeyboard: LongInt;
  BiDiKeyboard: LongInt;

procedure TForm1.SetLang(AForm: TForm);
begin
{$IfDef Windows}
  case AForm.ActiveControl.IsRightToLeft of
    True : ActivateKeyboardLayout(BiDiKeyboard, 0);
    False: ActivateKeyboardLayout(NonBiDiKeyboard, 0);
  end;
{$EndIf}
end;

initialization
  NonBiDiKeyboard:= GetUserDefaultLangId;
  BiDiKeyboard:= LangHeb;
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018