如題!

解决方案 »

  1.   

    链接一个文件,看帮助,写的那么清楚你不看var   F: TextFile;
      S: string;
    begin
      if OpenDialog1.Execute then            { Display Open dialog box }
      begin
        AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
        Reset(F);
        Readln(F, S);                        { Read first line of file }
        Edit1.Text := S;                     { Put string in a TEdit control }
        CloseFile(F);
      end;
    end;
      

  2.   

    AssignFile procedureAssociates the name of an external file with a file variable.Delphi syntax:procedure AssignFile(var F; FileName: string);DescriptionCall AssignFile to initialize a file variable in Delphi code. F is a file variable of any file type. FileName is a string-type expression or an expression of type PChar if extended syntax is enabled. After calling AssignFile, F is associated with the external file until F is closed.  All further operations on the file variable F operate on the external file named by FileName.When the FileName parameter is empty, AssignFile associates F with the standard input or standard output file. If assigned an empty name, after a call to Reset (F), F refers to the standard input file, and after a call to Rewrite (F), F refers to the standard output file.Do not use AssignFile on a file variable that is already open.Note: To avoid scope conflicts, AssignFile replaces the Assign procedure that was available in early versions of the Delphi product. However, for backward compatibility Assign is still available.
      

  3.   

    AssignFile定义:procedure AssignFile(var F; FileName: string);
     说明:AssignFile使一个外部文件名与一个文件变量想联系。为了避免范围冲突,在Delphi中AssignFile函数代替Assign函数。 然而,为保持向下兼容Assign仍然有效。F是一个任意文件类型文件变量,FileName是一个字符串类型表达或Pchar类表达(如果扩充语法是容许的)。所有对F的进一步操作都是对应于外部文件名。在调用AssignFile以后,F与外部文件名关联,直到F被关闭。当FileName参数是空的,F关联标准输入或输出文件。当分配一个空文件名,在调用了Reset(F)之后,F参考标准输入文件,类似,在调用了Rewrite(F)后,F将参与标准输出文件。在一个文件变量已经打开之后能能用AssignFile。
     
    例子:
    var
      F: TextFile;
      S: string;
    begin
      if OpenDialog1.Execute then          { 显示打开对话框 }
      begin
        AssignFile(F, OpenDialog1.FileName);   { 在对话框中选择文件 }
        Reset(F);
        Readln(F, S);                          { 读文件的第一行 }
        Edit1.Text := S;                       { 赋值到Edit1 }
        CloseFile(F);
      end;
    end;