Recent

Author Topic: Tedit issues  (Read 593 times)

trev

  • New member
  • *
  • Posts: 21
Tedit issues
« on: June 12, 2019, 03:55:57 am »
I'm in the process of converting an application I wrote in FMX in Delphi 10.2.1 to Lazarus. This is just my second day using Lazarus (although I used it a decade ago to convert a Delphi VCL and a Kylix program to tun on OS X).

I've noticed some odd behaviour of the Tedit control. The Tedit control is on a visible, active TTabSheet. Tested so far only on macOS 10.14.5.

1) Using Tedit.SetFocus in code does not seem to work at all (clicking on the control does set focus).

So, I thought I'd work around the issue by:

2) In the OnMouseEnter handler I set the focus to the TEdit control. This only works if the mouse pointer goes over the far right of the control. Otherwise it looks like the event never triggers.

Any ideas? A bug maybe? Or an ID10T error?
« Last Edit: June 15, 2019, 08:46:14 am by trev »
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #1 on: June 12, 2019, 05:36:36 am »
for issue #1 it's either a bug or a missing functionality.
SetFocus is rarely used, so it's possible nobody noticed the misbehavior before

for issue #2 what Lazarus version are you using?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

trev

  • New member
  • *
  • Posts: 21
Re: Tedit issues
« Reply #2 on: June 13, 2019, 06:15:16 am »
I'm using Lazarus 2.02 (32 bit Carbon) to produce macOS 64 bit binaries.
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

wittbo

  • Jr. Member
  • **
  • Posts: 54
Re: Tedit issues
« Reply #3 on: June 13, 2019, 10:16:39 am »
Not a direct answer, but more some kind of hint. Nearly 20 years ago there was a set of very nice and effective edit components for Delphi (TEditN, TTMEditN, TDBEditN) as a replacement of the Standard Delphi components. I loved them because of their additional features and when being on Delphi, I used them every time. Jose Maria Gias; his homepage isn't longer online, use this one: http://delphi.icm.edu.pl/newl/midxd30f.htm
Since about 3 years I'm on Lazarus (MacOS/Cocoa and Win10). Actually I'm porting his package to Lazarus, it's nearly ready to use. I will send a message upon finalizing.
-wittbo-
Lazarus 2.0.0  with FPC 3.0.4
MacOS 10.14.3 MacOS 10.13

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #4 on: June 13, 2019, 03:17:02 pm »
I'm using Lazarus 2.02 (32 bit Carbon) to produce macOS 64 bit binaries.
it should be working for 2.0.2
could you please provide a sample project?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

trev

  • New member
  • *
  • Posts: 21
Re: Tedit issues
« Reply #5 on: June 14, 2019, 12:28:29 pm »
Sample project attached.

I include three attempts to edit1.SetFocus:

 - Procedure TForm1.TabSheet2Show(Sender: TObject);
 - Procedure TForm1.PageControl1Change(Sender: TObject);
 - Procedure TForm1.Button1Click(Sender: TObject);

All fail. Thanks for looking!
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

lucamar

  • Hero Member
  • *****
  • Posts: 1536
Re: Tedit issues
« Reply #6 on: June 14, 2019, 03:14:18 pm »
I had a similar problem in Linux and now I always use SetFocusedControl(), Also the TabSheet must be visible so I set the focusing in a handler for the TPageControl.OnChange event.

It usually works--not always, Gtk being quite temperamental, but most of the time it does.

A small example:

Code: Pascal  [Select]
  1. procedure TMainForm.EditPagesChange(Sender: TObject);
  2. { EditPages is a TPageControl }
  3. begin
  4.   UpdateStatus;
  5.   { CurrentEditor returns the TMemo linside the current TabSheet }
  6.   if Assigned(CurrentEditor) then
  7.     SetFocusedControl(CurrentEditor);
  8. end;
  9.  
  10. function TMainForm.MemoInTab(ATab: TTabSheet): TMemo;
  11. { This returns the memo inside a tabsheet,
  12.   and is called from GetCurrentEditor }
  13. var
  14.   i: Integer;
  15. begin
  16.   Result := Nil;
  17.   if Assigned(ATab) then begin
  18.     for i := 0 to ATab.ControlCount-1 do
  19.       if ATab.Controls[i].InheritsFrom(TMemo) then begin
  20.         Result := ATab.Controls[i] as TMemo;
  21.         Break;
  22.       end;
  23.   end;
  24. end;
