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;

  • 相关阅读:
    65_磁盘文件的使用
    64_设备文件的使用
    63_json解析成map格式
    62_json文件解析成结构体格式
    61_map生成json的使用
    60_通过结构体生成json
    59_字符串的转换
    58_字符串的一些操作函数的使用
    57_recover的使用
    56_异常处理error,errors和painc的使用
  • 原文地址:https://www.cnblogs.com/hqyj/p/2154546.html
Copyright © 2011-2022 走看看