回 帖 发 新 帖 刷新版面

主题:一个问题!~

请问如果将2个文件(上篇.txt和下篇.txt)放入文件(全部.txt)中??
应该用怎么样的代码来编写??求救!~~~[em8]

回复列表 (共3个回复)

沙发

给你个完整的程序:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
    infile:textfile;
    fname,instring:string;
begin
    opendialog1.Filter:='文本文件|*.txt';
    if opendialog1.Execute then
       begin
       fname:=opendialog1.FileName;
       edit1.Text:=fname;
       assignfile(infile,fname);
       reset(infile);
       while not eof(infile) do
           begin
           readln(infile,instring);
           memo1.Lines.Add(instring);
           end;
       closefile(infile);
       end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
   outfile:textfile;
   fname:string;
begin
   if savedialog1.Execute then
      begin
      fname:=savedialog1.FileName;
      edit1.Text:=fname;
      assignfile(outfile,fname);
      rewrite(outfile);
      writeln(outfile,memo1.text);
      end;
   closefile(outfile);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  application.Terminate;
end;

end.

怎么样,够意思吧!!

板凳

我研究一下~`谢谢~~长尾兔

3 楼

用MEMO的loadfromfile,好像会再简单些。

我来回复

您尚未登录,请登录后再回复。点此登录或注册