zoukankan      html  css  js  c++  java
  • 文件操作

    type
       studentRecord  = record
         xh,xm:string[6];
         yw,sx,wy:integer;
       end;

    implementation

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);
    var
        t:studentrecord;
        f: file of studentrecord;
    begin
        assignfile(f,'c:\temp\文件.dat');   //文件变量与外部文件建立联系
        if fileexists('c:\temp\文件.dat') then
          reset(f) //以读方式打开文件
        else
          rewrite(f);  //以写方式打开文件;eof(f)为true
          //erase(f);//删除文件
        while not eof(f) do
        begin
            read(f,t);  //读取数据
            //
        end;
        closefile(f); //文件变量与外部文件中断联系
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
       t: studentrecord;
       f:file of studentrecord;
       size:integer;
    begin
      t.xh:='yuan';
      t.xm:='hahah';
      t.yw:=100;
      t.sx:=99;
      t.wy:=98;
      assignfile(f,'c:\temp\文件.dat');
      reset(f);
      size:=filesize(f);  //返回文件的大小
      seek(f,size);
      write(f,t);   //
      seek(f,0); //将文件指针移至文件位置
      listbox1.Clear;
      while not eof(f) do
      begin
          read(f,t);
          listbox1.Items.Add(t.xh+t.xm+inttostr(t.yw)+inttostr(t.sx)+inttostr(t.wy));
      end;
      closefile(f);
    end;

  • 相关阅读:
    c++智能指针的一些文章
    c++ template(8)模版多态
    空指针赋值分区
    windbg调试命令
    c++ template(5)模板实战
    GetStockObject 理解
    c++ template(6)模板术语
    c++ template(71)模板参数声明
    DirectDraw教程资料
    c++ template(9)trait和Policy
  • 原文地址:https://www.cnblogs.com/hqyj/p/2154546.html
Copyright © 2011-2022 走看看