tags:

views:

185

answers:

4

How may I test in coding if my .exe Delphi application is built with runtime package or is single .exe?

A: 

Did you try "Islibrary" ?

Marco van de Voort
Tried. It doesn't work. Both packaged and non-packaged .exe application return False.
Chau Chee Yang
An EXE is never a library.
Oliver Giesen
+1  A: 

Use could use the EnumModules() procedure, like so:

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;
mghie
+5  A: 

Another possibility:

function UsesRuntimePackages: Boolean;
begin
  Result := FindClassHInstance(TObject) <> HInstance;
end;
TOndrej
+1  A: 

Another possibility, in case you need this for an external executable (without running it):

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;
TOndrej