F: TextFile;
S: string;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
Readln(F, S); { Read first line of file }
Edit1.Text := S; { Put string in a TEdit control }
CloseFile(F);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
F1:TextFile;
Tmp_Str:String;
begin
AssignFile(F1,'c:\yourtxtfile.txt');
Reset(F1);
while not Eof(F1) do
begin
Readln(F1,Tmp_str);
ShowMessage(Tmp_Str);
end;
CloseFile(F1);
end;
begin
//test sFileName is exists?
if not FileExists(sFileName) then
Exit;
//Associate File
AssignFile(F,sFileName);
//Opens an existing file
Reset(F);
//First clear the memo
//Here Memo1 is Global var,and you can use Array
//or TMemoryStream var in stead of it.
if Memo1.lines.count > 0 then
Memo1.lines.clear;
//Read data per line
s := '';
while (not Eoln(F)) //File not end
begin
Readln(F,s);
Memo1.lines.Add(s);
if not (FileExists(GetNameDir(Application.ExeName)+'111.txt')) then
begin
Application.MessageBox('xuanhao.txt文件不存在','提示',MB_OK+MB_ICONSTOP);
Exit;
end;
AssignFile(FileName,GetNameDir(Application.ExeName) + '111.txt');
Reset(FileName);
Readln(FileName,Str);
CloseFile(FileName);