menu
  Home  ==>  papers  ==>  colibri_utilities  ==>  dfm_binary_to_text   

DFM Binary to Text - Felix John COLIBRI.

  • abstract : This project converts the .DFM file in Binary format to the ASCII Text format
  • key words : .DFM, CONVERT.EXE, WinExec, conversion BinToTxt
  • software used : Windows XP, Delphi 6
  • hardware used : Pentium 1.400Mhz, 256 M memory, 140 G hard disc
  • scope : Delphi 1 to 2005 for Windows
  • level : Delphi developer
  • plan :


1 - Introduction

Many Delphi utilities must access to the .DFM content. Delphi has two .DFM format:
  • a binary format, which is a Windows Resource, and loads very quickly. This was the first Delphi 1 format
  • a textual format, which has the same content, but has an ASCII Format
Since Delphi 1, Borland included the CONVERT.EXE tool which converts the binary format into the ASCII format. This is a DOS .EXE, and therefore must be called from the command line. In addition, if a project contains many forms, the conversion can be painful.

This simple tool simply finds all the .DFM files, and converts them into their textual format.




2 - The Dfm BinToTxt converter

2.1 - Organization

The project:
  • detects all the .DFM files in a path
  • for each .DFM file, CONVERT.EXE is launched from Delphi
  • after all the conversion, the .txt files can be changed into .dfm files


We encountered a couple of small problems:
  • the syntax of CONVERT.EXE is not published. We only know that
         CONVERT my_dfm.DFM
    does the following:
    • if the file in already in ASCII format, nothing is done
    • if the file is in binary format, it is converted and saved as a .TXT file
    Maybe CONVERT.EXE can save the file with the .DFM extension, maybe the utility can convert a whole path, maybe there are other options. This utility did not cost much time, so we chose to go ahead rather than spend hours to figure out the details of CONVERT.EXE
  • to launch a DOS .EXE requires the use of CreateProcess. This is a rather uncomfortable endeavour:
    • the errors are not always acknowledged (it depends on the .EXE which is launched)
    • if the execution results in the creation of files, there might be some delays before they are visible. You cannot simply use FileExists or GetFileDate to check the result. Obviously there are some threading issues. To avoid any problem, we simply let the WinExec quietly finish its work, and start other handling after that
    Certainly Windows gurus will find this approach laughable, but I have more interesting things to do than spelunk into the Windows innards.

2.2 - Detection of the Files

As already presented in other papers, we basically use FindFirst and FindNext. The search is performed with the following procedure call:

handle_all_files_recursive(1, my_pathmy_extension,
    [e_dir_handle_filee_dir_recursive], my_call_backNil);

and this procedures calls our call-back function:

procedure my_call_back(p_levelIntegerp_pathp_file_nameString;
    p_pt_dataPointer);
  begin // my_call_back
    f_execute_convert(k_convert_namep_pathp_file_name);
  end// my_call_back



2.3 - WinExec

The execution of the DOS conversion is done here:

function f_execute_convert(p_exe_namep_pathp_file_nameString): boolean;
  var l_current_pathString;
      l_command_lineString;
      l_startup_infotStartupInfo;
      l_process_infotProcessInformation;
      l_error_codedWord;
  begin
    Result:= False;

    l_current_path:= GetCurrentDir;
    ChDir(p_path);

    l_command_line:= p_exe_name' 'p_pathp_file_name;

    FillChar(l_startup_infoSizeOf(l_startup_info), 0);
    FillChar(l_process_infoSizeOf(l_process_info), 0);

    CreateProcess(nil,
        pChar(l_command_line),
        nilnilfalse,
        0, nilnil,
        l_startup_infol_process_info);

    // -- the the thread handle which is no longer required
    CloseHandle(l_process_info.hThread);

    // -- wait until the child has finished
    WaitForSingleObject(l_process_info.hProcessInfinite);

    // -- get the error code
    // -- 0 if pb
    GetExitCodeProcess(l_process_info.hProcessl_error_code);

    if (l_error_code= 0) or (l_error_code= 1)
      then begin
          Result:= True;
          display('  ok_exit 'IntToStr(l_error_code));
        end
      else begin
          display('*** pb 'p_exe_name' 'p_pathp_file_name
            + Format(' %4x ', [l_error_code]));
        end;

    // -- close the process handle
    CloseHandle(l_process_info.hProcess);
    ChDir(l_current_path);
  end// f_execute_dcc



2.4 - Additional handling

In addition to the conversion, we added the following features:
  • the files to convert (the .DFM and the .PAS) are copied to a target path. Therefore, we do not touch the original files (just in case...)
  • we can display the size difference. The ASCII file is always larger than the binary version, and this gives us a visual clue that the conversion somehow succeeded
  • the .TXT resulting from the conversion can replace the binary .DFM using the "change_the_txt_into_dfm_" button: we erase the .DFM and rename the .TXT.
  • if you click on a .DFM in the DirectoryListBox, and the view_dfm_ TabSheet is selected, the .DFM is loaded. You then can see the textual version of the .DFM
Here is a snapshot of the utility:



2.5 - Mini Manual

To use the utility:
   copy the .DFM and the corresponding .PAS in a directory of your choice
   copy CONVERT.EXE from C:\Program Files\Delphi\BIN\ to the EXE directory
   compile convert_dfm_to_txt.dpr and execute
   select the directory using the DirectoryListBox
   click "all_dir_recursive_"
   the .PAS and .DFM will be copied into the _data\_dfm_to_txt\ path, and all binary .DFMs will be converted to their .TXT counterpart
And:
  • to check the size difference, click "check_"
  • to erase the binary .DFM and rename the .TXT, click "change_the_txt_into_dfm_"
  • to view an ascii .DFM
       select the proper path using the tDirectoryListbox
       select the "view_dfm_" tab
       click on the .DFM



3 - Download the Sources

Here are the source code files: The .ZIP file(s) contain:
  • the main program (.DPR, .DOF, .RES), the main form (.PAS, .DFM), and any other auxiliary form
  • any .TXT for parameters, samples, test data
  • all units (.PAS) for units
Those .ZIP
  • are self-contained: you will not need any other product (unless expressly mentioned).
  • for Delphi 6 projects, can be used from any folder (the pathes are RELATIVE)
  • will not modify your PC in any way beyond the path where you placed the .ZIP (no registry changes, no path creation etc).
To use the .ZIP:
  • create or select any folder of your choice
  • unzip the downloaded file
  • using Delphi, compile and execute
To remove the .ZIP simply delete the folder.

The Pascal code uses the Alsacian notation, which prefixes identifier by program area: K_onstant, T_ype, G_lobal, L_ocal, P_arametre, F_unction, C_lass etc. This notation is presented in the Alsacian Notation paper.



As usual:

  • please tell us at fcolibri@felix-colibri.com if you found some errors, mistakes, bugs, broken links or had some problem downloading the file. Resulting corrections will be helpful for other readers
  • we welcome any comment, criticism, enhancement, other sources or reference suggestion. Just send an e-mail to fcolibri@felix-colibri.com.
  • or more simply, enter your (anonymous or with your e-mail if you want an answer) comments below and clic the "send" button
    Name :
    E-mail :
    Comments * :
     

  • and if you liked this article, talk about this site to your fellow developpers, add a link to your links page ou mention our articles in your blog or newsgroup posts when relevant. That's the way we operate: the more traffic and Google references we get, the more articles we will write.



4 - Conclusion

The convert_dfm_to_txt utility convert any binary .DFM into its Ascii version.




5 - Other Papers with Source and Links

Database
database reverse engineering Extraction of the Database Schema by analyzing the content of the application's .DFMs
sql parser Parsing SQL requests in Delphi, starting from an EBNF grammar for SELECT, INSERT and UPDATE
ado net tutorial a complete Ado Net architectural presentation, and projects for creating the Database, creating Tables, adding, deleting and updating rows, displaying the data in controls and DataGrids, using in memory DataSets, handling Views, updating the Tables with a DataGrid
turbo delphi interbase tutorial develop database applications with Turbo Delphi and Interbase. Complete ADO Net architecture, and full projects to create the database, the Tables, fill the rows, display and update the values with DataGrids. Uses the BDP
bdp ado net blobs BDP and Blobs : reading and writing Blob fields using the BDP with Turbo Delphi
interbase stored procedure grammar Interbase Stored Procedure Grammar : The BNF Grammar of the Interbase Stored Procedure. This grammar can be used to build stored procedure utilities, like pretty printers, renaming tools, Sql Engine conversion or ports
using interbase system tables Using InterBase System Tables : The Interbase / FireBird System Tables: description of the main Tables, with their relationship and presents examples of how to extract information from the schema
eco tutorial Writing a simple ECO application: the UML model, the in memory objects and the GUI presentation. We also will show how to evaluate OCL expressions using the EcoHandles, and persist the data on disc
delphi dbx4 programming the new dbExpress 4 framework for RAD Studio 2007 : the configuration files, how to connect, read and write data, using tracing and pooling delegates and metadata handling
blackfishsql using the new BlackfishSql standalone database engine of RAD Studio 2007 (Win32 and .Net) : create the database, create / fill / read Tables, use Pascal User Defined Functions and Stored Procedures
rave pdf intraweb how to produce PDF reports using Rave, and have an Intraweb site generate and display .PDF pages, with multi-user access
embarcadero er studio Embarcadero ER Studio tutorial: how to use the Entity Relationship tool to create a new model, reverse engineer a database, create sub-models, generate reports, import metadata, switch to Dimensional Model
Web
sql to html converting SQL ascii request to HTML format
simple web server a simple HTTP web Server and the corresponding HTTP web Browser, using our Client Server Socket library
simple cgi web server a simple CGI Web Server which handles HTML <FORM> requests, mainly for debugging CGI Server extension purposes
cgi database browser a CGI extension in order to display and modify a Table using a Web Browser
whois a Whois Client who requests information about owners of IP adresses. Works in batch mode.
web downloader an HTTP tool enabling to save on a local folder an HTML page with its associated images (.GIF, .JPEG, .PNG or other) for archieving or later off-line reading
web spider a Web Spider allowing to download all pages from a site, with custom or GUI filtering and selection.
asp net log file a logging CLASS allowing to monitor the Asp.Net events, mainly used for undesrtanding, debugging and journaling Asp.Net Web applications
asp net viewstate viewer an ASP.NET utility displaying the content of the viewtate field which carries the request state between Internet Explorer and the IIS / CASSINI Servers
rss reader the RSS Reader lets you download and view the content of an .RSS feed (the entry point into somebody's blog) in a tMemo or a tTreeView. Comes complete with an .HTML downloader and an .XML parser
news message tree how to build a tree of the NNTP News Messages. The downloaded messages are displayed in tListBox by message thread (topic), and for each thread the messages are presented in a tTreeVi"ew
threaded indy news reader a NewsReader which presents the articles sorted by thread and in a logical hierarchical way. This is the basic Indy newsreader demo plus the tree organization of messages
delphi asp net portal programming presentation, architecture and programming of the Delphi Asp Net Portal. This is a Delphi version of the Microsoft ASP.NET Starter Kit Web Portal showcase. With detailed schemas and step by step presentation, the Sql scripts and binaries of the Database
delphi web designer a tiny Delphi "RAD Web Designer", which explains how the Delphi IDE can be used to generate .HTML pages using the Palette / Object Inspector / Form metaphor to layout the page content
intraweb architecture the architecture of the Intraweb web site building tool. Explains how Delphi "rad html generator" work, and presents the CLASS organization (UML Class diagrams)
ajax tutorial AJAX Tutorial : writing an AJAX web application. How AJAX works, using a JavaScript DOM parser, the Indy Web Server, requesting .XML data packets - Integrated development project
asp net master pages Asp.Net 2.0 Master Pages : the new Asp.Net 2.0 allow us to define the page structure in a hierarchical way using Master Pages and Content Pages, in a way similar to tForm inheritance
delphi asp net 20 databases Asp.Net 2.0 and Ado.Net 2.0 : displaying and writing InterBase and Blackfish Sql data using Dbx4, Ado.Net Db and AdoDbxClient. Handling of ListBox and GridView with DataSource components
asp net 20 users roles profiles Asp.Net 2.0 Security: Users, Roles and Profiles : Asp.Net 2.0 offers a vaslty improved support for handling security: new Login Controls, and services for managing Users, grouping Users in Roles, and storing User preferences in Profiles
bayesian spam filter Bayesian Spam Filter : presentation and implementation of a spam elimination tool which uses Bayesian Filtering techniques
TCP/IP
tcp ip sniffer project to capture and display the packets travelling on the Ethernet network of your PC.
sniffing interbase traffic capture and analysis of Interbase packets. Creation of a database and test table, and comparison of the BDE vs Interbase Express Delphi components
socket programming the simplest Client Server example of TCP / IP communication using Windows Sockets with Delphi
delphi socket architecture the organization of the ScktComp unit, with UML diagrams and a simple Client Server file transfer example using tClientSocket and tServerSocket
Object Oriented Programming Components
delphi virtual constructor VIRTUAL CONSTRUCTORS together with CLASS references and dynamic Packages allow the separation between a main project and modules compiled and linked in later. The starting point for Application Frameworks and Plugins
delphi generics tutorial Delphi Generics Tutorial : using Generics (parameterized types) in Delphi : the type parameter and the type argument, application of generics, constraints on INTERFACEs or CONSTRUCTORs
UML Patterns
the lexi editor delphi source code of the Gof Editor: Composite, Decorator, Iterator, Strategy, Visitor, Command, with UML diagrams
factory and bridge patterns presentation and Delphi sources for the Abstract Factory and Bridge patterns, used in the Lexi Document Editor case study from the GOF book
gof design patterns delphi source code of the 23 Gof (GAMMA and other) patterns: Composite, Decorator, Iterator, Strategy, Visitor, Command
Debug and Test
Graphic
delphi 3d designer build a 3d volume list, display it in perspective and move the camera, the screen or the volumes with the mouse.
writing a flash player build your own ShockWave Flash movie Player, with pause, custom back and forward steps, snapshots, resizing. Designed for analyzing .SWF demos.
Utilities
the coliget search engine a Full Text Search unit allowing to find the files in a directory satisfying a complex string request (UML AND Delphi OR Patters)
treeview html help viewer Treeview .HTML Help Viewer : the use of a Treeview along with a WebBrowser to display .HTML files alows both structuring and ordering of the help topics. This tool was used to browse the Delphi PRISM Wiki help.
Delphi utilities
delphi net bdsproj structure and analysis of the .BDSPROJ file with the help of a small Delphi .XML parser
dccil bat generator generation of the .BAT for the Delphi DCCIL command line compiler using the .BDSPROJ
dfm parser a Delphi Project analyzing the .DFM file and building a memory representation. This can be used for transformations of the form components
dfm binary to text a Delphi Project converting all .DFM file from a path from binary to ascii format
component to code generate the component creation and initialization code by analyzing the .DFM. Handy to avoid installing components on the Palette when examining new libraries
exe dll pe explorer presents and analyzes the content of .EXE and .DLL files. The starting point for extracting resources, spying .DLL function calls or injecting additional functionalities
dll and process viewer analyze and display the list of running processes, with their associated DLLs and Memory mapped files (Process Walker)
Controls
find memo a tMemo with "find first", "find next", "sort", "save" capabilities
Helper units
windows environment read and write Windows Environment strings
stdin stdout send and receive strings from a GUI application to a CONSOLE application




6 - The author

Felix John COLIBRI works at the Pascal Institute. Starting with Pascal in 1979, he then became involved with Object Oriented Programming, Delphi, Sql, Tcp/Ip, Html, UML. Currently, he is mainly active in the area of custom software development (new projects, maintenance, audits, BDE migration, Delphi Xe_n migrations, refactoring), Delphi Consulting and Delph training. His web site features tutorials, technical papers about programming with full downloadable source code, and the description and calendar of forthcoming Delphi, FireBird, Tcp/IP, Web Services, OOP  /  UML, Design Patterns, Unit Testing training sessions.
Created: nov-04. Last updated: jul-15 - 98 articles, 131 .ZIP sources, 1012 figures
Copyright © Felix J. Colibri   http://www.felix-colibri.com 2004 - 2015. All rigths reserved
Back:    Home  Papers  Training  Delphi developments  Links  Download
the Pascal Institute

Felix J COLIBRI

+ Home
  + articles_with_sources
    + database
    + web_internet_sockets
    + oop_components
    + uml_design_patterns
    + debug_and_test
    + graphic
    + controls
    + colibri_utilities
      – delphi_net_bdsproj
      – dccil_bat_generator
      – coliget_search_engine
      – dfm_parser
      – dfm_binary_to_text
      – component_to_code
      – exe_dll_pe_explorer
      – dll_process_viewer
      – the_alsacian_notation
      – html_help_viewer
      – cooking_the_code
      – events_record_playback
    + colibri_helpers
    + delphi
    + firemonkey
    + compilers
  + delphi_training
  + delphi_developments
  + sweet_home
  – download_zip_sources
  + links
Contacts
Site Map
– search :

RSS feed  
Blog