如何在Delphi Prism中创建dot dat文件?

发布于 2024-11-16 16:11:56 字数 353 浏览 7 评论 0原文

我是 Delphi Prism 的新手,并且一直在测试它。当我听到和读到程序员对 Delphi Prism for .NET 说坏话时,我现在能感受到他们的痛苦。天哪,我在编写简单的代码来创建二进制或文本文件并将其写入其中时遇到了麻烦。

这是代码:

Assignfile(f,"c:\Test.txt");
Rewrite(f,1);
BlockWrite(f,x,sizeof(x));
closefile(f);

我不断收到所有命令的“未知标识符”错误消息。

如何为 Delphi Prism 编写这段代码?我想,我没有包含正确的名称空间或头文件,但那是什么。

先感谢您。

I am new to Delphi Prism and been testing it out. When I hear and read programmers bad mouthing Delphi Prism for .NET, now I feel their pain. My God, I am having trouble with writing a simple code to create a binary or textfile and to write into them.

Here is the code:

Assignfile(f,"c:\Test.txt");
Rewrite(f,1);
BlockWrite(f,x,sizeof(x));
closefile(f);

I keep getting "unknown identifier" error messages for all the commands.

How do you write this code for Delphi Prism? I think, I am not including the right namespace or headerfile, but what is that.

Thank you in advance.

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

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

发布评论

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

评论(1

日暮斜阳 2024-11-23 16:11:56

您正在尝试使用delphi RTL/VCL 函数,但它们在.NET 中不可用。

您应该使用 System.IO 中的 FileStream 类。这是一个示例

var buffer: array of byte := new byte[500]; // creates a 500 byte large buffer
// fill your buffer

using fileStream := File.Create('c:\temp\MyTest.txt') do begin
    fileStream.Write(buffer, 0, buffer.Length);
end;

除此之外,.NET 框架中还提供了 XmlWriter、XmlTextWriter 和 TextWriter 类(以及其他类),它们在处理流时有很大帮助。因此,如果您喜欢写入文本,则可以使用 TextWriter 类轻松写入流。

You're trying to use delphi RTL/VCL functions, but they are not available in .NET.

Yous should use the FileStream class from System.IO. This is an example

var buffer: array of byte := new byte[500]; // creates a 500 byte large buffer
// fill your buffer

using fileStream := File.Create('c:\temp\MyTest.txt') do begin
    fileStream.Write(buffer, 0, buffer.Length);
end;

In addition to that, there are XmlWriter, XmlTextWriter and TextWriter classes (and others) available in the .NET framework that help alot when handling streams. So if you like to write text, you can use the TextWriter class to easily write to the stream.

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