在Delphi中如何使用RC文件中的字符串表

类别:Delphi 点击:0 评论:0 推荐:
在Delphi中如何使用RC文件中的字符串表 

原作作者:wangzhidong(Steven Bob)

时间:2002年3月25日星期一 

首先用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位格式的差异。

实例下载:http://www.megspace.com/computers/coreware/

本文地址:http://com.8s8s.com/it/it5604.htm