我有一个单元,resourcestring它的implementation部分中有一个。如何resourcestring在另一个单元中获取 ' 标识符?
unit Unit2;
interface
implementation
resourcestring
SampleStr = 'Sample';
end.
如果它在该interface部分中可用,我可以这样写:
PResStringRec(@SampleStr).Identifier
我有一个单元,resourcestring它的implementation部分中有一个。如何resourcestring在另一个单元中获取 ' 标识符?
unit Unit2;
interface
implementation
resourcestring
SampleStr = 'Sample';
end.
如果它在该interface部分中可用,我可以这样写:
PResStringRec(@SampleStr).Identifier
implementation在单元部分中声明的任何内容都是该单元私有的。它不能直接从另一个单元访问。因此,您将不得不:
将 移至resourcestring该interface部分:
unit Unit2;
interface
resourcestring
SampleStr = 'Sample';
implementation
end.
uses
Unit2;
ID := PResStringRec(@Unit2.SampleStr).Identifier;
将 留resourcestring在implementation节中,并在节中声明一个函数interface以返回标识符:
unit Unit2;
interface
function GetSampleStrResID: Integer;
implementation
resourcestring
SampleStr = 'Sample';
function GetSampleStrResID: Integer;
begin
Result := PResStringRec(@SampleStr).Identifier;
end;
end.
uses
Unit2;
ID := GetSampleStrResID;