用opendialog打开的文件,文件的数据放在哪里?

解决方案 »

  1.   

    不太明白你的意思
    用opendialog打开的文件,好象是你只是取得该文件的信息(路径等),而不能直接得到他的数据!
      

  2.   

    opendialog.FileName—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  3.   

    to: rikky(读书、心知、生活)
    那么我怎么才可以得到文件的数据了
      

  4.   

    你通过opendialog获取要打开文件的路径,用FileOpen、FileRead、FileClose、FileSeek等文件操作函数获取文件数据
      

  5.   

    opendialog的所谓打开文件只是返回用户选择的文件路径名而已,并不是真的替你打开这个文件,打开文件的操作还是要自己写
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject);var
      iFileHandle: Integer;
      iFileLength: Integer;
      iBytesRead: Integer;
      Buffer: PChar;
      i: Integer
    begin
      if OpenDialog1.Execute then
      begin
        try
          iFileHandle := FileOpen(OpenDialog1.FileName, fmOpenRead);
          iFileLength := FileSeek(iFileHandle,0,2);
          FileSeek(iFileHandle,0,0);
          Buffer := PChar(AllocMem(iFileLength + 1));
          iBytesRead := FileRead(iFileHandle, Buffer, iFileLength);
          FileClose(iFileHandle);
        finally
          FreeMem(Buffer);
        end;
      end;
    end;
      

  7.   

    opendialog打开的文件,其实只是在OpenDialog.FileName里得到一个文件路径
      

  8.   

    怎么读缓冲区中的数据?wks你知道吗?
      

  9.   

    那要看你是什么数据了
    Buffer其实就是字符串你看fileopen的帮助,里面介绍的很清楚,有例子的
    如果还看不懂的话,告诉你一个文件流类
    procedure TForm1.Button1Click(Sender: TObject);
    var
      aa:TFileStream;
      str:String;
    begin
      aa:=TFileStream.Create('c:\aa.txt',fmOpenReadWrite);
      //aa.Read()
      aa.Free;
    end;
      

  10.   

    另外用老的pascalI/O命令也可以:
    procedure TForm1.Button1Click(Sender: TObject);
    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;
      

  11.   

    append   打开存在的文件追加
    AssignFile  分配一个文件名给一个file或textfile变量
    blockread  从文件读入数据(块) 
    blockwrite  从文件读入数据(块) 
    closefile
    eof   查看文件是否到结尾
    erase   删除一个文件
    filepos  返回文件位置
    filesize  
    read    读格式化数据
    readln   从文本文件读一行数据
    reset    打开一个文件  先AssignFile  再reset
    rewrite  打开一个文件进行冲写操作
    seek
    write
    writeln