Recent

Author Topic: TEdit for E-format numbers  (Read 1354 times)

fdsingleton

  • New Member
  • *
  • Posts: 31
TEdit for E-format numbers
« on: February 23, 2018, 11:47:01 pm »
Win32  Windows 7

I work with large and small numbers, and have applications where in some cases the string delivered to the TEdit text is like 1.234567E-10.  However, when wanting auto selection for editing only the 1.234567 is selected and the E-10 is not.  This is awkward for the user.  At one point I added a separate SelectAll statement to get the desired results.  However, it would be easier for me if I did not have to change this for many controls.  Am I missing some property shortcut?

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TEdit for E-format numbers
« Reply #1 on: February 24, 2018, 12:37:11 am »
You mean: you select the edit and want the entire text to be selected, not just the mantissa part? This is working correctly for me on Win10 and Win7 (Laz 1.8 and trunk). But when I double-click in the edit control the selection does not extend over the entire string, similar to what you describe.

You could fix this by subclassing the TEdit and override its DblClick. Add this unit to the interface uses clause of every unit of your form containing TEdit controls.

IMPORTANT: the unit must be at the end of the uses list. This makes the compiler use this modified TEdit instead of the original one whenever it sees a TEdit.

Code: Pascal  [Select][+][-]
  1. unit MyEdit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,StdCtrls;
  9.  
  10. type
  11.  
  12.   TEdit = class(StdCtrls.TEdit)
  13.   protected
  14.     procedure DblClick; override;
  15.   end;
  16.  
  17. implementation
  18.  
  19. {$R *.lfm}
  20.  
  21. procedure TEdit.DblClick;
  22. begin
  23.   inherited;
  24.   SelectAll;
  25. end;
  26.  
  27. end.

fdsingleton

  • New Member
  • *
  • Posts: 31
Re: TEdit for E-format numbers
« Reply #2 on: February 24, 2018, 03:25:18 am »
Thank you very much.  This works great. 

 

TinyPortal © 2005-2018