使用 Delphi 打开 ANSI 文件并保存 Unicode 文件
由于某种原因,最近我的许多客户端系统上的 *.UDL 文件不再兼容,因为它们曾经保存为 ANSI 文件,这不再与预期的 UNICODE 文件格式兼容。 最终结果是一个错误对话框,指出“该文件不是有效的复合文件”。
以编程方式打开这些文件并另存为 unicode 文件的最简单方法是什么? 我知道我可以通过在记事本中打开每个文件,然后另存为同一文件,但在另存为对话框的编码部分中选择“unicode”来完成此操作,但我需要在程序中执行此操作以减少支持来电。
这个问题很容易复制,只需在目录中创建一个 *.txt 文件,将其重命名为 *.UDL,然后使用 microsoft 编辑器对其进行编辑即可。 然后用记事本打开它并另存为ANSI编码文件。 尝试从 udl 编辑器打开 udl,它会告诉您它已损坏。 然后将其保存(使用记事本)为 Unicode 编码文件,它将再次正确打开。
For some reason, lately the *.UDL files on many of my client systems are no longer compatible as they were once saved as ANSI files, which is no longer compatible with the expected UNICODE file format. The end result is an error dialog which states "the file is not a valid compound file".
What is the easiest way to programatically open these files and save as a unicode file? I know I can do this by opening each one in notepad and then saving as the same file but with the "unicode" selected in the encoding section of the save as dialog, but I need to do this in the program to cut down on support calls.
This problem is very easy to duplicate, just create a *.txt file in a directory, rename it to *.UDL, then edit it using the microsoft editor. Then open it in notepad and save as the file as an ANSI encoded file. Try to open the udl from the udl editor and it will tell you its corrupt. then save it (using notepad) as a Unicode encoded file and it will open again properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,使用 delphi 2009,我能够想出以下代码,该代码似乎可以工作,但这是进行此转换的正确方法吗?
Ok, using delphi 2009, I was able to come up with the following code which appears to work, but is it the proper way of doing this conversion?
使用我的 TGpTextFile 单元可以非常简单地完成此操作。 我将整理一个简短的示例并将其发布在这里。
对于新的 Delphi 2009,它也应该非常简单 - 您可能正在使用它吗?
编辑:这是你如何使用我在 2009 年之前的 Delphis 中的东西来做到这一点。
许可证:上面的代码片段属于公共领域。 随心所欲地使用它。
This is very simple to do with my TGpTextFile unit. I'll put together a short sample and post it here.
It should also be very simple with the new Delphi 2009 - are you maybe using it?
EDIT: This his how you can do it using my stuff in pre-2009 Delphis.
License: The code fragment above belongs to public domain. Use it anyway you like.