TResourceStream 的进度条 (Delphi)
如何将 ProgressBar 用于 SaveToFile
方法?实际上我想将资源保存到文件中,并在保存时将进度条从 0% 更新到 100%,我该怎么做?
How to use ProgressBar for SaveToFile
method ? Actually I want to save a resource to a file, and have progress bar update from 0% to 100% as it saves, how do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(2)
您可以像下面的代码一样创建自己的 TResourceStream 后代。但对于大量资源(可能就是这种情况,否则您就不必看到进度)最好将其“包装”在单独的线程中。如果您需要帮助,请大声喊叫。
You can make your own TResourceStream descendant like in the code below. But for large resources (and that's probably the case, otherwise you wouldn't have to see progress) it's better to "wrap" this in a separate thread. Yell if you need help with that.
由于它继承自 TStream,因此您可以使用 Size 属性来获取总大小,使用 Position 属性来获取当前位置。您可以使用它们来“驱动”进度条。然后,您可以使用单独的 TFileStream 并从 TResourceStream 逐块写入文件,而不是使用 SaveToFile 写入文件。您可以对最后一部分使用 TStream.CopyFrom 方法。
Since it inherits from TStream you could use the Size property to get the total size and Position to get the current position. You can use those to 'drive' your progressbar. Then instead of using SaveToFile to write to the file you would use a seperate TFileStream and write to it block by block from TResourceStream. You could use the TStream.CopyFrom method for that last part.