2011-09-27 38 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';