Change EditBox default Pedding and Apply Input Mask lazarus / 21-General ---------------------------------------------------------------------- Mudassir · 2024-02-04 17:38 Hi, I used to make data-centric applications in Visual Foxpro and am an absolute beginner to Lazarus / Pascal.. trying to learn about Lazarus Controls /Widgets, Events and Methods. I tried to make a simple dummy data entry (as attached) and seek help  to solve some of my queries. 1. [SOLVED] Can not find a good way to bound Edit Box / Masked Edit Box to accept numeric input in required format. Same for Date input. Please guide me to use Input Masks properly. In, VFP we used to put Input Masks like 999.99 and set value of TextBox to 0 to make them accept numeric values in required format. I see Lazarus is such a powerful tool, there must be something similar in here too, I must be missing something. Solution: As Bart suggests , it would be good to use TSpinEdit and TFloatSpinEdit controls (look at Misc controls) to work with numeric values. 2.[SOLVED] The RoundTo() function seems to work great but I want the output to have two (fixed) decimal places and to keep it in numeric format, if possible. Like 125.00 or 17.80 please. Solution: As Jamie suggests WriteStr(OutputString;InPutStringFromEditControl:4:2); it's a good way to format numeric value in string format. 3. In Linux Mint, there is too much padding applied to Most of the Controls (as seen in attached screenshot)... Please suggest some way to control the padding & margin of the widgets. It would look too odd when deployed to other machines. Thank for going through my queries. Looking forward to have helpful information. ---------------------------------------------------------------------- Bart · 2024-02-04 18:07 Consider using a TFloatSpinEdit for floating point input. You can set Decimals property and hide the spinners if so required. You can set a MinValue and a MaxValue to limit the input. As a bonus, you it has a Value property of type Double, sou you can get and set the Value directly (without converting to and from string). For dates there is a TDateEdit control. It has a built in calendar and you can force the user to use that (forbidding the user to enter dates manually). If you use a TMaskEdit a sample EditMask for a date (dd-mm-yyyy) could be '!90/90/0000;1;_' For a floating point value with 3 digits and 2 decimals I would use '!999.99;1;0' and then use EditText (not Text) when you try to convert it to a float. (The zero at the end of the EditMaks is the caharcter used as "blank" e.g. where the user did not enter a character or deleted a character. If in this case the control shows '000.00' the Text property will be '   .  ' (all zero's replaced with a space), but EditText will be '000.00'. This way (using EditText) you can be certain that it will convert to a floating point number (as long as your DecimalSeparator actually is a dot ('.')). Long time ago when I switched from Delphi 3 to Lazarus, I used TMaskEdit for floating point entries (and time entries). At that time TMaskEdit of Lazarus was almost completely broken, so I participated in it's development and became it's maintainer. In the process of fixing the MaskEdit unit I "ported" most of my Delphi programs to Lazarus and ended up using TFloatSpinEdits instead. They offer more flexibility, min- and max-values, users can increment/decrement with cursor-keys and it's Value property is always a valid floating point. Also you don't have to handle the exception that is raise when the user enters invalid text in the TMaskEdit and then leaves the control... (You'll have to have an Application.OnException handler in order to do so.) A better usecase for a TMaskEdit could e.g. be ZIP codes (at least in NL, these have a fixed format) or an IPv4 string (EditMask: '!999.999.999.999;1;0' and then use EditText instead of Text). Bart ---------------------------------------------------------------------- Mudassir · 2024-02-04 18:57 Quote from: Bart on February 04, 2024, 07:07:16 pmConsider using a TFloatSpinEdit for floating point input. You can set Decimals property and hide the spinners if so required. You can set a MinValue and a MaxValue to limit the input. As a bonus, you it has a Value property of type Double, sou you can get and set the Value directly (without converting to and from string). Thanks Bart, The TFloatSpinEdit works perfect! Best suited as the control is made specifically for that purpose. Same should TSpinEdit do (without Floating Point) of-course. Would prefer to use them. Great to know you've been a maintainer of the control I used several EditMasks to get MaskedEdit Control work but it (sorry to say) lacks functionality. When we try to enter 12.25 it accepts 12_.25 that's a weird behavior I could not control. With FloatSpinEdit / SpinEdit controls it would also be easier to validate input and do calculations as the control holds numeric value. QuoteFor dates there is a TDateEdit control. It has a built in calendar and you can force the user to use that (forbidding the user to enter dates manually). Thanks again for the suggestion of TDateEdit, accepts manual input perfectly. Can't get this functionality with a control made to accept Text / General Input. I just can't find some property to show / accept Year in 4 digits yet. QuoteA better usecase for a TMaskEdit could e.g. be ZIP codes (at least in NL, these have a fixed format) or an IPv4 string (EditMask: '!999.999.999.999;1;0' and then use EditText instead of Text). Agreed, in these cases it would work good. Thanks a lot ---------------------------------------------------------------------- Mudassir · 2024-02-04 19:14 I noticed there is plenty of padding in Properties Entry Box but the Edit Box or Controls really look weird with too much padding. Check attached screenshot. Looking for a solution to control / override default padding please. ---------------------------------------------------------------------- KodeZwerg · 2024-02-04 21:43 Quote from: Mudassir on February 04, 2024, 08:14:08 pmI noticed there is plenty of padding in Properties Entry Box but the Edit Box or Controls really look weird with too much padding. Check attached screenshot. Looking for a solution to control / override default padding please.Showing a part of the IDE with formdesigner is to me not that much helpful since padding can mean a lot when talking about visual locations. When something aint shiny, it is best to take a snapshot, open that in a graphics editor of your choice, put a red rectangle around "before", copy that part twice to a new image, modifiy the second into an "after" so we exactly know how to help you best. Regards,   KodeZwerg. ---------------------------------------------------------------------- Bart · 2024-02-04 21:48 Quote from: Mudassir on February 04, 2024, 07:57:30 pmWhen we try to enter 12.25 it accepts 12_.25 that's a weird behavior I could not control. Your EditMask is '999.99' The 9 means a number but not required, so if you want to force the user to enter a number at that position, use a '0' in the EditMask. All this is Delphi compatible, which is a requirement. And yes, exactly this is the reason why you should not use it this way. As I explained, using '999.99;1;0' as EditMask, the user cannot erase the '0' characters in the control, so the there will always be a valid floating point number there. The drawback being that '2.2' will be displayed as '002.20'. Bart ---------------------------------------------------------------------- jamie · 2024-02-04 22:30 Or use the OnEditingDone event and use the WriteStr(OutputString;InPutStringFromEditControl:4:2); and reset the edit caption string using the outputstring;  This allows the user to be a little free with their typing and gets corrected here ---------------------------------------------------------------------- Mudassir · 2024-02-05 08:51 Quote from: Bart on February 04, 2024, 10:48:09 pmQuote from: Mudassir on February 04, 2024, 07:57:30 pmWhen we try to enter 12.25 it accepts 12_.25 that's a weird behavior I could not control. Your EditMask is '999.99' The 9 means a number but not required, so if you want to force the user to enter a number at that position, use a '0' in the EditMask. All this is Delphi compatible, which is a requirement. And yes, exactly this is the reason why you should not use it this way. As I explained, using '999.99;1;0' as EditMask, the user cannot erase the '0' characters in the control, so the there will always be a valid floating point number there. The drawback being that '2.2' will be displayed as '002.20'. Thanks for the explanation Bart, I tried that mask i.e. "999.99;1;0" already. The result was 00009.95 Kgs in Quantity that's a valid input but not a REAL world thing (sorry). While working on some Billing / Accounting package, I've to deal more with numeric inputs than strings. So, like you explained earlier, controls like TSpinEdit and TFloatSpinEdit seems more viable, though I've not used them practically yet. Will check the controls in full practical run and decide which way should I go. My experience (not related to the query): One of the main reasons for people like me still glued to VFP or even FoxPro is that our clients are so addicted to the applications they've been using for decades. And we are not able to find any alternate to VFP, with which we can provide them the same (if not better) user experience. Also the features / ease-of-access in most MS Languages made programmers too lazy to use any real language. So, (not easy to say but) most programmers depending on some MS platform find no way when it is Discontinued ---------------------------------------------------------------------- Mudassir · 2024-02-05 09:22 Quote from: jamie on February 04, 2024, 11:30:10 pmOr use the OnEditingDone event and use the WriteStr(OutputString;InPutStringFromEditControl:4:2); and reset the edit caption string using the outputstring; This allows the user to be a little free with their typing and gets corrected here  Thanks Jamie, that's a good way to Format, especially when used to show figures in lists / grids. As I am just beginning with Lazarus / Pascal, every bit of information / trick is too helpful. It's so like the str() function used in VFP: str(,,) For numeric input, will this not be better to use control/widget which support numeric values? (Just a thought) As it does not seem so easy with user inputs. Format the input, convert to numeric, validate input, convert again to store in database? ---------------------------------------------------------------------- Mudassir · 2024-02-05 11:39 Quote from: KodeZwerg on February 04, 2024, 10:43:38 pmShowing a part of the IDE with formdesigner is to me not that much helpful since padding can mean a lot when talking about visual locations. When something aint shiny, it is best to take a snapshot, open that in a graphics editor of your choice, put a red rectangle around "before", copy that part twice to a new image, modifiy the second into an "after" so we exactly know how to help you best. Sorry if I was not able to explain the problem. Attached two screenshots again to illustrate how padding is added to controls when using different themes. It's a great feature of Lazarus to read system / environment setting and apply them to the controls to give native look but there must be some way to change appearance / color / padding etc. The padding is added to the controls automatically (made no change to the height manually). Please see the runtime look of same form / application. In the first screenshot (as shared earlier), the height of control is 40px with a lot of padding - taken with Adapta Nokto gtk theme on system. While in the second screenshot (output-2), the height of control is 28px with minimal padding - taken with Mint-Y Dark Aqua. I want to find a way to "control" the padding applied to widgets automatically. Like, for example, if the system / auto padding to be applied to widgets is more than 4px then change it to 4px.