Вывести информацию о пакете
Автор: Xavier Pacheco
program PkgInfo;
uses
Forms,
Dialogs,
SysUtils,
PkgMain in 'PkgMain.pas' {PackInfoForm};
{$R *.RES}
var
OpenDialog: TOpenDialog;
begin
if (ParamCount > 0) and FileExists(ParamStr(1)) then
PkgName := ParamStr(1)
else
begin
OpenDialog := TOpenDialog.Create(Application);
OpenDialog.DefaultExt := '*.bpl';
OpenDialog.Filter := 'Packages (*.bpl)|*.bpl|Delphi 3 Packages ' +
'(*.dpl)|*.dpl';
if OpenDialog.Execute then
PkgName := OpenDialog.FileName;
end;
if PkgName <> '' then
begin
Application.Initialize;
Application.CreateForm(TPackInfoForm, PackInfoForm);
Application.Run;
end;
end.
unit PkgMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TPackInfoForm = class(TForm)
GroupBox1: TGroupBox;
DsgnPkg: TCheckBox;
RunPkg: TCheckBox;
BuildCtl: TRadioGroup;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Button1: TButton;
Label1: TLabel;
DescEd: TEdit;
memContains: TMemo;
memRequires: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
end;
var
PackInfoForm: TPackInfoForm;
PkgName: string; // This is assigned in project file
implementation
{$R *.DFM}
procedure PackageInfoCallback(const Name: string; NameType: TNameType;
Flags: Byte; Param: Pointer);
var
AddName: string;
Memo: TMemo;
begin
Assert(Param <> nil);
AddName := Name;
case NameType of
ntContainsUnit: Memo := TPackInfoForm(Param).memContains;
ntRequiresPackage: Memo := TPackInfoForm(Param).memRequires;
else
Memo := nil;
end;
if (Memo <> nil) then
begin
if Memo.Text <> '' then
AddName := ', ' + AddName;
Memo.Text := Memo.Text + AddName;
end;
end;
procedure TPackInfoForm.FormCreate(Sender: TObject);
var
PackMod: HMODULE;
Flags: Integer;
begin
// Since we only need to get into the package's resources,
// LoadLibraryEx with LOAD_LIBRARY_AS_DATAFILE provides a speed-
// efficient means for loading the package.
PackMod := LoadLibraryEx(PChar(PkgName), 0, LOAD_LIBRARY_AS_DATAFILE);
if PackMod = 0 then
Exit;
try
GetPackageInfo(PackMod, Pointer(Self), Flags, PackageInfoCallback);
finally
FreeLibrary(PackMod);
end;
Caption := 'Package Info: ' + ExtractFileName(PkgName);
DsgnPkg.Checked := Flags and pfDesignOnly <> 0;
RunPkg.Checked := Flags and pfRunOnly <> 0;
if Flags and pfNeverBuild <> 0 then
BuildCtl.ItemIndex := 1;
DescEd.Text := GetPackageDescription(PChar(PkgName));
end;
procedure TPackInfoForm.Button1Click(Sender: TObject);
begin
Close;
end;
end.
|