使用关闭时的参数数量错误

问题描述:

我在写一个小程序来保存文件中的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

随着一点点的谷歌搜索,我发现这个

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