小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

『Delphi園地』-FastReport問(wèn)題集

 chenge 2006-03-15

---------------- 使用自定義函數(shù) ----------------------------------------

Q: 我怎樣添加我的自定義函數(shù)?
A: 使用 TfrReport.OnUserFunction 事件. 這里有一個(gè)簡(jiǎn)單的例子:

procedure TForm1.frReport1UserFunction(const Name: String;
p1, p2, p3: Variant; var val: Variant);
begin
if AnsiCompareText(‘SUMTOSTR‘, Name) = 0 then
val := My_Convertion_Routine(frParser.Calc(p1));
end;

然后,你就可以在報(bào)表(任何表達(dá)式或腳本)的任何地方使用 SumToStr 函數(shù)了。


Q: 但是它僅僅能工作在一個(gè)TfrReport組件中??晌蚁朐谌魏蔚胤剑ㄔ谒械腡frReport組件中)使用的我的自定義函數(shù)?
A: 使 OnUserFunction event 句柄作為所有組件的公用句柄。如果你不能做到這一點(diǎn),你需要?jiǎng)?chuàng)建函數(shù)庫(kù):

type
TMyFunctionLibrary = class(TfrFunctionLibrary)
public
constructor Create; override;
procedure DoFunction(Fno: Integer; p1, p2, p3: Variant;
var val: Variant); override;
end;

constructor TMyFunctionLibrary.Create;
begin
inherited Create;
with List do
begin
Add(‘DATETOSTR‘);
Add(‘SUMTOSTR‘);
end;
end;

procedure TMyFunctionLibrary.DoFunction(Fno: Integer; p1, p2, p3: Variant;
var val: Variant);
begin
val := 0;
case Fno of
0: val := My_DateConvertion_Routine(frParser.Calc(p1));
1: val := My_SumConvertion_Routine(frParser.Calc(p1));
end;
end;

要注冊(cè)函數(shù)庫(kù),調(diào)用
frRegisterFunctionLibrary(TMyFunctionLibrary);
要卸載函數(shù)庫(kù),調(diào)用
frUnRegisterFunctionLibrary(TMyFunctionLibrary);


Q: 我怎樣將我的函數(shù)添加到函數(shù)列表中 (用表達(dá)式生成器)?
A: 使用 frAddFunctionDesc 過(guò)程 (在FR_Class 單元中):

frAddFunctionDesc(FuncLib, ‘SUMTOSTR‘, ‘My functions‘,
‘SUMTOSTR(<Number>)/Converts number to its verbal presentation.‘);

注意: "/" 符號(hào)是必須的! 它從它的描述中分隔函數(shù)語(yǔ)法。
FuncLib 被聲明為你自己的函數(shù)庫(kù) (如果你不使用函數(shù)庫(kù)可以將其設(shè)置為nil). 當(dāng)函數(shù)庫(kù)未注冊(cè)時(shí),所有它的函數(shù)將自動(dòng)從函數(shù)列表中刪除。


---------------- 使用變量 -------------------------------------

Q: 我怎樣編程實(shí)現(xiàn)填充變量列表(在數(shù)據(jù)詞典中)?

A: 數(shù)據(jù)詞典中的所有變量及分類(lèi)都被存儲(chǔ)在 TfrReport.Dictionary.Variables 中.

with frReport1.Dictionary do
begin
// 創(chuàng)建分類(lèi)(名稱(chēng)用空白)
Variables[‘ New category‘] := ‘‘;
// 創(chuàng)建變量
Variables[‘New Variable‘] := ‘CustomerData.Customers."CustNo"‘;
Variables[‘Another Variable‘] := ‘Page#‘;
end;

Q: 我定義了字符串變量:

with frReport1.Dictionary do
Variables[‘Month‘] := ‘March‘;

但是當(dāng)我運(yùn)行報(bào)表是,出現(xiàn)了錯(cuò)誤,為什么?

A: 因?yàn)?FastReport 假定數(shù)據(jù)詞典中的字符串變量值是一個(gè)表達(dá)式,它需要分析、計(jì)算它。
可以使用其它的方法:

with frReport1.Dictionary do
Variables[‘Month‘] := ‘‘‘‘ + ‘March‘ + ‘‘‘‘;

或者, 使用 frVariables 來(lái)傳輸固定數(shù)據(jù)到報(bào)表。


Q: 我不想在數(shù)據(jù)詞典中顯示某些數(shù)據(jù)集?

A: 使用 TfrReport.Dictionary.DisabledDatasets:

