lastdelimiter

Hi,

I have a memo that can contain text that uses more than one line on the report. If the user do not put in a CR only the first line is shown on the report. To avoid this I want to put in a CR at the after a word at a given length using the function lastdelimiter looking for the last space in my substring. But as far as I can tell this function is not implemented in Fast Report.

1. Is there another way for me to do this without using this function?
2. Will lastdelimiter be implemented in a future release of Fast Report?

I am currently using Fast Report 4.9.32

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited March 2010
    Do you know exactly how to achieve that in Delphi code?
    If yes, all you need is to create a user function. For example, I have a function that removes the ending CrLf of the memo.text, called by me as 'DoTrim':
    In Delphi:
    frxReport1.OnUserFunction := CustomReportFunction;
         frxReport1.AddFunction('function DoTrim(const pValue: string; var pTxt: string):boolean;', 'My Internal');
    

    then you implement it (still in your .pas file):
      function TRptBuilder.DoTrim(const Value: string; var pTxt: string): boolean;
      // trims trailing CrLf and blank spaces
      var
        lL: Integer;
      begin
        result := false;
        pTxt := Value;
        lL := length(pTxt);
        try
          while (lL > 0) and ((pTxt[lL] = #13) or (pTxt[lL] = #10) or (pTxt[lL] = ' ')) do
          begin
            Delete(pTxt, lL, 1);
            lL := length(pTxt);
            result := true;
          end;
        except
        end;
      end;
    

    And add this too:
    function TRptBuilder.CustomReportFunction(const MethodName: string; var Params: Variant): Variant;
      var
        lStr1: string;
      begin
        result := MethodName;
       if MethodName = 'DOTRIM' then
        begin
          if ((TVarData(Params[0]).VType = varString) or (TVarData(Params[0]).VType = varOleStr)) and
            ((TVarData(Params[1]).VType = varString) or (TVarData(Params[1]).VType = varOleStr)) then
          begin
            lStr1 := Params[0];
            result := DoTrim(lStr1, lStr1);
            Params[1] := lStr1;
          end
          else
            Showmessage('Invalid Parameters for DoTrim()');
        end
        else if MethodName = 'RESETCHAPTERCOUNTERS' then
          ResetChapterCounters
        else
          Showmessage('Not found: ' + MethodName);
      end;
    end;
    


    Then you can use it in the script, for your memo:
    procedure m1OnAfterData(Sender: TfrxComponent);
    var
     lTxt : string;
    begin
      lTxt := VarToStr(Value);     
      if DoTrim(lTxt, lTxt) then                 
        TfrxMemoView(sender).text := lTxt;
    end;
    

    All you need to do is follow those steps to create a function that does exactly what you neeed (not what I showed here).

    Search for 'OnUserFunction' in the pdf help files and you will find more about it.
  • edited 9:15PM
    Hi Anu and thanks for your quick reply [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />! I still have some problems, though. I tried to do as you shown in your reply, but I got an error message saying that "Script error at <line no in code part in report> Undeclared identifier: '<name of my function>'. I have tried several things without any luck. I even copied your excact code into my pas-file to see if that would produce another result. It did not. Do you know what I am doing wrong?[/img]
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 9:15PM
    It looks like you are not doing it in good time, try calling
    frxReport1.OnUserFunction := CustomReportFunction;
    frxReport1.AddFunction(...);
    as the last thing just before you call the show/preview methods.
    Otherwise, the only thing I can suggest is to read the manual, I learned from there.
  • edited 9:15PM
    Yes, that was all that needed to be done >! I did what you said and finally it works. Sorry for wasting your time on such an amateurish error...

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.