Problem with Format function

KelloucheKellouche Algeria
edited 6:15PM in FastReport 3.0
Hi !

please any one for help me.
why does this code not work
procedure SysMemo27OnAfterData(Sender: TfrxComponent);
var
   res : string;
begin
  SysMemo27.Text :=    SysMemo14.Value + SysMemo15.Value + SysMemo16.Value +
                       SysMemo18.Value + SysMemo19.Value + SysMemo20.Value +
                       SysMemo21.Value + SysMemo22.Value + SysMemo23.Value +
                       SysMemo24.Value + SysMemo25.Value + SysMemo26.Value;
  try
    res := Format('%2.0n', [SysMemo27.Text]); // this does not work
    SysMemo27.Text := res;
  except
    ShowMessage('Erreur de formatage');
  end
end;

Comments

  • edited 6:15PM
    wrote:
    try
    res := Format('%2.0n', [SysMemo27.Text]); // this does not work
    What error messase do you get?

    Try to test your variable before you make formating.
    try
       ShowMessage( SysMemo27.Text);         
       res := Format('%2.0n', SysMemo27.Text); 
    ...
    
    And yet - I'm not sure one should use square brackets for declared variable in FR3 (I use FR4)

    Mick
  • KelloucheKellouche Algeria
    edited 6:15PM
    Mick.pl wrote: »
    Mick.pl wrote: »
    try
    res := Format('%2.0n', [SysMemo27.Text]); // this does not work
    What error messase do you get?

    Try to test your variable before you make formating.
    try
       ShowMessage( SysMemo27.Text);         
       res := Format('%2.0n', SysMemo27.Text); 
    ...
    
    And yet - I'm not sure one should use square brackets for declared variable in FR3 (I use FR4)

    Mick

    I have no error message !
    the text is not formated, f.e if the value is "3841" the result after application of format function is "3841" so i think format function does not support text property (SysMemoxx.Tex)
    is there other way to do this ?!
  • edited 6:15PM
    Can you attach FR3 compiled demo (zip, exe) here?
    I use FR4 and can't test your issue in the environment you have [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> Mick[/img]
  • KelloucheKellouche Algeria
    edited 6:15PM
    Mick.pl wrote: »
    Can you attach FR3 compiled demo (zip, exe) here?
    I use FR4 and can't test your issue in the environment you have [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> Mick[/img]
    yes with pleasure
  • edited 6:15PM
    I needed FRDemo.exe to test formating as I didn't have any FR3 Designer [img]style_emoticons/<#EMO_DIR#>/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> But somehow I got it - FastReport C/S Demo 3.15a (2005) - and now I have it[/img][img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I could not find solution to force[/img]Format() as you wished, so I searched for alternative. Have a look below, maybe you'll find it helpfull.
    procedure SysMemo27OnAfterData(Sender: TfrxComponent);
    var
       res : string;
       sum : real;
    begin
      Sum := SysMemo14.Value + SysMemo15.Value + SysMemo16.Value +
             SysMemo18.Value + SysMemo19.Value + SysMemo20.Value +
             SysMemo21.Value + SysMemo22.Value + SysMemo23.Value +
             SysMemo24.Value + SysMemo25.Value + SysMemo26.Value;
      if (Engine.FinalPass) then
      try
        res := FormatFloat( '### ### ### ##0.', Sum);      
        SysMemo27.Text := res;
      except
        ShowMessage('Erreur de formatage');
      end
    end;
    

    And bonus for you to let you make your code more simple:
    function MySuperDate(  TD :TDateTime): string;                                                
    var
       ch : string;
       j, m, a : word; // pour stocker la date aprčs l'avoir d?©coder
    begin
      ch := ' Mois : ';
      // extraire le mois et le convertir en entier
      decodedate( TD, a, m, j);
      // tester sur le mois, en d?©duire le mois en lettre et lui ajouter l'ann?©e
      case m of
        1 : ch := ch + 'Janvier ' + IntToStr(a);
        2 : ch := ch + 'F?©vrier ' + IntToStr(a);
        3 : ch := ch + 'Mars ' + IntToStr(a);
        4 : ch := ch + 'Avril ' + IntToStr(a);
        5 : ch := ch + 'Mai ' + IntToStr(a);
        6 : ch := ch + 'Juin ' + IntToStr(a);
        7 : ch := ch + 'Juillet ' + IntToStr(a);
        8 : ch := ch + 'Aoűt ' + IntToStr(a);
        9 : ch := ch + 'Septembre ' + IntToStr(a);
        10 : ch := ch + 'Octobre ' + IntToStr(a);
        11 : ch := ch + 'Novembre ' + IntToStr(a);
        12 : ch := ch + 'D?©cembre ' + IntToStr(a);
      else
        ch := 'Erreur !';
      end;
      Result := ch;
    end;
    
    procedure Memo79OnAfterData(Sender: TfrxComponent);
    begin
      Memo79.Text := MySuperDate( Memo128.Value);
    end
          
    procedure Memo128OnAfterData(Sender: TfrxComponent);
    begin
      Memo128.Text := MySuperDate( Memo128.Value);
    end
    
    Mick
  • KelloucheKellouche Algeria
    edited May 2011
    thank you very much Mick.
  • edited 6:15PM
    I think there something error in your code.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.