[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

txt2dfm

I want to find an application, it can make Delphi 5 txtForm format to Delphi 4 dfm format.

I can find dfm2txt, but where can I find txt2dfm?
0
cookey
Asked:
cookey
1 Solution
 
intheCommented:
A conversion from DFM (binary Delphi Form file) to a text
 file is done easily using the function ObjectResourceToText.
  For the opposite direction, use ObjectTextToResource.

The following code sample packs the whole task in a
 handy function.
Usage:

// convert a DFM file to TXT
ConvertFormOrText('e:\temp\unit11.dfm', ConvertToText);

// vice versa, extension is not necessary
ConvertFormOrText('e:\temp\unit11', ConvertToDFM);

   
 type
  TDFMorTXT = (ConvertToForm, ConvertToText);

{ Given a file name this routine will convert the file from either
  1. A text file to a DFM file or
  2. A DFM file to a text file
  The output file name is built from the input file name }
function ConvertFormOrText(FileToConvertFrom : string;
                           ConversionType : TDFMorTXT) : boolean;
var
  InputStream, OutputStream : TFileStream;
  FileToConvertTo : string;
begin
  Result := True;
  FileToConvertTo := FileToConvertFrom;

  { change file extensions as appropriate }
  case ConversionType of
    ConvertToForm:
    begin
      FileToConvertFrom := ChangeFileext(FileToConvertFrom, '.TXT');
      FileToConvertTo := ChangeFileext(FileToConvertFrom, '.DFM');
    end;
    ConvertToText:
    begin
      FileToConvertFrom := ChangeFileext(FileToConvertFrom, '.DFM');
      FileToConvertTo := ChangeFileext(FileToConvertFrom, '.TXT');
    end;
  end;

  try
    try
      { Create a file stream for the specified file }
      InputStream  := TFileStream.Create(FileToConvertFrom, fmOpenRead);
      OutputStream := TFileStream.Create(FileToConvertTo, fmCreate);

      { Now perform the selected conversion }
      case ConversionType of
        ConvertToForm : ObjectTextToResource(InputStream, OutputStream);
        ConvertToText : ObjectResourceToText(InputStream, OutputStream);
      end;
    except
      On EStreamError do Result := False;
    end;
  finally
    InputStream.Free;
    OutputStream.Free;
  end;
end;
0
 
rwilson032697Commented:
Nice code Barry. Personally I prefer to use convert.exe in the Delphi bin directory... :-)

Cheers,

Raymond.
0
 
cookeyAuthor Commented:
Thanks very much
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now