在Delphi中,您可以声明要存储在模块资源部分的String Table中的字符串.
resourcestring
rsExample = 'Example';
Run Code Online (Sandbox Code Playgroud)
在编译时,Delphi将为其分配一个ID并将其存储在String表中.
有没有办法检索声明为resourcestring的字符串的ID?
原因是我使用的包与gnugettext一样.System.pas中的某些函数(如LoadResString)被挂钩,因此当我在表达式中使用resourcestring时,它将被替换为不同的字符串(转换).当然,这非常方便,但有时我需要资源字符串的原始(未翻译)文本.
当我能够检索字符串的资源ID时,我可以调用LoadString API来获取原始文本,而不是翻译文本.
为了帮助我们模块化单片应用程序,我们正在设置用于调试版本的包,同时仍然编译为发布版本的单个exe.
我们的一个包(EAUtils)包含一个正在生产的单元[DCC Error] E2201 Need imported data reference ($G) to access 'SMsgDlgWarning' from unit 'SystemUtils'.
在构建EAUtils包本身时会发生这种情况.我还没有构建依赖于EAUtils的包.EAUtils仅依赖于rtl/vcl包和我为Jedi WinApi单元创建的包.
这是行的结果:
// This is a TaskDialog override, with the same args as the old MessageDlg.
function TaskDialog(const aContent: string; const Icon: HICON = 0;
const Buttons: TTaskDialogCommonButtonFlags = TDCBF_OK_BUTTON): Integer;
const
Captions: array[TMsgDlgType] of Pointer = (@SMsgDlgWarning, @SMsgDlgError, @SMsgDlgInformation, @SMsgDlgConfirm, nil);
var
aMsgDlgType: TMsgDlgType;
aTitle: string;
begin
aMsgDlgType := TaskDialogIconToMsgDlgType(Icon);
if aMsgDlgType <> mtCustom then
aTitle := LoadResString(Captions[aMsgDlgType])
else
aTitle := …Run Code Online (Sandbox Code Playgroud) 我正在尝试为资源字符串设置Tab char,如下所示
const
Tab : string = Chr( 9 );
resourcestring
xmlversion = Tab + '<?xml version="1.0" encoding="utf-8" ?>';
codetemplate = Chr( 9 ) + '<codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0">';
Run Code Online (Sandbox Code Playgroud)
第一个resourcestring不起作用.编译器返回'E2026期望的常量表达式'.
第二行代码编译正常.它只是一个与Tab相同的代码.
供参考 - 以下是我的代码,我在NewLoadResString函数中得到StackOverflow异常.这个案例就像我已经创建了两个stringlist,即RecStrNameIdMap和NewStringValueList.这里RecStrNameIdMap是用于存储名称和字符串标识符映射的哈希字符串列表.这样我就可以为其标识符(即ID)引用资源字符串名称.
NewStringValueList是一个字符串列表,其中包含少数Resourcestrings的新值.
我已经在system.LoadResString方法上连接了NewLoadResString方法.在新方法中,我正在检查我是否在NewStringValueList中为给定的resourcestring提供了新值,然后获取该值并返回new而不是旧的声明值.
堆栈溢出异常发生在行*
如果RecStrNameIdMap.IndexOfName(IntToStr(ResStringRec ^ .Identifier))> -1则
*任何人都可以请检查我收到此错误的原因.
unit UnitTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TMethodHook = class
private
aOriginal : packed array[ 0..4 ] of byte;
pOldProc, pNewProc : pointer;
pPosition : PByteArray;
public
constructor Create( pOldProc, pNewProc : pointer );
destructor Destroy; override;
end;
var
Form2: …Run Code Online (Sandbox Code Playgroud)