FastReport 3 的變數傳遞 |
答題得分者是:chinyu
|
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
請問各位:
我最近使用 FastReport 3.20 版本 Delphi5 在FR的Variable Dictionary 中 設定了一個 hCompany 的變數 而在 Band中把這組變數以一個 Text Memo 放進來成為 [hCompany] 然後由我的Delphi 傳值給這個變數 frxReport1.Variables['hCompany']:= '我的公司名稱' 這一切在設定上看來都沒有問題, 但在run 的時候, 卻出現 Memo1: Error in Expression '我的公司名稱': Undelcared Identiifer: '我的公司名稱' 似乎 FR 把我傳入的值當成是 Memo1的變數名稱來用, 不知各位有沒有遇到這樣的問題, 如何解決? |
Victor4022
中階會員 發表:0 回覆:76 積分:90 註冊:2011-02-20 發送簡訊給我 |
您可以試試看: Delphi -> frxReport1.Script.AddVariable('MyVar1', 'String', '我的公司名稱'); FR3 -> Memo.Text := [MyVar1]
編輯記錄
Victor4022 重新編輯於 2011-11-03 19:37:51, 註解 無‧
|
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
因為我之前不記得使用那版的FR3沒有這個問題, 最近裝了3.20後才發現(也試過 3.17, 3,14都一樣),
然後我試了很多方法, 包含所提到的方式, 都會引發本帖所提的錯誤, 還有使用這樣的方式 TfrxMemoView(frxReport1.FindObject('hCompany')).Memo.Text:= '我的公司名稱' 是引發 Access Error 的問題 不知道還有那種可能性 ps: 如果我把 [hCompany] 屬性 Allow Expressions 取消是可以過, 但卻是直接印出 hCompany 的字串, 而不是我想要的公司名稱 我在懷疑是不是FR3的 BUG, 但手上也沒有其他的 FR3 版本可測 ===================引 用 Victor4022 文 章=================== 您可以試試看: Delphi -> frxReport1.Script.AddVariable('MyVar1', 'String', '我的公司名稱'); FR3 -> Memo.Text := [MyVar1] |
Victor4022
中階會員 發表:0 回覆:76 積分:90 註冊:2011-02-20 發送簡訊給我 |
抱歉未附上我的測試版號,而且忘記加入 Delphi 程式碼區段,導致早上回覆的內容有些 code 不正確。
以下是我測試 4.9x 和 3.2x 的結果,應該是可行的: Delphi 程式碼如下: [code delphi] frxReport1.Script.AddVariable('MyVar', 'String', 'daskdjaskjdas'); frxReport1.ShowReport(); [/code] FR3 的 Memo 字串如下: [code delphi] [MyVar] [/code] Memo 屬性有開啟 AllowExpressions 透過 Delphi 程式在 frxReport1加入 variable (是 TfrxReport.Script 而不是 TFrxReport) ---- 剛剛測試了 3.12 Enterprise 版,也是正常的。
編輯記錄
Victor4022 重新編輯於 2011-11-04 06:24:54, 註解 無‧
|
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
感謝Victor4022的協助
之前在使用xp環境的 Delphi5 時也是沒有問題, 而是這陣子轉上Win7 跑 Delhpi5 後才發現有問題, 所有的設定都是沿用之的報表, 設定也應該沒有問題, 但就是不知道問題出在那裡? 因為除了這個問題外, 另外如果我傳了一個字串, 內容是日期字串如 20110101 是沒有問題, 但如果傳入 2011/01/01 也一樣發生這個問題 如果傳入 12:34:24 也是相同錯誤( 時間是一個字串傳入, 而不是直接以 TDateTime格式) 我還在持續找問題點, 不過為了趕件 只好把FR3的 Varaibles 的設定改成以 資料庫帶入DataSet 方式導入參數, 情況是可以正常列印. 真是見鬼了, 自從使用 Win7 x64版本後, 發現搭配以前的 Delphi 問題多多! ===================引 用 Victor4022 文 章=================== 抱歉未附上我的測試版號,而且忘記加入 Delphi 程式碼區段,導致早上回覆的內容有些 code 不正確。 以下是我測試 4.9x 和 3.2x 的結果,應該是可行的: Delphi 程式碼如下: [code delphi] frxReport1.Script.AddVariable('MyVar', 'String', 'daskdjaskjdas'); frxReport1.ShowReport(); [/code] FR3 的 Memo 字串如下: [code delphi] [MyVar] [/code] Memo 屬性有開啟 AllowExpressions 透過 Delphi 程式在 frxReport1加入 variable (是 TfrxReport.Script 而不是 TFrxReport) ---- 剛剛測試了 3.12 Enterprise 版,也是正常的。 |
chinyu
高階會員 發表:12 回覆:157 積分:153 註冊:2002-06-14 發送簡訊給我 |
這樣修改變數方式是要加單引號的:
FR 2.X -> faq.txt 1.12. Error when assigning a string value to the FR variable. (code like frReport1.Dictionary.Variables['Range'] := '10..50') FR trying to calc such string values. Add quotes: frReport1.Dictionary.Variables['Range'] := '''' '10..50' ''''; or use frVariables for static data. -------------------------------------------------------------------------------------------- FR 4.X -> FR4.6.ProgrammerManual-en.pdf 35頁 It should be noted, that when accessing a report variable its value is calculated if it is of string type. That means the variable which value is 'Table1."Field1"' will return a value of a DB field, but not the 'Table1."Field1"' string. You should be careful when assigning a string-type values to report variables. For example, the next code will raise exception "unknown variable 'test'" when running a report: frxReport1.Variables['My Variable'] := 'test'; because FastReport trying to calculate a value of such variable. The right way to pass a string values is: frxReport1.Variables['My Variable'] := '''' 'test' ''''; 我記得 FR 3.x 應該也是。 ===================引 用 P.D. 文 章=================== 請問各位: 我最近使用 FastReport 3.20 版本 Delphi5 在FR的Variable Dictionary 中 設定了一個 hCompany 的變數 而在 Band中把這組變數以一個 Text Memo 放進來成為 [hCompany] 然後由我的Delphi 傳值給這個變數 frxReport1.Variables['hCompany']:= '我的公司名稱' 這一切在設定上看來都沒有問題, 但在run 的時候, 卻出現 Memo1: Error in Expression '我的公司名稱': Undelcared Identiifer: '我的公司名稱' 似乎 FR 把我傳入的值當成是 Memo1的變數名稱來用, 不知各位有沒有遇到這樣的問題, 如何解決? |
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
感謝 chinyu 提供的資訊
終於我知道問題在那裡了 因為 chinyu 所提到的做法, 之前我也試過, 但是一樣的問題, 但我發現, 我試的動作有一個地方不同, 就是 frxReport1.Variables['hCompany']:= myCompanyVar; 當然以上的做法是一樣不行, 所以我參考說明, 我怕大家看不清楚, 所以紅字部份放大然後空格(實際是沒有空格的 frxReport1.Variables['hCompany']:= ' ' ' '; 通過了! YA~~~ 原來它和Delphi BDE 設定一樣, 是必須使用 單引號, 而不能使用雙引號 也感謝所有提供協助的朋友 ===================引 用 chinyu 文 章=================== 這樣修改變數方式是要加單引號的: FR 2.X -> faq.txt 1.12. Error when assigning a string value to the FR variable. (code like frReport1.Dictionary.Variables['Range'] := '10..50') FR trying to calc such string values. Add quotes: frReport1.Dictionary.Variables['Range'] := '''' '10..50' ''''; or use frVariables for static data. -------------------------------------------------------------------------------------------- FR 4.X ->FR4.6.ProgrammerManual-en.pdf 35頁 It should be noted, that when accessing a report variable its value is calculated if it is of string type. That means the variable which value is 'Table1."Field1"' will return a value of a DB field, but not the 'Table1."Field1"' string. You should be careful when assigning a string-type values to report variables. For example, the next code will raise exception "unknown variable 'test'" when running a report: frxReport1.Variables['My Variable'] := 'test'; because FastReport trying to calculate a value of such variable. The right way to pass a string values is: frxReport1.Variables['My Variable'] := '''' 'test' ''''; 我記得 FR 3.x 應該也是。
編輯記錄
P.D. 重新編輯於 2011-11-09 09:27:22, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |