How to use string table in RC file in Delphi
Original author: wangzhidong (Steven Bob) Time: Monday, March 25, 2002. First use Notepad or Resource workshop 4.5 to create the RC file. The structure is as follows
| /****************************************************** ***************************rcdemo.rcPRoduced by Borland Resource Workshop**************** *************************************************** ***********/#include "urcdemo.pas"STRINGTABLE {IDS_HELLO, "I am glad to see you."IDS_RC, "This programming is created by %s."} |
Then use BRCC.EXE or BRCC32.exe to compile rcdemo.rc into the rcdemo.res file, and then rename rcdemo.res to the rcdemo.rc file. If you use Resource workshop 4.5, a PAS unit file will be generated. In this case, the content of urcdemo.pas is as follows:
| (****************************************************** ***************************urcdemo.pasproduced by Borland Resource Workshop****************** *************************************************** ***********)unit urcdemo;interfaceconst IDS_HELLO = 2; IDS_RC = 1;implementationend. |
This technology can be used to solve string storage problems and program localization problems in error handling. example:
| unit ufmRCDemo;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) GroupBox1: TGroupBox; Button1: TButton; Button2: TButton; GroupBox2: TGroupBox; Button3: TButton ; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses urcdemo ;{$R rcdemo.rc}{$R *.dfm}{Use windows API}procedure TForm1.Button1Click(Sender: TObject);var arystr: array [0..255] of char;begin windows.LoadString(hInstance, IDS_RC, arystr, sizeof(arystr)); ShowMessage(arystr);end;procedure TForm1.Button2Click(Sender: TObject);var arystr: array [0..255] of char;begin windows.LoadString(hInstance, IDS_Hello, arystr, sizeof(arystr)); ShowMessage(arystr);end;{Use Delphi native function}procedure TForm1.Button3Click(Sender: TObject);begin ShowMessage(LoadStr(IDS_Hello)) ;end;procedure TForm1.Button4Click(Sender: TObject);begin ShowMessage(LoadStr(IDS_RC));end;end. |
Note: The difference between 16-bit format and 32-bit format. Instance download: http://www.megspace.com/computers/coreware/