1

resourcestringセクションにがあるユニットがありますimplementationresourcestringの識別子を別のユニットで取得するにはどうすればよいですか?

unit Unit2;

interface

implementation

resourcestring
  SampleStr = 'Sample';

end.

interfaceセクションで利用できる場合は、次のように記述できます。

PResStringRec(@SampleStr).Identifier
4

1 に答える 1

4

ユニットのimplementationセクションで宣言されたものはすべて、ユニットに対してプライベートです。別のユニットから直接アクセスすることはできません。したがって、次のいずれかを行う必要があります。

  1. resourcestringを次のinterfaceセクションに移動します。

    unit Unit2;
    
    interface
    
    resourcestring
      SampleStr = 'Sample';
    
    implementation
    
    end.
    

    uses
      Unit2;
    
    ID := PResStringRec(@Unit2.SampleStr).Identifier;
    
  2. をセクションに残し、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;
    
于 2015-03-19T00:57:30.833 に答える