unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Memo1: TMemo;
OpenDialog1: TOpenDialog;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
function open_file(f_name :string;memostr:Tmemo):boolean;//定义读入文件函数
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
function TForm1.open_file(f_name: string;memostr:TMemo): boolean;
var File_str:Textfile;
tempstr :string;
begin
try
Screen.Cursor := crHourGlass;
AssignFile(File_str, f_name);
Reset(File_str);
application.ProcessMessages ;
while not eof(file_str) do
begin
Readln(File_str, tempstr);
memostr.Lines.Add(tempstr);
end;
finally
CloseFile(File_str);
Screen.Cursor:= crDefault;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
opendialog1.Filter :='files(.txt)|*.txt';
if opendialog1.Execute then
open_file(opendialog1.FileName,memo1);
end;
end.