Forms Delphi

Title: Convert from DFM to Text and Text to DFM
Question: How can I convert my Delphi formfile (DFM) to a textfile and vice versa?
Answer:
{ use this function to convert;
Example (DFM-TXT): ConvertFormToText('unit1.dfm');
Example (TXT-DFM): ConvertTextToForm('unit1.txt'); }
uses
SysUtils;
function ConvertFormToText(SourceFileName: string): boolean;
var
InputStream, OutputStream: TFileStream;
DestFileName: string;
begin
result := true;
{ change the file extension to .txt }
DestFileName := ChangeFileExt(SourceFileName, '.txt');
{ Create a file stream for the specified file }
InputStream := TFileStream.Create(SourceFileName, fmOpenRead);
OutputStream := TFileStream.Create(DestFileName, fmCreate);
{ convert }
try
try
ObjectResourceToText(InputStream, OutputStream);
except
On EStreamError do Result := False;
end
finally
{ free memory }
InputStream.Free;
OutputStream.Free;
end;
end;
function ConvertTextToForm(SourceFileName: string): boolean;
var
InputStream, OutputStream: TFileStream;
DestFileName: string;
begin
result := true;
DestFileName := ChangeFileExt(SourceFileName, '.dfm');
InputStream := TFileStream.Create(SourceFileName, fmOpenRead);
OutputStream := TFileStream.Create(DestFileName, fmCreate);
try
try
ObjectTextToResource(InputStream, OutputStream);
except
on EStreamError do result := false;
end
finally
InputStream.Free;
OutputStream.Free;
end;
end;