Hi, How can I convert Delphi's DFM forms from the binary format into text format using C#?
+14
A:
Best way is probably to call CONVERT.EXE
, a command-line app included with Delphi. Here's an example in Delphi. You can do the same in C#.
Craig Stuntz
2010-08-16 15:33:57
Tip: Associate the *.DFM file type with CONVERT.EXE. That way you can select multiple DFM-files in the explorer and select "Open with Convert" in the context menu.
Jørn E. Angeltveit
2010-08-17 10:15:29
+2
A:
I use these four methods to test the DFM file format and to convert as follows:
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;
Bill
2010-08-16 19:31:37