首先用Notepad或Resource workshop 4.5建立RC文件。
結構如下
/****************************************************************************
rcdemo.rc
produced by Borland Resource Workshop
*****************************************************************************/
#include "urcdemo.pas"
STRINGTABLE
{
IDS_HELLO, "I am glad to see you."
IDS_RC, "This programming is created by %s."
}
然後用BRCC.EXE 或BRCC32.exe把rcdemo.rc編譯成rcdemo.res文件,接著把rcdemo.res改名
為rcdemo.rc文件。 如用Resource workshop 4.5會產生一個PAS單元文件,本例為urcdemo.pas
內容如下:
(****************************************************************************
urcdemo.pas
produced by Borland Resource Workshop
*****************************************************************************)
unit urcdemo;
interface
const
IDS_HELLO = 2;
IDS_RC = 1;
implementation
end.
利用此項技術可實現錯誤處理中字符串問題存儲問題和程序的本地化問題。
范例:
unit ufmRCDemo;
interface
uses
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;
implementation
uses urcdemo;
{$R rcdemo.rc}
{$R *.dfm}
{利用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;
{利用Delphi原生函數}
procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage(LoadStr(IDS_Hello));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage(LoadStr(IDS_RC));
end;
end.
注意:16位格式於32位格式的差異。