How to use a string table in the RC file in Delphi

zhaozj2021-02-16  44

How to use a string table in the RC file in Delphi

Original Author: wangzhidong (Steven Bob)

Time: Monday, March 25, 2002

First build RC files with NotePad or Resource Workshop 4.5.

Structure is as follows

/ ************************************************** ************************* 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."}

Then use Brcc.exe or Brcc32.exe to compile rcdemo.rc into rcdemo.Res files, then rename RcDemo.Res

For the rcdemo.rc file. If you use Resource Workshop 4.5, a PAS unit file is generated. This example is UrcDemo.Pas.

The content is as follows:

(********************************************************* ************************* URCDEMO.PAS Produced by Borland Resource Workshop **************** *********************************************************** ************) Unit urcdemo; interface

Const

IDS_HELLO = 2; IDS_RC = 1; Implementation

End.

Using this technology, you can realize the localization of string problem storage issues and programs in error handling.

example:

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 Urcdemo; {$ r rcdemo.r}

{$ 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; {} function using native Delphi procedure TForm1.Button3Click (Sender: TObject); begin ShowMessage (LoadStr (IDS_Hello)); end; procedure TForm1.Button4Click (Sender: TObject); begin ShowMessage (LoadStr (IDS_RC)); end; end.

Note: 16-bit formats in 32-bit formats.

Example Download: http://www.megspace.com/computers/coreware/

转载请注明原文地址:https://www.9cbs.com/read-27754.html

New Post(0)