2011-09-27 39 views

回答

2

是的。我不知道你对这个领域的意思和你使用的是什么版本的FastReport,但我会试着向你展示与报表对象交互的原理(这可以在预览中为任何报表对象完成窗口)。然而,TfrxReport.OnClickObject事件与FastReport版本不同,因此取决于您使用的版本,这可能会有所不同。

以下示例(使用版本4.12编写)与Memo1进行交互,在设计时将Text object (TfrxMemoView)放置在报告frxReport1上。您需要的其余部分是在主窗体中编写代码为OnClickObject事件处理程序。

procedure TForm1.frxReport1ClickObject(Sender: TfrxView; 
    Button: TMouseButton; Shift: TShiftState; var Modified: Boolean); 
begin 
    // comparing names is not so efficient, so for many controls I would use 
    // rather Sender.Tag and set the Tag property at report design time and 
    // use case Sender.Tag of construction 

    if Sender.Name = 'Memo1' then // is the Sender my Memo1 text object ? 
    begin 
    if fsBold in (Sender as TfrxMemoView).Font.Style then // is Memo1 font bold ? 
    begin 
     (Sender as TfrxMemoView).Font.Style := []; // then set it to default 
     ShowMessage('You just set memo text font to default'); // display message 
    end 
    else 
    begin 
     (Sender as TfrxMemoView).Font.Style := [fsBold]; // else set it to bold 
     ShowMessage('You just emphased your memo text font'); // display message 
    end; 

    Modified := True; // setting Modified to True causes the report to refresh 
    end; 
end; 
+0

哦,谢谢,我已经一个答案搜索。 – Nightw0rk

+0

@ Nightw0rk,很高兴为您效劳 – TLama

0

如果你需要把其他文本,尝试一个选项:

(Sender as TfrxMemoView).Text := 'Hi friend'; 

或:

TfrxMemoView(Sender).Text := 'Hi friend';