如题。
另:怎样对文件进行操作?如文件的拷贝等等,是用TStream 类吗?
另:怎样对文件进行操作?如文件的拷贝等等,是用TStream 类吗?
解决方案 »
- 连接数据库问题
- 怎样显示父类窗体上的控件?
- 谁有Erik Unger写的DirectX header files for DELPHI?
- 如何在按纽或标签上做超级链接?
- QReport菜鸟问题,在线求救
- TStream如何创建?为什么TStream.create编译会有warning?
- 高分求一本电子书:Indy in Depth,详情请见 http://www.atozedsoftware.com/indy/book/
- 一个关于SQL的问题,请大家帮个忙!谢谢了!
- 请大家帮忙,到那里有win api函数的文本下载啊?
- 我用Delphi5.0编写一个关机程序,在win98、me下可以关机,但在win2000下变成了注销。为什么?
- 急死我了求救 高手速来
- 如何让自己的程序生成exe文件,是程序自己组织EXE文件的各个模块,不是res打包释放!
Procedure FileCopy( Const sourcefilename, targetfilename: String );
Var
S, T: TFileStream;
Begin
S := TFileStream.Create( sourcefilename, fmOpenRead ); try
T := TFileStream.Create( targetfilename,
fmOpenWrite or fmCreate );
try
T.CopyFrom(S, S.Size ) ;
finally
T.Free;
end;
finally
S.Free;
end;
End;{This way uses memory blocks for read/write.}
procedure FileCopy(const FromFile, ToFile: string);
var
FromF, ToF: file;
NumRead, NumWritten: Word;
Buf: array[1..2048] of Char;
begin
AssignFile(FromF, FromFile);
Reset(FromF, 1); { Record size = 1 } AssignFile(ToF, ToFile); { Open output file }
Rewrite(ToF, 1); { Record size = 1 }
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
end;{This one uses LZCopy, which USES LZExpand.}
procedure CopyFile(FromFileName, ToFileName: string);
var
FromFile, ToFile: File;
begin
AssignFile(FromFile, FromFileName); { Assign FromFile to FromFileName } AssignFile(ToFile, ToFileName); { Assign ToFile to ToFileName }
Reset(FromFile); { Open file for input }
try
Rewrite(ToFile); { Create file for output }
try
{ copy the file an if a negative value is returned }
{ raise an exception }
if LZCopy(TFileRec(FromFile).Handle, TFileRec(ToFile).Handle) < 0
then
raise EInOutError.Create('Error using LZCopy')
finally
CloseFile(ToFile); { Close ToFile } end;
finally
CloseFile(FromFile); { Close FromFile }
end;
end;
procedure MyFunc();
const
pdx: LongInt = 1;
begin
...
Inc(pdx); //每次调用 MyFunc过程,pdx的值是递增的
end;
关于文件的操作,用TStream的确是一个好的选择.T
主要是TFileStream, TMemoryStream, TBlobStream 用的比较多