Jump to content
prodeldpen

FMX ComboEdit and Alt + codes

Recommended Posts

Hello,

 

I would like to be able to enter characters with alt+codes in a FMX Comboedit.
For instance Alt+0192 for the uppercase A with grave accent : À.

I found by googling that for FMX Memo, this can be done with chosing Platform for Controltype, I tested and it works, while with Styled it doesn't.

 

Since Controltype is not published in TComboEdit, I did it with code.

 

procedure TForm1.FormCreate(Sender: TObject);
begin
 ComboEdit1.ControlType := FMX.Controls.TControlType.Platform;
end;

 

No problem to compile, but I can't get the À by typing Alt+0192, while I can do it on the TMemo juste beside in this test app. I can even copy and paste the character form the FMX Memo to the FMX comboedit, but I would prefer a more straigthtforward way...

Is there any way I can do it ?

 

Share this post


Link to post

I found the answer, for those interested. Actually I had already done it for another control a few years ago but had completely forgotten !

I don't need to change Controltype, it works with Styled.

It is KeyUp which captures the code with 3 digits and the char, while just before Keydown captures the Alt and the 3 individual digits.

So in order not to capture twice the letters typed the normal way, I keep track of the last key captured by Keydown in a variable, DernierCodeKeydown, and I intercept the Alt+codes (except those of the "Control" Unicode category) in Keyup, and then I take into account the absence of "SetSeltext" in TComboEdit with copy SelStart and SelLength :

var
  Form1: TForm1;
  DernierCodeKeydown:word;

...

procedure TForm1.ComboEdit1KeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
 DernierCodeKeyDown := Key;
end;

 

procedure TForm1.ComboEdit1KeyUp(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
var gauche,droite:string;
begin
      if (Key <> DernierCodeKeyDown)
      then
      if (Ord(KeyChar) in [32..126, 160..172, 174..255])
      or (Ord(KeyChar) > 255) then
      begin
        if ComboEdit1.ReadOnly then
          Exit;
        gauche:=copy(ComboEdit1.Text,1,ComboEdit1.SelStart);
        droite:=copy(ComboEdit1.Text,ComboEdit1.SelStart+1+ComboEdit1.SelLength,length(ComboEdit1.Text));
        ComboEdit1.Text:=gauche+KeyChar+droite;
        ComboEdit1.SelStart := ComboEdit1.SelStart + 1;
      end
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×