with frReport1.Dictionary do
begin
// 關(guān)閉該數(shù)據(jù)集
DisabledDatasets.Add(‘CustomerData.Bio‘);
// 或者, 關(guān)閉整個(gè)數(shù)據(jù)模塊/窗體
DisabledDatasets.Add(‘CustomerData*‘);
end;


Q: 我怎樣將數(shù)據(jù)傳送到報(bào)表?

A: 有幾個(gè)方法可以實(shí)現(xiàn)它. 第一是使用全局對(duì)象 frVariables (在 FR_Class 單元中被定義):

frVariables[‘My variable‘] := 10;

這段代碼創(chuàng)建了一個(gè)名稱(chēng)為“My variable”,值為 10 的變量。這是最好的傳輸固定數(shù)據(jù)的報(bào)表的方法。

第二種方法是使用 TfrReport.OnGetValue 事件. 這可以使用這個(gè)方法來(lái)傳送動(dòng)態(tài)數(shù)據(jù)、記錄等。

procedure TForm1.frReport1GetValue(ParName: String; var ParValue: Variant);
begin
if ParName = ‘MyField‘ then
ParValue := Table1MyField.Value;
end;

最后, 第三種方法是通過(guò)編程在數(shù)據(jù)詞典中定義變量(可以參考以前的問(wèn)題):

with frReport1.Dictionary do
begin
Variables[‘MyVariable‘] := ‘CustomerData.Customers."CustNo"‘;
Variables[‘Another Variable‘] := ‘10‘;
end;


Q: 我能在報(bào)表和程序間傳送數(shù)據(jù)嗎?
A: 使用 frVariables 對(duì)象. 如果你在報(bào)表的任何對(duì)象的腳本中寫(xiě)入以下代碼:

MyVariable := 10

那么,在你的程序中,你可以使用以下代碼來(lái)獲取 MyVariable 的值:
v := frVariables[‘MyVariable‘];


---------------- 腳本 (FastReport Pascal) ---------------------------------

Q: Band 中是否可以使用腳本?

A: 當(dāng)然. 選擇 band ,然后按 Ctrl+Enter 或在對(duì)象瀏覽器中選擇 "OnBeforePrint" 屬性。

Q: 報(bào)表頁(yè)中是否可以使用腳本?

A: 當(dāng)然. 選擇頁(yè) (在空白處單擊) ,然后在對(duì)象瀏覽器中選擇 "OnBeforePrint" 屬性。如果該頁(yè)是一個(gè)對(duì)話框窗體,那么這個(gè)屬性就是 "OnActivate".


Q: 我有兩個(gè)對(duì)象: Memo1 和 Memo2. 我能否在 Memo1 的腳本中調(diào)用 Memo2 的屬性和方法?

A: 當(dāng)然, 例如,你可以這樣做: 對(duì)象名.屬性名.


Q: 在腳本中,我可以使用對(duì)象的哪些屬性?

A: 幾乎所有你能在對(duì)象瀏覽器中看到的屬性。例如,可以使用 Font.Name, Font.Size等來(lái)存取字體屬性。


---------------- 其它問(wèn)題 --------------------------------------------

Q: 怎樣改變多頁(yè)報(bào)表中某一頁(yè)的順序?

A: 拖動(dòng)頁(yè)標(biāo)簽到目的位置。


Q: 我想查看所有的字段及變量,我想在報(bào)表中使用列表來(lái)實(shí)現(xiàn)它?

A: 設(shè)置 TfrReport.MixVariablesAndDBFields := True.現(xiàn)在,所有的數(shù)據(jù)字段及變量可在“插入數(shù)據(jù)字段”對(duì)話框中可存取了。


Q: 我不想顯示導(dǎo)入選項(xiàng)對(duì)話框?

A: 在導(dǎo)入組件(比如,TfrTextExport)中設(shè)置所有必需的選項(xiàng),然后通過(guò)設(shè)置ShowDialog屬性為False來(lái)關(guān)閉此對(duì)話框。


Q: 為什么 TotalPages 變量不起作用? 它總是返回 0.

A: 在你的報(bào)表中設(shè)置 Two-pass 選項(xiàng). 要設(shè)置它,你需要在報(bào)表設(shè)計(jì)器的“文件”菜單中,打開(kāi)“報(bào)表選項(xiàng)”對(duì)話框。


Q: 我用BLOB字段來(lái)存儲(chǔ)我的報(bào)表。當(dāng)我運(yùn)行報(bào)表設(shè)計(jì)器時(shí),它顯示我的報(bào)表未命名?

