Recent

Author Topic: [Solved] Strange bug with TEdit  (Read 1331 times)

lainz

  • Hero Member
  • *****
  • Posts: 4713
  • Web, Desktop & Android developer
    • https://lainz.github.io/
[Solved] Strange bug with TEdit
« on: November 08, 2021, 04:44:24 pm »
Hi, sometimes using a barcode scanner the TEdit is flipped, instead of writing from left to right it start writing from right to left.

No, there's no change on the position of the text, is always left aligned. The problem is the cursor that is always at the left of the characters, so anything you write goes to the left.

Notice that this mostly happens on slow hardware.
« Last Edit: November 08, 2021, 11:09:52 pm by lainz »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Strange bug with TEdit
« Reply #1 on: November 08, 2021, 05:29:33 pm »
Hi!

Do this on slow hardware:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1Change(Sender: TObject);
  2. begin
  3.   Edit1.SelStart:= Length(Edit1.Text);
  4.   AppliCation.ProcessMessages;
  5. end;
  6.  

This will always position the cursor at the mostright position.

Winni

ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Strange bug with TEdit
« Reply #2 on: November 08, 2021, 05:34:45 pm »
The problem occurs with EchoMode:=emNormal, without Events assigned and AutoSelect:=False?

I think that winni's suggestion worth a test more than mine.
« Last Edit: November 08, 2021, 05:39:41 pm by ezlage »

lainz

  • Hero Member
  • *****
  • Posts: 4713
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Strange bug with TEdit
« Reply #3 on: November 08, 2021, 11:09:39 pm »
Thanks winni it works.

But finally I solved it a bit differently, with an higher delay for the timer that prevents the search occur when the user types each character. From 20 ms to 100 ms and it works fine.

lainz

  • Hero Member
  • *****
  • Posts: 4713
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Solved] Strange bug with TEdit
« Reply #4 on: November 10, 2021, 02:58:46 pm »
Stranger enough...

Now I found this code was the problem:

Code: Pascal  [Select][+][-]
  1. procedure TPOSBerryLiteSearch.EnfocarBuscador;
  2. var
  3.   cp: TPoint;
  4. begin
  5.   if FEdit.Focused then
  6.     Exit;
  7.   cp := FEdit.CaretPos;
  8.   if FEdit.CanSetFocus then
  9.   begin
  10.     FEdit.SetFocus;
  11.     FEdit.CaretPos := cp;
  12.   end;
  13. end;

Focusing works badly on Linux. So I removed this code and everything works fine again.

 

TinyPortal © 2005-2018