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. |
-i:mask | ❌ | ✅ | ✅ | Specifies a mask (also using wildcards) for searching input files to be included. |
-l | ❌ | ❌ | ❌ | Specifies that hexadecimal values should be outputed as lowercase instead of uppercase. |
-o:file | "file.inc" | ❌ | ❌ | Specifies the include output filename. |
-r | ❌ | ❌ | ❌ | Specifies that files should be searched recursively in sub-folders. |
-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. |
-y | ❌ | ❌ | ❌ | Specifies to automatically overwrite existing output file. |
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
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. |