Delphi 如何测试应用程序(.exe)是否使用运行时包生成

Delphi 如何测试应用程序(.exe)是否使用运行时包生成,delphi,Delphi,如果我的.exe Delphi应用程序是使用运行时软件包构建的,或者是单个.exe,我如何在编码中进行测试?您是否尝试过“Islibrary”?使用可以使用EnumModules()过程,如下所示: function EnumModuleProc(HInstance: Integer; Data: Pointer): Boolean; begin Result := True; if HInstance <> MainInstance then begin Inc(P

如果我的.exe Delphi应用程序是使用运行时软件包构建的,或者是单个.exe,我如何在编码中进行测试?

您是否尝试过“Islibrary”?

使用可以使用
EnumModules()
过程,如下所示:

function EnumModuleProc(HInstance: Integer; Data: Pointer): Boolean;
begin
  Result := True;
  if HInstance <> MainInstance then begin
    Inc(PInteger(Data)^);
    Result := False;
  end;
end;

function UsesRuntimePackages: boolean;
var
  PckgCount: integer;
begin
  PckgCount := 0;
  EnumModules(EnumModuleProc, @PckgCount);
  Result := PckgCount > 0;
end;
函数EnumModuleProc(HInstance:Integer;Data:Pointer):布尔;
开始
结果:=真;
如果是实例,则开始
公司(PInteger(数据)^);
结果:=假;
结束;
结束;
函数UsesRuntimePackages:布尔值;
变量
PckgCount:整数;
开始
PckgCount:=0;
EnumModules(EnumModuleProc,@PckgCount);
结果:=PckgCount>0;
结束;
另一种可能性:

function UsesRuntimePackages: Boolean;
begin
  Result := FindClassHInstance(TObject) <> HInstance;
end;
函数UsesRuntimePackages:Boolean;
开始
结果:=FindClassHInstance(TObject)HInstance;
结束;

另一种可能性,如果您需要将其用于外部可执行文件(不运行它):


尝试它不起作用。打包和非打包的.exe应用程序都返回False。
procedure InfoProc(const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
begin
  case NameType of
    ntContainsUnit:
      if Name = 'System' then
        PBoolean(Param)^ := False;
  end;
end;

function UsesRuntimePackages(const ExeName: TFileName): Boolean;
var
  Module: HMODULE;
  Flags: Integer;
begin
  Result := True;

  Module := LoadLibraryEx(PChar(ExeName), 0, LOAD_LIBRARY_AS_DATAFILE);
  try
    Flags := 0;
    GetPackageInfo(Module, @Result, Flags, InfoProc);
  finally
    FreeLibrary(Module);
  end;
end;