A Delphi binary file to .inc file tool with full source code.
This tool takes as input any file, reads it binary and creates a include file with constants arrays containing the file contents.
Simply run the bin2inc tool from command line and specify the parameters you want to personalizze your output file.
| Switch | Default | Mandatory | Multiple | Description |
|---|---|---|---|---|
| -a:# | auto | ❌ | ❌ | Specifies the desired array alignment. # can be one of the values: 1 for byte alignment, 2 for word, 3 for cardinal, 4 for unsigned 64-bit integer. If a file cannot be aligned by specified alignment, automatic alignment will be used. |
| -c:## | 8 | ❌ | ❌ | Speficies the number of columns/values to use for line while describing arrays. |
| -f | ❌ | ❌ | ❌ | Indicates to create constant reference structure to arrays at the end of include file. |
| -l | ❌ | ❌ | ❌ | Specifies that hexadecimal values should be outputed as lowercase instead of uppercase. |
| -r | ❌ | ❌ | ❌ | Specifies that files should be searched recursively in sub-folders. |
| -y | ❌ | ❌ | ❌ | Specifies to automatically overwrite existing output file. |
| -i:mask | ❌ | ✅ | ✅ | Specifies a mask (also using wildcards) for searching input files to be included. |
| -o:file | "file.inc" | ❌ | ❌ | Specifies the include output filename. |
| -s:## | 2 | ❌ | ❌ | Specifies that indentation should be made with the specified number of spaces. |
| -t | ❌ | ❌ | ❌ | Specifies that indentation should be made with a tabulation character. |
You can include a .inc file almost anywhere in a .pas file putting a $I compiler directive as long as the code doesn't break, for example you could include it under your interface or implementation section like this.
...
implementation
uses
SysUtils;
{$I 'bin\test.inc'}
...Or also, include this inside a function like this.
...
procedure GenerateOutputFile;
{$I 'bin\test.inc'}
var
I: Integer;
S: String;
begin
...You can access the constant as you wish, but you can move it back to a memory stream for example in this way:
var MStream := TMemoryStream.Create;
MStream.Write(BIN_FILE_BIN[0], SizeOf(BIN_FILE_BIN));Firstly build (but don't run) Bin2Inc.dpr "bin" folder, then execute:
bin2inc -i:commedia.txt -o:test.inc -y
Now, build IncTest.dpr in the "bin" folder too and just run it from the folder, it will compare content of original file with that in the include file.
| Version | Release date | Description |
|---|---|---|
| 1.0 | 2002 | First version created in early '00s, released Sep 24, 2023 on GitHub. |
| 1.1 | 2023-09-27 | Fixed an old slow implementation and corrected small things. |
| 1.1 | 2023-10-20 | Added a sample project showing how to use this. |
| 1.2 | 2023-10-28 | Added the -f option. |