A: 在運(yùn)行報(bào)表設(shè)計(jì)器前,這樣做:

frReport1.FileName := ‘Name of my report‘;


Q: 我想在重新定義報(bào)表設(shè)計(jì)器中的“打開(kāi)”及“保存”按鈕的功能?


A: 查看 TfrDesigner 組件. 它有幾個(gè)必需的事件: OnLoadReport 和
OnSaveReport. 這里有一小段代碼例子:

procedure TForm1.frDesigner1LoadReport(Report: TfrReport;
var ReportName: String; var Opened: Boolean);
begin
with MyOpenDialog do
begin
Opened := ShowModal = mrOk;
if Opened then
begin
Report.LoadFromBlobField(…);
ReportName := …;
end;
end;
end;

procedure TForm1.frDesigner1SaveReport(Report: TfrReport;
var ReportName: String; SaveAs: Boolean; var Saved: Boolean);
begin
if SaveAs then
with MySaveDialog do
begin
Saved := ShowModal = mrOk;
if Saved then
begin
Report.SaveToBlobField(…);
ReportName := …;
end;
end
else
Report.SaveToBlobField(…);
end;


Q: 在 QR 中, 我可以寫(xiě)這樣的代碼: QRLabel1.Caption := ‘Some text‘. 我可以用FR這樣做嗎?

A: FR 對(duì)象并不是一個(gè)組件 (這并不像 QR, RB). 但使用 TfrReport.FindObject 方法可以通過(guò)對(duì)象名稱(chēng)找到該對(duì)象。

var
t: TfrMemoView;
begin
t := TfrMemoView(frReport1.FindObject(‘Memo1‘));
if t <> nil then
t.Memo.Text := ‘FastReport‘;
end;


Q: 我想在用戶預(yù)覽(TfrPreview組件)中自定義熱鍵?

A: 這個(gè)組件有個(gè)窗口: Tform 屬性. 將自定義句柄指定到 Window.OnKeyDown 屬性.


Q: Fast Report 2.4 不能裝載 FreeReport 2.21 文件?

A: 這僅需要使用16進(jìn)制數(shù)改變報(bào)表文件的第一字節(jié),然后在源代碼中修改下面的部分。在這些修改之后, 裝載報(bào)表并保存它. 最后,返回到源代碼處.

FR_Class:

function ReadString(Stream: Tstream): String;
begin
{ if frVersion >= 23 then}
Result := frReadString(Stream) {else
Result := frReadString22(Stream);}
end;

procedure ReadMemo(Stream: Tstream; Memo: Tstrings);
begin
{ if frVersion >= 23 then}
frReadMemo(Stream, Memo){ else
frReadMemo22(Stream, Memo);}
end;


FR_Utils:

procedure frReadMemo(Stream: Tstream; l: Tstrings);
var
s: String;
b: Byte;
n: Word;
begin
l.Clear;
l.Text := frReadString(Stream); exit;
Stream.Read(n, 2);
if n > 0 then
repeat
Stream.Read(n, 2);
SetLength(s, n);
Stream.Read(s[1], n);
l.Add(s);
Stream.Read(b, 1);
until b = 0
else
Stream.Read(b, 1);
end;

function frReadString(Stream: Tstream): String;
var
s: String;
n: Integer;
b: Byte;
begin
Stream.Read(n, 4);
SetLength(s, n);
Stream.Read(s[1], n);
if (n > 0) and (s[n] = #$0A) then
SetLength(s, n - 2);
// Stream.Read(b, 1);
Result := s;
end;


Q: 怎樣不在打印預(yù)覽中打印報(bào)表?
A: 這里有一段代碼:

frReport1.PrepareReport;
frReport1.PrintPreparedReport(‘‘, 1, True, frAll);

frReport1.PrintPreparedReportDlg;


Q: 我想在報(bào)表中旋轉(zhuǎn)圖片。問(wèn)題是這張圖片是由我的應(yīng)用程序生成的。是否有方法可以在打印前將這幅圖片裝載到報(bào)表中?

A: 使用 TfrReport.OnBeforePrint 事件:

if View.Name = ‘Picture1‘ then
TfrPictureView(View).Picture.LoadFromFile(…) 或
.Assign 或
.你所想要做的任何事情

(出處:www.delphibbs.com)

鄭重聲明:此文章由網(wǎng)友發(fā)布,僅供學(xué)習(xí)參考!如有侵權(quán),請(qǐng)及時(shí)告知我們將之移除!


    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多