2012-07-06 45 views
1

我在寫一個小程序來保存文件中的TEdit控件的內容。使用關閉時的參數數量錯誤

這個想法是,用戶在TEdit控件中寫入一些東西,然後按下按鈕在磁盤上寫入文件,但是當嘗試編譯時,我得到了「unit1.pas(37,15)錯誤:爲調用指定的參數數量錯誤到「關閉」「

我的表單只有TEdit控件和一個TButton。

var 
    Form1: TForm1; 
    f: text; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    writeln (f,Edit1.Text); 
    close (f); 
end; 

Begin 
    assign (f,'code.txt'); 
    rewrite (f); 
end. 

我到底在做什麼錯?

+2

必須用'CloseFile'代替 – RRUZ 2012-07-06 19:03:20

+0

@RRUZ:謝謝你,這很好地工作。 – Ashir 2012-07-06 23:46:35

回答

4

隨着一點點的谷歌搜索,我發現這個

Close exists in both System unit (implicitly used) and TCustomForm (TForm ancestor) class. Pascal identifier scoping rules makes unqualified Close takes the inner most scope. Therefore, if you call it in a TForm method, then it's TForm's Close that gets called. To avoid this, either use qualified call (System.Close to call the one from System unit or Self.Close to call the one belonging to current form) or CloseFile (which actually just calls System.Close) from ObjPas unit (automatically used in {$mode objfpc} or {$mode delphi}).

+0

謝謝。 'CloseFile'完美地工作。 – Ashir 2012-07-06 23:47:11