How to create dot dat file in 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 names开发者_如何学JAVApace or headerfile, but what is that.
Thank you in advance.
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.
精彩评论