« Last Edit: June 14, 2019, 03:21:36 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

trev

  • New member
  • *
  • Posts: 21
Re: Tedit issues
« Reply #7 on: June 14, 2019, 04:03:38 pm »
I had a similar problem in Linux and now I always use SetFocusedControl(), Also the TabSheet must be visible so I set the focusing in a handler for the TPageControl.OnChange event.

Thanks, but even a Button click event on the tab page fails to set the focus with edit.SetFocus and/or SetFocusedControl(edit).
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #8 on: June 14, 2019, 06:09:53 pm »
Sample project attached.
Thank you. I can see the problem (the issue is with tab change events actually within Cocoa-Widgetset. Not much you can do about it.).

If you comment out code of
 - Procedure TForm1.TabSheet2Show(Sender: TObject);
 - Procedure TForm1.PageControl1Change(Sender: TObject);

You'll see that
 - Procedure TForm1.Button1Click(Sender: TObject);
would work.

Which is only a little relief

But I'd think this is fixable. Stay tuned.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #9 on: June 14, 2019, 09:19:13 pm »
if you update your trunk to r61393.
you should have it working now.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

trev

  • New member
  • *
  • Posts: 21
Re: Tedit issues
« Reply #10 on: June 15, 2019, 03:26:46 am »
Thanks! That was quick. I've doubled my Patreon support :)
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

trev

  • New member
  • *
  • Posts: 21
Re: [Solved] Tedit issues
« Reply #11 on: June 15, 2019, 08:30:21 am »
Small unwanted side-effect  :-[

Code: [Select]
procedure TForm1.deviceEditKeyUp(Sender: TObject);
var
  i: integer;
  tempStr: String;
begin
  try
    for i := 0 to picListBox.Items.Count - 1 do
      if(AnsiStartsText(deviceEdit.Text, picListBox.Items[i]) = True) then
        begin
          picListBox.ItemIndex := i;
          picListBox.TopIndex := picListBox.ItemIndex;
          break;
        end;
   finally
    if(i = picListBox.Items.Count - 1) then
      begin
        MakeBeep;                             // Alert user
        tempStr := deviceEdit.Text;
        delete(tempStr, Length(tempStr), 1);  // remove unmatching char
        deviceEdit.Text := tempStr;
      end;
   end;
end;

The procedure above checks what the user has typed in the edit box against the list box entries and either breaks out of the for loop when there is a partial match at the start of an entry or falls through to beep and remove the character that does not match any entries.

However, when deviceEdit.SetFocus has been executed in code (as opposed to clicking the edit box), the procedure fails because AnsiStartsText never matches for some reason.
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #12 on: June 15, 2019, 08:17:55 pm »
what is deviceEditKeyUp?
it looks like an event handler. But keyup event handler comes with additional parameters (key code and shift state)
If it's an event handler, what event does it process?
as usual - sample projects help.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

trev

  • New member
  • *
  • Posts: 21
Re: Tedit issues
« Reply #13 on: Today at 01:40:06 am »
what is deviceEditKeyUp?
it looks like an event handler. But keyup event handler comes with additional parameters (key code and shift state)

The compiler kept complaining (hinting) about the unused key and shift args, removing them shut it up and didn't seem to cause any issues.

Quote
If it's an event handler, what event does it process?
as usual - sample projects help.

It processes key strokes in the deviceEdit and highlights the corresponding matching entry in the ListBox.

I'll come up with a sample project to show the behaviour.
Lazarus 2.1 r61397, FPC 3.04, macOS 10.14.5

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2094
    • havefunsoft.com
Re: Tedit issues
« Reply #14 on: Today at 01:51:48 am »
The compiler kept complaining (hinting) about the unused key and shift args, removing them shut it up and didn't seem to cause any issues.
I've a bad feeling about this!

please either restore the parameters, or reassign the event. Just to be sure they're there.
In order to satisfy the compiler, you can right click on the message (in Messages) window and select any option you'd like to ignore the hint.
(I typically use "Hide with project option")
« Last Edit: Today at 01:54:24 am by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz