How to compare C++ builder/Delphi DFM binary files with Tortoise SVN ?


With antique versions of Delphi or C++ builder (<= 4), the DFM files – which define the structure of the application forms – are stored as binary files.
Binary files are a hassle because they prevent any batch processing, search, etc… But only with version control do they become a real pain in the ass. Versions can’t be compared, which makes conflict solving almost impossible. And conflicts happen often because Delphi and C++ builder modifiy DFM files for any reason (ex : moving a form around).

If you use Tortoise SVN and strugle with DFM conflicts, here is a solution to automate DFM comparison :

  1. Create the following « compare-dfms.bat » int your C:\ folder :

[code lang=shell]
echo offSETLOCAL enableextensions enabledelayedexpansionset dmf1_as_txt=%~1

set dmf1_as_txt=”%dmf1_as_txt:~0,-4%.txt”
set dmf2_as_txt=%~2
set dmf2_as_txt=”%dmf2_as_txt:~0,-4%.txt”

echo %dmf1_as_txt%
echo %dmf2_as_txt%

C:\Borland\CBuilder4\Bin\convert.exe %1 %dmf1_as_txt%
C:\Borland\CBuilder4\Bin\convert.exe %2 %dmf2_as_txt%

“D:\Program Files\TortoiseSVN\bin\TortoiseProc.exe” /command:diff /path:%dmf1_as_txt% /path2:%dmf2_as_txt%

[/code]

  1. Modify the convert.exe path based on C++ builder/Delphi installation folder .
    • Convert.exe is a Borland tool to convert DFM binary files to text back and forth
  2. Modify the TortoiseProc.exe path based on your TortoiseSVN installation folder.
    • TortoiseProc is the file comparison tool we’ll be using here, but feel free to use your prefered tool (ex : WinMerge)
  3. Open Tortoise settings (right click on a folder, and select menu TortoiseSVN->Settings), then select Diff Viewer and click on « Advanced »
    Tortoise-SVN-diff-viewer-advanced
  4. Add a new rule for « .dfm » extensions : “c:\compare-dfms.bat” %mine %base (Change the compare-dfms.bat path accordingly)
    Tortoise-SVN-diff-viewer-advanced-add-extension
  5. Finally, compare two revision of a DFM like you do for any other file (ex : double-click on the file name in the commit window) :
    Tortoise-SVN-diff-DFM

Please note that :

  • Starting in C++ Builder 5, DFMs can be saved as text files, hence making this trick useless.
  • Contrary to other file types, you can compare but not modify DFMs from tortoise. If you have changes to do, you will still have to make them from the C++ Builder IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *