用什么函数??

解决方案 »

  1.   

    给你一个例子:
    var
     f:textfile;
    procedure TForm_info_input.Button1Click(Sender: TObject);
    begin
     if opendialog1.Execute then
      file_name_edit.Text:=opendialog1.FileName;
    end;procedure TForm_info_input.input_pbtnClick(Sender: TObject);
    var
     cardno,cardsnr,card_str:string;
    begin
     if file_name_edit.Text='' then
     begin
      messagebox(self.handle,'文件路径不能为空!','提示',MB_OK);
      exit;
     end;
     with Form_DM do
     try
      AssignFile(f,file_name_edit.text);
      reset(f);
      ADO_card_init_1.close;
      ADO_card_init_1.sql.Text:='insert ck_card_init values(:Vcard_no,:Vcard_id,''4'')';
      while not eof(f) do
      begin
       readln(f,card_str);
       if length(card_str)<>15 then
       begin
        messagebox(self.handle,pchar(card_str+'格式不对!'),'提示',MB_OK);
        continue;
       end;
       cardno:=copy(card_str,1,6);
       cardsnr:=copy(card_str,8,8);
       ADO_card_init_1.parameters.ParamByName('Vcard_no').value:=cardno;
       ADO_card_init_1.parameters.ParamByName('Vcard_id').value:=cardsnr;
       ADO_card_init_1.execsql;
      end;
      closefile(f);
     except
      messagebox(self.handle,'信息导入出错或已存在导入信息!','错误',MB_OK);
      exit;
     end;
     Form_DM.ADO_card_init_0.Close;
     Form_dm.ADO_card_init_0.Open;
     mess_panel.Caption:='记录数为:'+inttostr(Form_DM.ado_card_init_0.recordcount)+'。';end;
      

  2.   

    你要读到哪? listbox的话可以loadfromfile
      

  3.   

    1.使用assignfile函数,让文件变量和文件联接起来;
    2.使用reset函数,对文件进行读操作(若想对文件进行写操作,就使用rewrite函数);
    3.使用readln函数读取文本文件中的内容;其实要对文本文件进行读写操作最好的方法是使用loadfromfile函数和savetofile函数