如何在虚拟列表视图显示数据后立即保存它?

发布于 2024-10-14 10:58:41 字数 1654 浏览 1 评论 0原文

我想在填充数据后立即将数据保存在虚拟列表视图中。如果我使用 Savedialog 来保存数据,它就可以工作。如果我在ListviewOnData事件中调用保存过程,它会提示错误“无法创建文件...”。我在这里重现我的观察。

procedure TForm6.savefileList(AListView: TListView; sFileName: string);

begin
F:= TFileStream.Create(sFileName, fmCreate or fmOpenRead);
...                                                       
...
F.free;

end;

Procedure Tform6.SavevirtualistinSaveDialog;// A buttonClick calls this procedure
begin
If SaveDialog1.execute then
savefilelist(listview1, savedialog1.FileName);; // It works and save data in sfilename.
..
end;

procedure TForm6.ListView1Data(Sender: TObject; Item: TListItem);
begin


with ld do begin     
...
...
// filling data in virtual list

end;
             // Right after filling data, I call Dosavelist procedure.
Dosavelist; //error line " Can not Create file", If I annotate this line
            // and call SavevirtualistinDialog in another buttonClick event, 
            //the data can be saved.

end;

Procedure Tform6.Dosavelist;
begin
savefilelist(listview1, extractfilepath(application.exename)+'list.tmp');
end;

我希望在填充数据后立即将数据保存在列表视图(虚拟模式)中。但提示错误。

怎么解决呢。先感谢您。

新编辑:

我从listview1data事件中删除Dosavelist并将其放入另一个跟踪listview的函数中。有用。于是就解决了。 谢谢大家的帮助。

//My complete savefilelist para is:

savefilelist(listview1, extractfilepath(application.exename)+'list.tmp'); 

//In SavevirtualistinSaveDialog procedure, the complete save code line is: 

savefilelist(listview1, savedialog1.FileName);

或者Dosavelist程序可能没有被调用?在哪里?如何捕捉虚拟列表视图刚刚填充完毕的瞬间?我不知道 ListviewData 事件之后紧接的是什么事件?

再次感谢您。

I want to save data in virtual listview immediately after it is filled. If I use Savedialog to save data, it works. If I call save procedure in ListviewOnData event, it prompts Error " Can not create file...". I reproduce my observation here.

procedure TForm6.savefileList(AListView: TListView; sFileName: string);

begin
F:= TFileStream.Create(sFileName, fmCreate or fmOpenRead);
...                                                       
...
F.free;

end;

Procedure Tform6.SavevirtualistinSaveDialog;// A buttonClick calls this procedure
begin
If SaveDialog1.execute then
savefilelist(listview1, savedialog1.FileName);; // It works and save data in sfilename.
..
end;

procedure TForm6.ListView1Data(Sender: TObject; Item: TListItem);
begin


with ld do begin     
...
...
// filling data in virtual list

end;
             // Right after filling data, I call Dosavelist procedure.
Dosavelist; //error line " Can not Create file", If I annotate this line
            // and call SavevirtualistinDialog in another buttonClick event, 
            //the data can be saved.

end;

Procedure Tform6.Dosavelist;
begin
savefilelist(listview1, extractfilepath(application.exename)+'list.tmp');
end;

I expect save the data in listview (virtual mode) right after it is filled. But it prompts errors.

How to solve it. Thank you in advance.

New Edit:

I delete Dosavelist from listview1data event and put it in another function that tracks listview. It works. So it is solved.
Thank you all for help.

//My complete savefilelist para is:

savefilelist(listview1, extractfilepath(application.exename)+'list.tmp'); 

//In SavevirtualistinSaveDialog procedure, the complete save code line is: 

savefilelist(listview1, savedialog1.FileName);

Or Dosavelist procedure may not be called there? Where? How can I capture the moment when the virtual listview has just finished being filled? I do not know what event that is right after ListviewData event?

Thank you again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-10-21 10:58:41

这听起来好像您没有指定绝对文件路径。然后 Windows 在保存文件时依赖当前工作目录。保存对话框设置此目录,因此一切正常。在您的 ListviewOnData 事件中,cwd 可能未正确设置。

This sounds as if you don't specify an absolute file path. Then Windows relies on the current working directory when saving the file. The save dialog sets this directory, so everything works. In your ListviewOnData event, the cwd probably isn't set correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文