help me?

zonelive 2004-07-13 09:11:48
我现有窗体是listview,button1,button2
button1的事件是点击时把数据读出来在listview中显示
如:
bh xm rq
11 a 2004-7-1
12 b 2004-7-1
13 c 2004-7-1
现在要求通过button2的事件把以上内容保存为txt文本文件
那位大哥帮我一把,谢谢~!
...全文
41 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cronuz 2004-07-13
  • 打赏
  • 举报
回复
楼主:还是好好看看jijl2001(jijl2001)的Source

TStringList与你要的TListView是不一样的,它只是字符類型的一種存储(就象字符型数組)
zonelive 2004-07-13
  • 打赏
  • 举报
回复
谢谢jijl2001,给我如此详细的答复
我在别人的原代码中看到这样一段代码:
var
FileRec:TStringList;
FileName:string;
begin
FileRec:=TStringList.Create;
try
FileName:=ExtractFilePath(Application.ExeName)+FormatDateTime('yyyymmdd',Now)+'.txt';
if FileExists(FileName) then
FileRec.LoadFromFile(FileName);
end
这段代码的效果是把数据保存到自动生成一个用日期为标题的文本文件中,
它这里只用了FileRec.LoadFromFile(FileName)就把数据载入到文本里了,能帮我看看吗?
jijl2001 2004-07-13
  • 打赏
  • 举报
回复
procedure TLogFileForm.FileNewItemClick(Sender: TObject);
var
Txt: TextFile;
Line,DataFile: string;
i:integer;
begin
if SaveDialog1.Execute then begin
DataFile:=SaveDialog1.FileName+'.txt';
AssignFile(Txt, DataFile);
try
ReWrite(Txt);
Line := SetSpace(Listview1.Columns.Items[0].Caption,20) +
SetSpace(Listview1.Columns.Items[1].Caption,20) +
SetSpace(Listview1.Columns.Items[2].Caption,10) +
SetSpace(Listview1.Columns.Items[3].Caption,20) +
Listview1.Columns.Items[4].Caption ;
Writeln(Txt, Line);
For i:=0 to Listview1.Items.Count-1 do begin
Line :=SetSpace(Listview1.Items[i].Caption,20) +
SetSpace(Listview1.Items[i].SubItems.Strings[0],20) +
SetSpace(Listview1.Items[i].SubItems.Strings[1],10) +
SetSpace(Listview1.Items[i].SubItems.Strings[2],20) +
Listview1.Items[i].SubItems.Strings[3];

Writeln(Txt, Line);
end;
PopMsg(1,'导出成功!');
finally
CloseFile(Txt);
end;
end;
end;

function SetSpace(Txt:string;L:integer):String;
var
i,a:integer;
begin
if Length(Txt)>L then begin
Result:=Copy(txt,1,L);
end else begin
a:=L-Length(txt);
For i:=a to L do begin
txt:=txt+' ';
end;
Result:=txt;
end;
end;
看看吧,

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