Recent

Author Topic: T-edit component for money  (Read 4258 times)

Kalevi

  • New Member
  • *
  • Posts: 29
T-edit component for money
« on: September 13, 2022, 01:12:05 pm »
Has someone made a T-Edit component that can only be written in monetary value?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2065
  • Fifty shades of code.
    • Delphi & FreePascal
Re: T-edit component for money
« Reply #1 on: September 13, 2022, 01:18:48 pm »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Kalevi

  • New Member
  • *
  • Posts: 29
Re: T-edit component for money
« Reply #2 on: September 13, 2022, 01:30:20 pm »
I haven't been able to make a mask that would work. In addition, an empty field should have, for example, 0:00.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2065
  • Fifty shades of code.
    • Delphi & FreePascal
Re: T-edit component for money
« Reply #3 on: September 13, 2022, 01:40:16 pm »
for example, 0:00
I do not clear understand, 0:00 would be a time value not a monetary, or? I might miss something.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Kalevi

  • New Member
  • *
  • Posts: 29
Re: T-edit component for money
« Reply #4 on: September 13, 2022, 01:43:41 pm »
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

  • Hero Member
  • *****
  • Posts: 2065
  • Fifty shades of code.
    • Delphi & FreePascal
Re: T-edit component for money
« Reply #5 on: September 13, 2022, 01:46:04 pm »
https://wiki.lazarus.freepascal.org/jujiboutils I hope that this will make you happy and solve your problem with currencies. (TJLabeledCurrencyEdit)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: T-edit component for money
« Reply #6 on: September 13, 2022, 01:47:30 pm »
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

Please either attach the code as a file or use [ code ] tags to avoid the forum software potentially misinterpreting it.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2065
  • Fifty shades of code.
    • Delphi & FreePascal
Re: T-edit component for money
« Reply #7 on: September 13, 2022, 03:40:05 pm »
Is now your question how to fix your code or would you use the TJLabeledCurrencyEdit for the request in your post #1?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: T-edit component for money
« Reply #8 on: September 13, 2022, 04:27:44 pm »
Maybe TCurrSpinEditEx?

Bart

Kalevi

  • New Member
  • *
  • Posts: 29
Re: T-edit component for money
« Reply #9 on: September 13, 2022, 07:53:43 pm »
That LazControls TFloatSpinEditE is good if you can remove its spin feature, although you can write more than 2 decimal places there.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: T-edit component for money
« Reply #10 on: September 13, 2022, 08:08:41 pm »
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][+][-]
  1. procedure TCustomCurrSpinEditEx.EditKeyPress(var Key: char);
  2. begin
  3.   inherited EditKeyPress(Key);
  4.   if not (Key in (Digits + AllowedControlChars + ['-', FDecimalSeparator])) then Key := #0;   // <--- Add FDecimalSeparator here
  5.   if (Key = '-') and IsLimited and (MinValue >= 0) then Key := #0;
  6. 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

  • New Member
  • *
  • Posts: 29
Re: T-edit component for money
« Reply #11 on: September 14, 2022, 02:10:56 pm »
Oh, great. It's working. Thank you.

Ally

  • Jr. Member
  • **
  • Posts: 53
Re: T-edit component for money
« Reply #12 on: September 14, 2022, 03:15:50 pm »
Have a look at this.

https://forum.lazarus.freepascal.org/index.php/topic,53352.msg394615.html#msg394615

I think this component could solve your problems.

Kalevi

  • New Member
  • *
  • Posts: 29
Re: T-edit component for money
« Reply #13 on: September 19, 2022, 09:37:22 am »
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

  • Jr. Member
  • **
  • Posts: 53
Re: T-edit component for money
« Reply #14 on: September 19, 2022, 12:08:00 pm »
Hello Kalevi,

It's quite simple like this:

Code: Pascal  [Select][+][-]
  1. DecimalNumberEdit1.Text := '0' + DefaultFormatSettings.DecimalSeparator + '00';

Greetings Roland

 

TinyPortal © 2005-2018