how to write tstrings' contents into an file? |
尚未結案
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
source code: procedure TForm1.Button1Click(Sender: TObject);
var
s:tstrings;
ff:textfile;
begin
s := tstringlist.Create;
open1.Filter := 'Filetypes|*.txt';
if open1.Execute then
try
s.LoadFromFile(open1.FileName);
if not fileexists('C:\ff.txt') then
filecreate('C:\ff.txt');
writeln(ff,s.text); finally
s.Free;
end;
end;
end.
open1 :opendialog1 My plan: write the contents stored in Tstringlist(s) in an external file called ff. Cos the ff.txt doesnt exist at first, then i create it, but i cant run successfully. hope somebody can fix these code for me! thanx a lot!
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
var S:TStrings; ff:Textfile; IsAppend:Boolean; I:integer; begin S := TStringlist.Create; Try if open1.Execute then S.LoadFromFile(open1.FileName); IsAppend := Fileexists('C:\ff.txt'); Assignfile(ff,'C:\ff.txt'); try if IsAppend then Append(ff) else Rewrite(ff); For I:=0 to S.Count-1 do Writeln(ff,S[I]); flush(ff); finally Closefile(ff); end; finally FreeandNil(S); end; end;try it.. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |