Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of loaded run time packages?

I'm creating a "Version Info" dialog box for my applications; something similar to the one Delphi has in the "About" dialog box. I'd like to display the version information only for the run time packages (.BPL files), and not all the loaded DLLs. Does the RTL include functions to get a list of the loaded packages, or I have to use the EnumProcessModules function and filter the result?

Thanks in advance...

like image 640
iMan Biglari Avatar asked Feb 11 '13 12:02

iMan Biglari


1 Answers

You can use the EnumModules function from System.

Here's a very simple demonstration of how to use the EnumModules function and get the names of all the loaded BPL's. It's a console application, but the code can be easily reused in a production application. If you want to test it out, make sure you're using packages:

program Project17;

{$APPTYPE CONSOLE}

uses
  SysUtils, Classes, Windows;

function EnumModulesFunc(HInstance: Integer; Data: Pointer): Boolean;
var Buff:array[0..1023] of char;
begin
  if GetModuleFileName(HInstance, @Buff, SizeOf(Buff)) = ERROR_INSUFFICIENT_BUFFER then
    Buff[High(Buff)] := #0;
  TStringList(Data).Add(Buff);
end;

var L: TStringList;

begin
  try
    L := TStringList.Create;
    try
      System.EnumModules(EnumModulesFunc, L);
      WriteLn(L.Text);
    finally L.Free;
    end;
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
like image 89
Cosmin Prund Avatar answered Nov 17 '22 10:11

Cosmin Prund