Inserting a String Table into your .exe
This is helpful if you do not want to have a text file in the folder/directory of the program you distribute.
First open an editor like Notepad.exe
Type these words into the text file:
StringTable
begin
1, "DPSC"
2, "Tips"
3, "Source Code"
4, "Interviews, reviews, and articles"
end
Then save the text file as:
MyStrings.rc
We will use BRC32.exe that comes with Delphi, it should be in Delphi's
Bin folder/directory, to
compile the file.
In order to use BRC32.exe you have to use a DOS window, using DOS is
not hard at all.
Whenever you use DOS all you have to do, to get back to Windows (Your
desktop) is type the
word exit, then press the Enter key.
So we will type this sentance in the DOS window:
(We are in the 'c:\Delphi 3\bin\StringsRes\' directory)
c:\Delphi 3\bin\StringsRes>BRC32 -r MyStrings.rc
If this does not work or you get an error, you may not have Delphi in
your computers path.
A way around this is for you to copy the BRC32.exe and RW32CORE.DLL
into your
folder/directory that you are using, then try again.
(The above files, BRC32.exe and RW32CORE.DLL, may be different, for
different versions of
Delphi)
Use Explorer or another File Manager and have a look in your folder/directory,
you should find
that you have an extra file called MyStrings.RES.
Start Delphi, then start a new project (Application):
Look for {$R *.DFM} in Unit1 and add {$R MyStrings.res} next to it.
Add two labels to your Form.
Next drop a Button onto your Form, double-click on the Button and add
this code:
procedure TForm1.Button1Click(Sender: TObject);
var Buffer : Array[0..255] Of Char;
begin
LoadString(hInstance, 1, @Buffer, 255);
Label1.Caption := StrPas(Buffer);
LoadString(hInstance, 2, @Buffer, 255);
Label2.Caption := StrPas(Buffer);
end;
//StrPas = Converts null-terminated string to a Pascal string.
Run the program and then click on the Button.
Your complete unit should look like this:
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var Form1: TForm1;
implementation
{$R *.DFM} {$R MyStrings.res}
procedure TForm1.Button1Click(Sender: TObject);
var Buffer : Array[0..255] Of Char;
begin
LoadString(hInstance, 1, @Buffer, 255);
Label1.Caption := StrPas(Buffer);
LoadString(hInstance, 2, @Buffer, 255);
Label2.Caption := StrPas(Buffer);
end;
//StrPas = Converts null-terminated string to a Pascal string.
end.