本文整理自网络,侵删。
Test for a binary form file//判断二进制格式文件function IsDFMBinary(FileName: string): Boolean;var F: TFileStream; B: Byte;begin B := 0; F := TFileStream.Create(FileName, fmOpenRead); try F.Read( B, 1 ); Result := B = $FF; finally F.Free; end;end;Convert from binary to text and vice versa// 从二进制转换为文本,反之亦然function Dfm2Txt(Src, Dest: string): boolean;var SrcS, DestS: TFileStream;begin if Src = Dest then begin MessageDlg('Error converting dfm file to binary!. ' + 'The source file and destination file names are the same.', mtError, [mbOK], 0); result := False; exit; end; SrcS := TFileStream.Create(Src, fmOpenRead); DestS := TFileStream.Create(Dest, fmCreate); try ObjectResourceToText(SrcS, DestS); if FileExists(Src) and FileExists(Dest) then Result := True else Result := False; finally SrcS.Free; DestS.Free; end;end;
function Txt2DFM(Src, Dest: string): boolean;var SrcS, DestS: TFileStream;begin if Src = Dest then begin MessageDlg('Error converting dfm file to binary!. ' + 'The source file and destination file names are the same.', mtError, [mbOK], 0); Result := False; exit; end; SrcS := TFileStream.Create(Src, fmOpenRead); DestS := TFileStream.Create(Dest, fmCreate); try ObjectTextToResource(SrcS, DestS); if FileExists(Src) and FileExists(Dest) then Result := True else Result := False; finally SrcS.Free; DestS.Free; end;end;Open a Binary DFM File as a Text Stream/// 打开二进制DFM文件作为文本流function DfmFile2Stream(const Src: string; Dest: TStream): boolean;var SrcS: TFileStream;begin SrcS := TFileStream.Create(Src, fmOpenRead or fmShareDenyWrite); try ObjectResourceToText(SrcS, Dest); Result := True; finally SrcS.Free; end;end;
相关阅读 >>
Delphi xe 新功能试用:多种皮肤样式静、动态设置方法
Delphi firedac fdconnection 事务
更多相关阅读请进入《Delphi》频道 >>