现代Object Pascal介绍-第六部分
立即下载
薄情
2025-05-13
OutputInt
InputInt
资源
308.4 KB
robsean@126.com QQ 群:192903718
1 / 11
6. 运行时库
6.1. 使用 streams(流)输入/输出
现代的程序应该使用 TStream 类,并且它是很多完成输入/输出的衍生物。它有很多有用的派
生物,像 TFileStream, TMemoryStream, TStringStream.
{$mode objfpc}{$H+}{$J-}
uses SysUtils, Classes;
var
S: TStream;
InputInt, OutputInt: Integer;
begin
InputInt := 666;
S := TFileStream.Create('my_binary_file.data', fmCreate);
try
S.WriteBuffer(InputInt, SizeOf(InputInt));
finally FreeAndNil(S) end;
S := TFileStream.Create('my_binary_file.data', fmOpenRead);
try
S.ReadBuffer(OutputInt, SizeOf(OutputInt));
finally FreeAndNil(S) end;
Writeln('Read from file got integer: ', OutputInt);
end.
在 Castle Game Engine 中: 你应该使用 Download 方法来创建一个流(stream),操作资源
(资源包括下载自 URLs和 Android 资产(assets)的文件,数据)。此外,为打开在你游戏数据
(一般在 data子目录中)中的资源使用 ApplicationData 函数。
EnableNetwork := true;
S := Download('https://castle-engine.io/latest.zip');
S := Download('file:///home/michalis/my_binary_file.data');
S := Do
OutputInt/InputInt/资源/
OutputInt/InputInt/资源/
-->