TLMDMaskEdit and negative currency

I have a TLMDMaskEdit set with a MaskType of meCurrency.  The CurrencySettings are set as default where the negativeFormatStr for negative values should show inside of parentheses.  However, when I use SetValue(-50), it shows as a positive value (no parens)... $50.00 instead of ($50.00)

I feel like I'm missing something.  Thoughts?

LMD Tools 2019.4
Delphi Rio 10.3.1

Comments

  • 11 Comments sorted by Votes Date Added
  • Status on this?  My currency setting is set correctly as far as I know, but still not showing parens around negative values.

    NegativeFormatStr is set as the default which is: (¤1,1)

    Using 2019.11
    Delphi Rio 10.3.3

  • You have to set CurrencySettings.SystemDefaults to cmUser before customizing currency masks. Otherwise custom masks are not used and even not saved to dfm.
  • I am not using a custom currency mask, that (¤1,1) setting for NegativeFormatStr is the default.  But even so, I tried setting SystemsDefaults to cmUser and it made no difference.  That format is not being used for negative values.  Please advise.

    Thanks,
    Eric

  • I played around with the cmUser setting, and it does not use it if if is just (¤1,1), however, if I set it to this: (¤-1,1) then it works, but I do not want ($-25.00), I want ($25.00) when negative.  So it is as if it sees (¤1,1) as the default and skips the formatting of a negative value.  It appears it wants something other than (¤1,1).  So -(¤1,1) works, so does (¤1,1)- and (¤-1,1), but not (¤1,1).

    Hope that helps.
  • I tested with (¤-1,1). I'l look more.
  • Fixed. If you can work with sources, as a quick fix you can change the source code:

    procedure TLMDCurrencySettings.UpdateNegFormatSignature;
    var
      i : integer;
      d: TLMDString;
    begin
      FNegFormatSignature := '';
      d := FSymbol + FFractionDelim + '1' + '¤';
      for i := 1 to length(FNegFormatStr) do
      begin
        if Pos(FNegFormatStr[i], d) = 0 then
          FNegFormatSignature := FNegFormatSignature + FNegFormatStr[i];
        if FNegFormatStr[i] = '¤' then
          FNegFormatSignature := FNegFormatSignature + FSymbol;
      end;
      if Pos('-', FNegFormatSignature) > 0 then // <<<<<<<<<<<<<<<<<<
        FNegFormatContainsMinus := true
      else
        FNegFormatContainsMinus := false;
    end;
  • Are you sure?  It does not appear to work for me when NegativeFormatStr is set to (¤1,1), either with cmUser or cmSystem.

    I debugged the IsNegative function which gets called when I set the value to -20, and the line where it compares s1 to FNegFormatSignature returns false.
    s1 = '($)'
    fNegFormatSignature = '($,)'
    Since they are not equal, it returns false.

    If I modify the fNegFormatSignature in debug at that compare line and set it to the same as s1 by removing the comma, i.e. ($), then it works.  So there is something in how it parses the signature.

    If I do not make that change you mentioned in your post, it never even calls IsNegative, so we made progress :)

    Of course, I'm using 2019.11 not the latest, so maybe something was already fixed in that regard.  I will try updating.



  • Updated to 2020.3 and same issue in TLMDCurrencySettings.IsNegative with s1 not matching FNegFormatSignature for negative numbers.


  • edited June 30 Posts: 0 Accepted Answer Vote Up0Vote Down
    I've made more modifications. Since they are spread, I've sent the file to you via e-mail.
  • Thanks, Eugene.  That seems to work!
Sign In or Register to comment.