gpt4 book ai didi

delphi - 如何替换备忘录 (FastReport) 中的字符串?

转载 作者:行者123 更新时间:2023-12-03 15:09:31 24 4
gpt4 key购买 nike

我的报告中有一个备忘录对象,需要替换“%...%”字符串。例如,在 Rave 报告中:

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

但是,FastReport 中不存在替换文本的方法(或属性)。我怎样才能做到这一点?

我正在使用 Fast Report 4.9.72Delphi 2010

谢谢!

最佳答案

因为没有StringReplace在可用的 FastReport 中,我会通过 Delphi 代码来完成此操作。可以以某种方式导入函数,但在我看来,这似乎安排得更好。请注意,在第一个示例中,我假设 Memo1 存在(否则您会遇到访问冲突)。

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;

关于delphi - 如何替换备忘录 (FastReport) 中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com