全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2743
推到 Plurk!
推到 Facebook!

symbol was eliminated by linker Delphi7编译器错误

答題得分者是:pcboy
waytounknow
一般會員


發表:4
回覆:7
積分:2
註冊:2007-08-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-11-22 23:58:24 IP:203.191.xxx.xxx 訂閱
各位大大,最近我通过delphi7定义了一个函数GetFilePath;目的是为了从INi配置文件中读取一个保存文件的路径。函数定义如下:
function GetFilePath(iniFileName,sSection,sIndent: string):string;
function TForm1.GetFilePath(iniFileName,sSection, sIndent: string): string;
var
IniFile : TInIFile;
begin
IniFile := TIniFile.Create(AppFilePath iniFileNames);
try
Result := IniFile.ReadString(sSection,sIndent,'');
finally
IniFile.Free;
end;
end;
然后我通过一个按钮时间调用这个函数
var
FilePath:string;
begin
FilePath := GetFilePath('hm2_report','report_path');
end;
在调试时,我发现函数GetFilePath中的第一个参数iniFileNames给出错误信息,Symbol was eblimimated by linker。IniFileName不是delphi的保留字啊,怎么会出现这样的错误?
烦请路过的高手帮俺看一下,谢了。
------
My way ....

way to unknow
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-11-23 10:03:13 IP:61.220.xxx.xxx 訂閱
我不是高手, 請問您有把Bug盡量除盡再貼出來嗎? 還是留一堆bug讓想幫您的人自己處理?
( 或者建議您將整個程式壓縮上傳還比較方便 debug )
問題1
function GetFilePath(iniFileName,sSection,sIndent: string):string;
function TForm1.GetFilePath(iniFileName,sSection, sIndent: string): string;  出現 [Error] Unit1.pas(28): Function needs result type
問題2
FilePath := GetFilePath('hm2_report','report_path'); 出現 [Error] Unit1.pas(48): Not enough actual parameters
只用兩個參數去呼叫需要三個參數的函數
問題3
function TForm1.GetFilePath(iniFileName,sSection, sIndent: string): string; 這裡是  iniFileName
IniFile := TIniFile.Create(AppFilePath iniFileNames);  這裡卻是 iniFileNames (多一個s)
 
問題4
> 然後我通過一個按鈕時間調用這個函數 
您到底用 Button 按鈕 ?
或使用 Timer 時間 ?
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
編輯記錄
pcboy 重新編輯於 2007-11-23 10:03:31, 註解 無‧
pcboy 重新編輯於 2007-11-23 10:06:30, 註解 無‧
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-11-23 10:04:57 IP:61.220.xxx.xxx 訂閱
供您參考
[code cpp]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IniFiles;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
function GetFilePath(iniFileName,sSection, sIndent: string): string;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetFilePath(iniFileName,sSection, sIndent: string): string;
var
IniFile : TInIFile;
AppFilePath : String;
begin
AppFilePath:= extractfilepath(application.exename);
IniFile := TIniFile.Create(AppFilePath iniFileName);
try
Result := IniFile.ReadString(sSection,sIndent,'');
finally
IniFile.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FilePath : String;
begin
FilePath := GetFilePath('report.ini', 'hm2_report','report_path');
Memo1.Clear;
Memo1.Lines.Add(FilePath);
end;

end.
[/code]
其中 report.ini 內容如下
[code cpp]
[hm2_report]
report_path=d:\report.txt
[/code]
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
sryang
尊榮會員


發表:39
回覆:762
積分:920
註冊:2002-06-27

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-11-24 00:11:37 IP:124.10.xxx.xxx 訂閱
Symbol was elimimated by linker 不是錯誤
當你設中斷點追蹤程式執行時,若這個變數被 linker 忽略掉,
也就是程式編譯過程中,經過最佳化之後,可以不需要這個變數了,linker 就會視同沒有這個變數
所以,你無法得知這個變數的內容

真要知道也行,把 Project Options 中 Compiler 頁籤上的 Optimization 不勾選,重新 build 一遍就是了
要 build 喔,光 compile 不行的
------
歡迎參訪 "腦殘賤貓的備忘錄" http://maolaoda.blogspot.com/
waytounknow
一般會員


發表:4
回覆:7
積分:2
註冊:2007-08-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-11-26 17:58:48 IP:203.191.xxx.xxx 訂閱
非常感谢两位大大的热心帮助。尤其是版主pcBoy的热心讲解。
我真是受益良多。
------
My way ....

way to unknow
系統時間:2024-04-29 14:37:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!