Jump to content
Sign in to follow this  
Cristian Peța

Inch representation format in TEdit like controls

Recommended Posts

Customers asked me a long time ago for a feature to be able to introduce the length in inch in "12 3/16" format in a TEdit like control.

I've made a component for this but with the new TNumberBox in Delphi 10.4.2 I wonder if this is usual and if there are some components for this in Delphi world?

Edited by Cristian Peța

Share this post


Link to post
Guest
3 hours ago, Cristian Peța said:

I wonder if this is usual and if there are some components for this in Delphi world?

hi @Cristian Peța

 

if fact, you dont needs (necessary) of a "new" component!

  • in (pratically) all Delphi editons, you have "TMaskEdit"
  • this component/class ask just 3 parts of control the entry:  
    • Part1: you use "0" or "9", been "0" to say: entry mandatory!
    • Part2: to say if you desire the "mask" be store with your data on, let say, a table-field, like when using a TDateTime value, you see?
    • Part3: any char to represent (on screen) the values not typed on Edit! in my sample, "\/" it means that "/" not will be typed by user, because it is "part" of the mask!
  • My TMaskEdit have: EditMask = '00 0\/00;0;_'

image.thumb.png.6287673a9bcce16a51cc8c1f35717cf5.png

 

hug

Share this post


Link to post

There must be a bug in Delphi as "\/" does not make a literal from "/" but instead converts it to the system's date separator. Buhh.

Anyway, what if the user just want to enter 12"?

Share this post


Link to post

But if you read the Text property you have "12316". How to transform this into a value?

And what if the user want to type "12 15/16" or "123 1/4"?

 

And I have my control that do the job but was wondering if there are some other edit controls for this. Maybe it's not so common.

Edited by Cristian Peța

Share this post


Link to post

Now I see there is an TMaskEdit.EditText property. But it looks odd if you have a mask like this "0000 00\/00;0;_" and want to write only "1 1/2"

Share this post


Link to post
Guest
2 hours ago, Cristian Peța said:

Now I see there is an TMaskEdit.EditText property. But it looks odd if you have a mask like this "0000 00\/00;0;_" and want to write only "1 1/2"

just use "0000 00\/00;1;_"  to stored the mask with text!

  • there is not problem with use "\/" or any other char like "\X" --> "X" as a "literal value not typed by user as "/" !
    • it's silly comment! poor baby! :classic_love:

 

image.thumb.png.8ca92868ef1b6d0e1ec35d706946c13e.png

 

if need not type some value, like above, just use "SPACEBAR" to jump to next part of mask!

  • put the "0" (mandatory value) on "first chars on mask" as my sample above!
  • you can put any char as "showed on screen - like my "*" now, include "space or == char(0) using ALT+255 === old code many used on D.O.S. do you remember?"
  • of course, if you dont "want it" on resulted = maskedit.EditText, try "StringReplace()" function to remove all "*" or any other char on string-resulted!
    • StringReplace( maskedit.EditText, "*", '', [ options = replace all, and, ignore case]
    • using a char different, like me, "*" for screen and ' ' for separate the parts, would be good, in case, using "StringReplace". then, you will preserve the "spaces" if you want it
  • you see?

 

image.thumb.png.3e5fbb129befc09cd3f765390b121fc9.png

 

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add('MaskEdit1.Text = ' + MaskEdit1.Text );
  Memo1.Lines.Add('MaskEdit1.EditMask = ' + MaskEdit1.EditMask );
  Memo1.Lines.Add('MaskEdit1.EditText = ' + MaskEdit1.EditText );
  Memo1.Lines.Add('MaskEdit1.EditText = ' + StringReplace(MaskEdit1.EditText, '*', '', [rfReplaceAll, rfIgnoreCase]));
end;

 

 

hug

Edited by Guest

Share this post


Link to post

Nothing against above stuff.

 

Another approach can be usage of TEdit, parse data on your own to get a float as result to work with.

Should have a better look, but users must be told somewhere how to enter data that it works.

 

I found this code by Andreas Rejbrand to getting you started.

Share this post


Link to post
Guest
16 minutes ago, KodeZwerg said:

Another approach can be usage of TEdit, parse data on your own to get a float as result to work with.

hi @KodeZwerg

 

for sure, there is many others ways, and, TEdit is one for sure! you're right!

 

But TMaskEdit is a "evolution" (if I can say some like that) of TEdit. We should see the "ancestral" of two class!

  • look how many code using "TEdit" and "TMaskEdit" :classic_rolleyes:

 

TMaskEdit = class(TCustomMaskEdit)

  • TCustomMaskEdit = class(TCustomEdit)  <----
  • TCustomEdit = class(TWinControl)
  • TWinControl = class(TControl)
  • TControl = class(TComponent)
  • TComponent = class(TPersistent, IInterface, IInterfaceComponentReference)

TEdit = class(TCustomEdit)  <----

  • TCustomEdit = class(TWinControl)
  • TWinControl = class(TControl)
  • TControl = class(TComponent)
  • TComponent = class(TPersistent, IInterface, IInterfaceComponentReference)
     

 

hug

Edited by Guest

Share this post


Link to post
Guest

put your photo like "DateSepator" and will see the bug bigger that this! :classic_cheerleader:

  • insane use of property is a brain-bug too!
Edited by Guest

Share this post


Link to post

@emailx45

Sorry that I mentioned that a TEdit looks better.

 

By reading complete thread again, he asked if new Delphi got native stuff to do. He already has its own component so i am out.

Share this post


Link to post
Guest
20 minutes ago, KodeZwerg said:

By reading complete thread again, he asked if new Delphi got native stuff to do. He already has its own component so i am out.

no. no. no. It's good have a new opinion or view!

you're wellcome

 

me, can be wrong too! dont worry!

 

 

hug

Edited by Guest

Share this post


Link to post
4 hours ago, emailx45 said:
  • insane use of property is a brain-bug too!

It will be the system default by default. So in my case it's __ __.__

Looks like a bug in MaskEdit

Edited by Attila Kovacs

Share this post


Link to post

folks -- please step down a little and focus on the topic. If you don't want to contribute anything substantive - even for the time being - that's okay.
Together, we should be careful not to lapse into personal affronts.

Share this post


Link to post

Yeah, thx. We found a bug in the RTL/VCL and a better way to communicate. I see no offensive material.

Edited by Attila Kovacs
  • Haha 1

Share this post


Link to post
Posted (edited)

I have a half baked component that accepts metric or imperial.

Half baked because

in metric mode it works in mm only

In Imperial mode it works in inches only.

It does not display fraction format but accepts it

 

so these are all valid input

 

6'3"

5m23cm

1 1/5M

3 1/2"

3' 1/2"

12ga

 

If anyone wants to help improve the code let me know, and I will stick it on Github.

 

 

 

Edited by Bernard

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
Sign in to follow this  

×