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);
var a:Tstringlist; begin a:=Tstringlist.create; a.loadfromfile(''); a.string[i] a.free; end;
var F: TextFile; s: string;
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);
s := ''; end; //end of [while (not Eoln(F))]
//Close File CloseFile(F); end;
同意 theone_jxm() ( ) 信誉:100
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;
var 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;
begin
Memo1.Lines.LoadFromFile('C:\Autoexec.bat');
end;
再assignfile(Mytxt,'c:\1.txt');
然后Readln;
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);
a:Tstringlist;
begin
a:=Tstringlist.create;
a.loadfromfile('');
a.string[i]
a.free;
end;
F: TextFile;
s: string;
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);
s := '';
end; //end of [while (not Eoln(F))]
//Close File
CloseFile(F);
end;
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;
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;