在Delphi中,如何打开一个TXT文件?是用OpenFile函数吗?请各位大侠指点。
打开文件之后,又该如何将文件的内容取出来呢?谢谢各位了!!!

解决方案 »

  1.   

    用memomemo.loadfromfile('c:\aa.txt');就可以了!
      

  2.   

    你看看opendialog的控件帮助吧.很全的.
      

  3.   

    memo.loadfromfile('c:\aa.txt');就可以了!
      

  4.   

    F:TextFile;
      Dir:string;
      SpotID:string;
      SCom1,Scom2:string;Dir:='SellSpot_ID.txt';     //SellSpot_ID.txt文件是程序中用来存放操作站点号、通信串口的
        AssignFile(F, Dir);
        Reset(F);
        Readln(F,SpotID);    //得到登录地点
        Readln(F,Scom1);    //有线通信串口
        Readln(F,Scom2);    //无线通信串口
        CloseFile(F);
      

  5.   

    var f:TextFile;
        s:string;
    begin
    AssignFile(f,'c:\a.txt');
    Reset(f); 还有rewrite append等
    readln(f,s)  读取一行
    closefile(f);
    end;
      

  6.   

    FileOpen('c:\aa.txt',FILE_SHARE_READ or FILE_SHARE_WRITE);
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      Rec1=Record
        str1:string[10];
        x:Integer;
        y:Integer;
      end;
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        ListBox1: TListBox;
        ListBox2: TListBox;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      a:array[1..5,1..2] of Integer;
      rc:Rec1;
      i,j:Integer;
      file1,file2:Textfile;
      str1:string;
    begin
      assignfile(file1,'ftest1.dat');
      assignfile(file2,'ftest2.dat');
      Rewrite(file1);
      Rewrite(file2);
      randomize;
      for i:=1 to 5 do
        begin
          for j:=1 to 2 do
            begin
              a[i,j]:=random(10000);
              write(file1,a[i,j],' ');
              if j=2 then
                begin
                  rc.x:=a[i,j-1];
                  rc.y:=a[i,j];
                  rc.str1:='record1:'+IntToStr(i);
                  //writeln(file2,rc);
                  writeln(file2,rc.str1,'  ',rc.x,' ',rc.y);
                end;
            end;
            writeln(file1);
        end;
      Reset(file1);
      Reset(file2);
      for i:=1 to 5 do
        begin
          str1:='';
          for j:=1 to 2 do
            begin
              read(file1,a[i,j]);
              str1:=str1+inttostr(a[i,j])+'  ';
            end;
          readln(file1);
          //ShowMessage('show1.'+inttostr(i)+':'+str1);
          ListBox1.Items.Add('show1.'+inttostr(i)+':'+str1);
        end;
      for i:=1 to 5 do
        begin
          //readln(file2,rc);
          //readln(file2,b[i]);
          readln(file2,rc.str1,rc.x,rc.y);
          str1:=rc.str1+inttostr(rc.x)+'  '+inttostr(rc.y);
          //showmessage('show3.'+str1);
          ListBox2.Items.Add('show3.'+str1);
        end;
      closefile(file1);
      closefile(file2);
      //close;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      close;
    end;end.