T-edit component for money lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- Kalevi · 2022-09-13 11:12 Has someone made a T-Edit component that can only be written in monetary value? ---------------------------------------------------------------------- KodeZwerg · 2022-09-13 11:18 https://wiki.freepascal.org/TMaskEdit maybe? ---------------------------------------------------------------------- Kalevi · 2022-09-13 11:30 I haven't been able to make a mask that would work. In addition, an empty field should have, for example, 0:00. ---------------------------------------------------------------------- KodeZwerg · 2022-09-13 11:40 Quote from: Kalevi on September 13, 2022, 01:30:20 pmfor example, 0:00I do not clear understand, 0:00 would be a time value not a monetary, or? I might miss something. ---------------------------------------------------------------------- Kalevi · 2022-09-13 11:43 I've made money Edit componetin, but there's a problem with it that you can write characters other than numbers on it. Here's a file unit RahaEd; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, GenRutii,   LCLIntf, LCLType, LMessages, Messages; type   TRahaEd = class(TEdit)   private      FArvo: Currency;   protected      vanhatext: String;     procedure KeyPress(var Key: Char); override;     procedure DoEnter; override;     procedure DoExit; override;   public      Muokattu: Boolean;     procedure AsetaArvo(I:Currency);   published    property Arvo: Currency read FArvo write AsetaArvo ;   end; procedure Register; implementation procedure Register; begin   RegisterComponents('Standard',[TRahaEd]); end; function LaskeKaava(s: String): String; var  ope: Char;      tot, luku: Currency;      function SeuraavaLuku(var ss: String): Currency;      begin        Result := 0;        while (Length(ss) > 0) and (ss[1] >= '0') and (ss[1] <= '9') do begin           Result := (Result * 10) + (Ord(ss[1]) - Ord('0'));           ss := Copy(ss, 2, Length(ss)-1);           end;      end; begin   Result := '';   tot    := SeuraavaLuku(s);   while Length(s) > 0 do begin      ope  := s[1];      s    := Copy(s, 2, Length(s)-1);      luku := SeuraavaLuku(s);      case ope of        '*': tot := tot * luku;        '/': tot := tot / luku;        '+': tot := tot + luku;        '-': tot := tot - luku;        end;      end;   Result := MaaraToStr(tot); end; procedure TrahaED.AsetaArvo(I:Currency); begin   FArvo := I;   Text := MkToStr(FArvo);   SelectAll; end; procedure TrahaED.KeyPress(var Key: Char); begin   if ((Key >= Char(VK_F1)) and (Key <= Char(VK_F12))) then   else   if ((48 > Integer(Key)) or (Integer(Key) > 57)) and      not ((32 < Integer(Key)) or (Key = Char(VK_BACK)) or       (Key = Char(VK_DELETE)) or (Key = DecimalSeparator)) then      Key := Char(0) ;   inherited KeyPress(Key);   if Text <> '-' then      FArvo := StrToMk(Text); end; procedure TrahaED.DoEnter; begin   Text := MkToStr(FArvo);   vanhatext := Text;   inherited DoEnter; end; procedure TrahaED.DoExit; begin   if (Pos('*',Text) > 0) or (Pos('/',Text) > 0) or(Pos('+',Text) > 0) or(Pos('-',Text) > 1) then      Text := LaskeKaava(Text);   FArvo := StrToMk(Text);   Text := MkToStr(FArvo);  { etunollat pois }   Muokattu := vanhatext <> Text;   inherited; end; end. ---------------------------------------------------------------------- KodeZwerg · 2022-09-13 11:46 https://wiki.lazarus.freepascal.org/jujiboutils I hope that this will make you happy and solve your problem with currencies. (TJLabeledCurrencyEdit) ---------------------------------------------------------------------- PascalDragon · 2022-09-13 11:47 Quote from: Kalevi on September 13, 2022, 01:43:41 pmI've made money Edit componetin, but there's a problem with it that you can write characters other than numbers on it. Here's a file Please either attach the code as a file or use [ code ] tags to avoid the forum software potentially misinterpreting it. ---------------------------------------------------------------------- KodeZwerg · 2022-09-13 13:40 Is now your question how to fix your code or would you use the TJLabeledCurrencyEdit for the request in your post #1? ---------------------------------------------------------------------- Bart · 2022-09-13 14:27 Maybe TCurrSpinEditEx? Bart ---------------------------------------------------------------------- Kalevi · 2022-09-13 17:53 That LazControls TFloatSpinEditE is good if you can remove its spin feature, although you can write more than 2 decimal places there. ---------------------------------------------------------------------- wp · 2022-09-13 18:08 Just noticed that the TCurrSpinEditEx does not allow typing the decimal separator. Updated the version in ccr-svn. If you use the OPM version modify the following method in unit ExEditCtrls: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomCurrSpinEditEx.EditKeyPress(var Key: char);begin  inherited EditKeyPress(Key);  if not (Key in (Digits + AllowedControlChars + ['-', FDecimalSeparator])) then Key := #0;   // <--- Add FDecimalSeparator here  if (Key = '-') and IsLimited and (MinValue >= 0) then Key := #0;end; Yes, you can type an arbitrary number of decimal places, but when editing ends the input string is rounded as specified by the Decimals property. The spinner can be hidden by switching the property UpDownVisible to false. Note that it is still operative when the up/down arrows are pressed. If you don't want this, set the Increment property to 0. ---------------------------------------------------------------------- Kalevi · 2022-09-14 12:10 Oh, great. It's working. Thank you. ---------------------------------------------------------------------- Ally · 2022-09-14 13:15 Have a look at this. https://forum.lazarus.freepascal.org/index.php/topic,53352.msg394615.h tml#msg394615 I think this component could solve your problems. ---------------------------------------------------------------------- Kalevi · 2022-09-19 07:37 This RhsPack component DecimalNumberEdit is almost complete if an empty component could still be filled in with 0.00. Thank you, Roland, for your excellent work. ---------------------------------------------------------------------- Ally · 2022-09-19 10:08 Hello Kalevi, It's quite simple like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DecimalNumberEdit1.Text := '0' + DefaultFormatSettings.DecimalSeparator + '00'; Greetings Roland ---------------------------------------------------------------------- Arioch · 2022-09-19 10:51 it is really not clear what exactly would you need standard TEdit has NumberOnly propery, AFAIR TMaskEdit, mentioned above, can provide you with formatting like 012345.00 there is also TCalcEdit in Lazarus standard pallete, MISC tab, probably derived from RxLib there is also another RxLib continuation, JediVCL, part of it was ported to Lazarus and is available in CCR, i has TJvCalcEdit and TJvValidateEdit svn://svn.code.sf.net/p/lazarus-ccr/svn https://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvValidateEdit https://wiki.delphi-jedi.org/wiki/JVCL_Help:TJvCalcEdit JvValidateEdit has properties CheckChars, DecimalPlaces, DisplayPrefix, DisplaySuffix and others JvCalcEdit has properties DecimalPlaces, DisplayFormat and others KControls library has TKNumberEdit - https://github.com/kryslt/KControls/ ---------------------------------------------------------------------- Kalevi · 2022-09-20 07:25 Thank you for the instructions, I noticed after I had already written it here. I am very grateful for these guidelines and, in particular, for this Roland DecimalNumberEdit1 component.