为了在我使用的文件中写一些东西,例如这段代码:
procedure MyProc (... );
const
BufSize = 65535;
var
FileSrc, FileDst: TFileStream;
StreamRead: Cardinal;
InBuf, OutBuf: Array [0..bufsize] of byte;
begin
.....
FileSrc := TFileStream.Create (uFileSrc, fmOpenRead Or fmShareDenyWrite);
try
FileDst := TFileStream.Create (uFileTmp, fmCreate);
try
StreamRead := 0;
while ((iCounter < iFileSize) or (StreamRead = Cardinal(BufSize)))
begin
StreamRead := FileSrc.Read (InBuf, BufSize);
Inc (iCounter, StreamRead);
end;
finally
FileDst.Free;
end;
finally
FileSrc.Free;
end;
end;
对于 I/O 文件,我使用一个字节数组,所以一切正常,但是当我使用字符串时,例如声明:
InBuf, OutBuf: string // in delphi xe2 = unicode string
然后不工作。从某种意义上说,该文件什么也不写。我已经明白为什么,或者只是想明白了。我认为这个问题可能是为什么字符串只包含一个指向内存而不是静态结构的指针;正确的?在这种情况下,有一些解决方案可以解决吗?从某种意义上说,是否可以为我使用字符串而不是向量编写文件做点什么?或者我需要使用矢量?如果可能的话,我能做到吗?非常感谢。