如何保存 TListView 内的内容到文件?
解决方案 »
- 请问如何固定wwdbgrid的列宽,以及禁止列位置的移动
- 关于对递归的理解
- 问一个问题,请大家帮帮我啊!
- 请各位大哥,给我调式这两个过程,马上揭贴,谢谢!
- 这么多人就不知道在delphi5.0下没有安装Excel,把dbgrid控件中的数据生成Excel文件吗?(求完整源代码送高分)
- 大家介绍基本学数据库的好书哦~~~~
- query小问题(菜鸟级)
- delphi调用 webservice 提示Unmarshalling Error
- 请问我怎么用程序下载文件并保存?
- 如何控制微型打印机?请高手指点,先谢谢啦!!!
- Qreport 设置QRShape 顺序
- 如何在查询(TADOQuery)中新增字段,并可以显示及修改值,从别的表计算统计中得出其值
IniFile: String;
fSource: TextFile;
begin
IniFile := _DIR_APP+__SDefaultDIR;
if FileExists(IniFile) then // 存在该 Ini 文件
begin
AssignFile(fSource,IniFile);
ReSet(fSource);
while not Eof(fSource) do begin
ReWrite(fSource);
WriteLn(fSource,text); // 写内容
CloseFile(fSource);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var slt: Tstringlist;
i,j: integer;
begin
slt:= Tstringlist.Create;
j:= ListView1.Items.Count;
for i:=0 to j - 1 do
slt.Add(ListView1.Items[i].Caption);
slt.SaveToFile('c:\a.txt');
end;
FormatStr = '%:-20s|';
var
StrList: TStringList;
Str: string;
Line: string;
i, j: integer;
begin
StrList := TStringList.Create;
try
Str := '';
Line := '';
for i := 0 to ListView1.Columns.Count - 1 do
begin
Str := Str + Format(FormatStr, [ListView1.Columns[i].Caption]);
Line := Line + '--------------------+';
end;
StrList.Add(Str);
Strlist.Add(Line);
for j := 0 to ListView1.Items.Count - 1 do
begin
Str := Format(FormatStr, [ListView1.Items[j].Caption]);
for i := 1 to ListView1.Columns.Count - 1 do
Str := Str + Format(FormatStr, [ListView1.Items[j].SubItems[i - 1]]);
StrList.Add(Str);
end;
Strlist.SaveToFile('temp.txt');
finally
StrList.Free;
end;
end;