Indeed brackets around a number make it a non number by default (being it float or otherwise).Indeed Molly - turn it on it's head :) - - - I'm using a TEdit
Try to look at it from the other end, namely the component that displays the value. What are you currently using for that ?
If those are simple numeric display components then you might be able to tweak those to display the number(s) as you'd like them to be displayed.Your phrase 'simple numeric display components' makes me think that there ARE edit components that don't use strings, but numbers, as the displayable property (ie, .text or .caption) but I've yet to discover any. (I have only been using Laz since mid August as you know :) )
In the case of your floattostr example, you can replace that with your own function, make the negative check and return the value bracketed. The opposite can also be done in case you wish to stay consistent.That is my 'work-around';
Easier would be to create your own (record) type and use operators to convert from your format to a real float (and back again).That's an interesting possibility - - - not that I have any real idea as to how to go about it!
Your phrase 'simple numeric display components' makes me think that there ARE edit components that don't use strings, but numbers, as the displayable property (ie, .text or .caption) but I've yet to discover any. (I have only been using Laz since mid August as you know :) )
I'm using a TEditIn that case i am confused a little.
Your phrase 'simple numeric display components' makes me think that there ARE edit components that don't use stringsDon't worry about being new to Lazarus, we all were at one point :-) (i still am for that matter).
In any case it still needs a string to display.Of course but, it was not clear from your original question that you required both input and output. Different circumstance, different approach :)
That's an interesting possibility - - - not that I have any real idea as to how to go about it!I'm still stuck with the need to do an explicit conversion. I thought that implicit conversion worked for record class operators (in opposite to global operators) so i must be (doing something) wrong there.
I'm still using
if pos('(',inp)>0 then begin
Or a little more simple but less input error-proof :I don't have a problem with input checking, it would normally be '-20' rather than '(20)' and in fact that last would display an error. Once checked the display would change to £(20.00)
However, I see that http://www.freepascal.org/docs-html/rtl/sysutils/formatfloat.html can also work here, thou I've never used it for the exact task.That looks as if it would be OK but doesn't address the return to a value; which is where my issue really is.
Your phrase 'simple numeric display components' makes me think that there ARE edit components that don't use strings, but numbers, as the displayable property
TFloatSpinEdit TFloatSpinEditEx.
Bart
I am an accountant here in Brazil and and i prefer entry accounting data with two differents Tedits. It's reduce entry errors when doesn't need to input negative values.
Rethink the possibility of creating separate entry fields between debit and credit without negative entrys.
And the output formatting can be done by the difference of this fields.
I am an accountant here in Brazil and and i prefer entry accounting data with two differents Tedits. It's reduce entry errors when doesn't need to input negative values.
Rethink the possibility of creating separate entry fields between debit and credit without negative entrys.
And the output formatting can be done by the difference of this fields.
J-G I use jujiboutils package and could help you because have a value and format propertiesI already have the jujiboutils package and have looked at the offerings there but all the FloatEdit components have a label which can't be hidden so totally useless for this application.
J-G I use jujiboutils package and could help you because have a value and format propertiesI already have the jujiboutils package and have looked at the offerings there but all the FloatEdit components have a label which can't be hidden so totally useless for this application.
I already have the jujiboutils package and have looked at the offerings there but all the FloatEdit components have a label which can't be hidden so totally useless for this application.
To hide the label in code:Thanks for your input jujibo.To hide the label in design mode, simply type a blank space in property editor (Editlabel->Caption)
JLabeledFloatEdit1.EditLabel.Visible:= False;
To read and set values, use the property Value:At design time it seems that there is no 'Value' property so it cannot be set to 0.00 and although I've set the 'Decimals' to 2 and the DisplayFormat to '9999.99' or '####.##' , at run time, the display is [ nil] and although the component takes focus, it doesn't take keyboard entry. I've tried both FloatEdit and CurrencyEdit.
JLabeledFloatEdit1.Value:= 10.5; f:= JLabeledFloatEdit2.Value;
At design time it seems that there is no 'Value' property so it cannot be set to 0.00 and although I've set the 'Decimals' to 2 and the DisplayFormat to '9999.99' or '####.##' , at run time, the display is [ nil] and although the component takes focus, it doesn't take keyboard entry. I've tried both FloatEdit and CurrencyEdit.
:D )
This is all very interesting for potential future development but it doesn't actually address the issue of taking the string (20.00) and converting it to the value -20 ... but Molly has addressed that very effectively (even though I'm still working on the 'Understanding' of that code :D )
At design time it seems that there is no 'Value' property so it cannot be set to 0.00 and although I've set the 'Decimals' to 2 and the DisplayFormat to '9999.99' or '####.##' , at run time, the display is [ nil] and although the component takes focus, it doesn't take keyboard entry. I've tried both FloatEdit and CurrencyEdit.
:D )
Apologies, jujibo, I had inadvertantly selected from the DB Version. Now I've checked the 'normal' package the components do work as expected and I can set the default value to 0.00.At design time it seems that there is no 'Value' propertyYes, Value property is available at design time (see attached image).
Quote from: J-GThis is all very interesting for potential future development but it doesn't actually address the issue of taking the string (20.00) and converting it to the value -20 )
Do you want to display negative numbers like "(20)" for -20? or you really want to type (20) and being translated to -20? For the first case would be easy to implement a new display property for negative numbers. For the second case, I don't see the utility but could be managed too.
The first case is exactly what I would like - and if the colour could also be set to red that would also be useful. There would be a small matter of display alignment since the trailing bracket should protrude beyond the 'pence' to keep the decimal point aligned.
Mostly yes.Quote from: J-GThe first case is exactly what I would like - and if the colour could also be set to red that would also be useful. There would be a small matter of display alignment since the trailing bracket should protrude beyond the 'pence' to keep the decimal point aligned.
Well, I can implement two properties:
NegativeDisplayFormat (if empty it usesDisplayformat)
NegativeFontColor
About the gap because the parenthesis is not so easy... probably adding a space to DisplayFormat may be enough
Does this fit your needs?
You can get it in latest lazarus-ccr svn code (rev 5629) . Get, compile and install.
As you can see, there is no need for special StrToFloat. :)
Only problem I have is that I have no idea how to 'Get' rev 5629In case not using svn, you can point your browser to lazarus ccr svn on sourceforge (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/), then press the link "download snapshot" which will let sf generate a zip file for you which includes the latest (my time of writing that was rev. 5630).
Only problem I have is that I have no idea how to 'Get' rev 5629In case not using svn, you can point your browser to lazarus ccr svn on sourceforge (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/), then press the link "download snapshot" which will let sf generate a zip file for you which includes the latest (my time of writing that was rev. 5630).
fwiw:having a separate component is/was another option that would help your case the best way possible (i' just did not had the time to do it myself, so thank you very much jujibo).
I am downloading the snapshot but I was anticipating an update to the jujiboutils package which I could simply add to my existing installation of Laz 1.6 whereas I feel that I will have a new version of Lazarus.
Am I being a 'wuss' ?? :)
I am downloading the snapshot but I was anticipating an update to the jujiboutils package which I could simply add to my existing installation of Laz 1.6 whereas I feel that I will have a new version of Lazarus.Either you know what version control does or you don't. Nothing "wuss" about that :)
Am I being a 'wuss' ?? :)
...(at least it should. I am a bit confused about jujibo's reaction as that would indicate my directions won't work ?).
Ah - a kindred spirit :) even though I might feel like a wuss.I am downloading the snapshot but I was anticipating an update to the jujiboutils package which I could simply add to my existing installation of Laz 1.6 whereas I feel that I will have a new version of Lazarus.Either you know what version control does or you don't. Nothing "wuss" about that :)
Am I being a 'wuss' ?? :)
In case you have a svn client installed on your computer, you literally have a set of (commandline-)tools that allow you to download specific portions of the source-tree.Once I'd unzipped the download I could better see what I had and now have an understanding of the concept of version control.
By downloading a snapshot, you've literally downloaded the complete source-tree. This includes all those other components that are present in the lazasrus ccr (and that are probably of no direct interest for you).
In case of jujiboutils, you can do with only extracting the folder lazarus-ccr-svn-5630\components\jujiboutils from the zip file and install the component from that sources, as any other package./component
(at least it should. I am a bit confused about jujibo's reaction as that would indicate my directions won't work ?).I've re-read jujibo's reaction (and the second response) and suspect that the version I now have may not be the best. Since there is no time pressure, I think my best bet is to wait 'til tomorrow and download again.
@J-G:Thanks Molly - that's a timely warning, I wouldn't have considered looking for an 'Uninstall Packages' option but I've now found it.
I forgot to mention: make sure you've un-installed the previous version of jujibo utils before attempting to install the updated version from source.
@J-G:Thanks jujibo, I'm sure that will be useful for all users. When writing components of this nature it is difficult to foresee what other users may think is useful and great that you are in a position to take suggestions on board.
I have implemented custom color for negative values in every jujiboutils numeric component DB aware and non DB aware (integer, float and currency). Mask for negative value format was already working. You can download latest code from lazarus-ccr SVN
In your case, set DisplayFormat to: #,0.00€;(#,0.00)€ and NegativeColor to cl_red to get the desired result.
I suggest you to use currency components to deal with currency values instead of float one.That would have been my intention as well, thanks.
Thanks jujibo, I'm sure that will be useful for all users. When writing components of this nature it is difficult to foresee what other users may think is useful and great that you are in a position to take suggestions on board.
Since I am UK based and using the £ preceding the value, I presume that £#,0.00;£(#,0.00) will work as well.
@jujibo where i can download the last version? Thank you.
*Spanish: Hola, uso constantemente el componente que has desarrollado, podría decirse que son un fan de los componentes jujibo :D y la verdad no entiendo nada ni de SVN ni trunk y quisiera contar con la última versión, uso Lazarus 1.6. Gracias por el excelente trabajo.
Saludos.