How can I replace the lines in a note (FastReport)?

I have a memo object in my report and you need to replace the lines "% ...%". For example, in a Rave report:

MemoBuf.ReplaceAll('%my_str%',  "new string", false);

But, there is no method (or property) for replacing text in FastReport. How can i do this?

I use Fast Report 4.9.72and Delphi 2010.

Thank!

+5
source share
3 answers

Since there is no FastReport StringReplace, I would do it from Delphi code. You can somehow import the functions, but it seems to me better organized. Note that in this first example, I assume that exists Memo1(you would get an access violation otherwise).

procedure TForm1.Button1Click(Sender: TObject);
var
  Memo: TfrxMemoView;
begin
  Memo := frxReport1.FindObject('Memo1') as TfrxMemoView;
  Memo.Text := StringReplace(Memo.Text, '%my_str%', 'new string', [rfReplaceAll]);
  frxReport1.ShowReport;
end;

, - :

procedure TForm1.Button2Click(Sender: TObject);
var
  Memo: TfrxMemoView;
  Component: TfrxComponent;
begin
  Component := frxReport1.FindObject('Memo1');
  if Component is TfrxMemoView then
  begin
    Memo := Component as TfrxMemoView;
    Memo.Text := StringReplace(Memo.Text, '%my_str%', 'new string', [rfReplaceAll]);
    frxReport1.ShowReport;
  end;
end;
+6

, Rave Reports, , FastReport:

  • Memo. "my_str", . : [my_str]. , . pascal, , , . Delphi, FastReport [..], . .
  • FastReport Delphi, , .
  • script ( , Delphi), , .
0

:

function StringReplace(const S, OldPattern, NewPattern: string;
  iReplaceAll: boolean=true; iIgnoreCase :boolean=true): string;
var
  SearchStr, Patt, NewStr: string;
  Offset: Integer;
begin
  if iIgnoreCase then begin
    SearchStr := UpperCase(S);
    Patt := UpperCase(OldPattern);
  end else begin
    SearchStr := S;
    Patt := OldPattern;
  end;
  NewStr := S;
  Result := '';
  while SearchStr <> '' do begin
    Offset := Pos(Patt, SearchStr);
    if Offset = 0 then begin
      Result := Result + NewStr;
      Break;
    end;
    Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
    NewStr := Copy(NewStr, Offset + Length(OldPattern), MaxInt);
    if not iReplaceAll then begin
      Result := Result + NewStr;
      Break;
    end;
    SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt);
  end;
end;
0

All Articles