Я использую эти четыре метода для проверки формата файла DFM и преобразования следующим образом:
function IsDFMStreamBinary( AStream: TMemoryStream ): Boolean;
{ Returns true if dfm file is in a binary format }
var
F: TMemoryStream;
B: byte;
begin
B := 0;
F := TMemoryStream.Create;
F.LoadFromStream( AStream );
try
F.read( B, 1 );
Result := B = $FF;
finally
F.Free;
end;
end;
function DfmFile2Stream( const ASrc: string; ADest: TStream ): Boolean;
{ Save dfm to stream }
var
SrcS: TFileStream;
begin
SrcS := TFileStream.Create( ASrc, fmOpenRead or fmShareDenyWrite );
try
ObjectResourceToText( SrcS, ADest );
Result := True;
finally
SrcS.Free;
end;
end;
procedure Txt2DFM( ASrc, ADest: string );
{ Convert Text to DFM }
var
SrcS, DestS: TFileStream;
begin
SrcS := TFileStream.Create( ASrc, fmOpenRead );
DestS := TFileStream.Create( ADest, fmCreate );
try
ObjectTextToResource( SrcS, DestS );
finally
SrcS.Free;
DestS.Free;
end;
end;
function Dfm2Txt( const ASrc, ADest: string ): boolean;
{ Convert a binary DFM to text }
var
ASrcS, ADestS: TFileStream;
begin
ASrcS := TFileStream.Create( ASrc, fmOpenRead );
ADestS := TFileStream.Create( ADest, fmCreate );
try
ObjectResourceToText( ASrcS, ADestS );
Result := True;
finally
ASrcS.Free;
ADestS.Free;
end;
end;