//Read文本文件 var txtFile: TextFile; txtString: String; begin AssignFile(txtFile,'C:\test.txt'); Reset(txtFile); try while not Eof(txtFile) do begin Readln(txtFile,txtString); ListBox.Items.Add(txtString); //忘记啦!好像是这么来着! end; finally CloseFile(txtFile); end; end;
//Write文本文件 var i: Integer; txtFile: TextFile; txtString: String; begin AssignFile(txtFile,'C:\test.txt'); Rewrite(txtFile); try for i:=0 to ListBox.Items.Count - 1 do begin Writeln(txtFile,ListBox.Items[i].Text); //忘记啦!好像是这么来着! end; finally CloseFile(txtFile); end; end;
用CreateFile创建文件 再用ReadFile读取文件内容 WriteFile写数据到文件//ReadFile.....for i:=0 to Count-1 do begin if str:string<>ListBox1.Items.String[i] then Listbox1.Items.Add(str:String); end;ListBox1.DeleteSelected; // 删除所选择的内容for i:=0 to Count-1 do begin if ListBox1.Items.String[i]=str:String then ListBox1.Selected[i]:=True; end; ListBox1.DeleteSelected;for i:=0 to Count-1 do begin if (ListBox1.Selected[i]) and (InputQuery('提示','请输入新数据',str:String)) and (str:String<>'') then ListBox1.Items.ExChange(i,ListBox1.Add(str:String)); end; ListBox1.Items.Delete[ListBox1.Count];ListBox1.SaveToFile(FileName:String);//WriteFile....
读取文件: procedure LoadFile(AListBox : TListBox; AFileName : String); var sl : TStringList; i : Integer; begin sl := TStringList.Create; try sl.LoadFromFile(AFileName); for i := 0 to sl.Count - 1 do if AListBox.Items.IndexOf(sl[i]) < 0 then AListBox.Items.Add(sl[i]); finally sl.Free; end; end;至于存盘直接用AListBox.Items.SaveToFile('c:\xxx\xxx.xxx');就行了
var
txtFile: TextFile;
txtString: String;
begin
AssignFile(txtFile,'C:\test.txt');
Reset(txtFile);
try
while not Eof(txtFile) do
begin
Readln(txtFile,txtString);
ListBox.Items.Add(txtString); //忘记啦!好像是这么来着!
end;
finally
CloseFile(txtFile);
end;
end;
var
i: Integer;
txtFile: TextFile;
txtString: String;
begin
AssignFile(txtFile,'C:\test.txt');
Rewrite(txtFile);
try
for i:=0 to ListBox.Items.Count - 1 do
begin
Writeln(txtFile,ListBox.Items[i].Text); //忘记啦!好像是这么来着!
end;
finally
CloseFile(txtFile);
end;
end;
(内容写入到文本文件中)
ListBox.Items.LoadFromFile('');无重复信息
把ListBox.Sorted设为True;
检查相邻行是否相同,如果相同,删除之写文件
ListBox.Items.SaveToFile('');
再用ReadFile读取文件内容
WriteFile写数据到文件//ReadFile.....for i:=0 to Count-1 do
begin
if str:string<>ListBox1.Items.String[i] then
Listbox1.Items.Add(str:String);
end;ListBox1.DeleteSelected; // 删除所选择的内容for i:=0 to Count-1 do
begin
if ListBox1.Items.String[i]=str:String then
ListBox1.Selected[i]:=True;
end;
ListBox1.DeleteSelected;for i:=0 to Count-1 do
begin
if (ListBox1.Selected[i]) and (InputQuery('提示','请输入新数据',str:String)) and (str:String<>'') then
ListBox1.Items.ExChange(i,ListBox1.Add(str:String));
end;
ListBox1.Items.Delete[ListBox1.Count];ListBox1.SaveToFile(FileName:String);//WriteFile....
procedure LoadFile(AListBox : TListBox; AFileName : String);
var
sl : TStringList;
i : Integer;
begin
sl := TStringList.Create;
try
sl.LoadFromFile(AFileName);
for i := 0 to sl.Count - 1 do
if AListBox.Items.IndexOf(sl[i]) < 0 then
AListBox.Items.Add(sl[i]);
finally
sl.Free;
end;
end;至于存盘直接用AListBox.Items.SaveToFile('c:\xxx\xxx.xxx');就行了