Can't load package %s error while installing a package - delphi

I'm testing on Delphi 2007 and my groupproject is composed by 2 packages.
PackageRun.bpl
It's marked as "runtime only" and contains a unit named "uMyTestRun.pas" in which is defined an empty TFrame descendant:
unit uMyTestRun;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TMyTest = class(TFrame)
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
PackageDes.bpl
It requires PackageRun.bpl, it's marked as "designtime only" and contains a unit named "uMyTestDes.pas" in which I wrote the following code:
unit uMyTestDes;
interface
uses
Classes,
uMyTestRun;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponents', [TMyTest]);
end;
end.
Output directories of both packages are in Library paths (Inside there are bpl, dcp and dcu).
Trying to install PackageDes.bpl (Component, Install Packages..., Add...), I'm getting the following error:
Can't load package C:\<...>\PackageDes.bpl. Impossibile trovare il
modulo specificato.
The last part of the message is in my OS's language, in english it should be something like "Can't find specified module". (My OS is Windows 10 Pro 64bit).
PackageDes.bpl is exactly in the same path shown in the error message (C:\<...>\PackageDes.bpl).
After some tests, I found that the error disappear by removing the following line from uMyTestDes.pas unit:
RegisterComponents('MyComponents', [TMyTest]);
Is there something wrong in my code/projects/environment?

Run Process Monitor from http://SysInternals.com and set the filters to intercept only file operations ( toolbar rightmost buttons ) of your Delphi IDE process (check the process name in TaskManager or shortcut properties (it is bds.exe for Delphi XE2), then add the filter similar to Include / Process Name / Ends With / bds.exe ).
Then clear the log in PM, switch to Delphi and try to load the package, then as soon as error pops up switch back to PM and stop capturing events. Try to do it fast as you can, for example do not waste your time closing error box.
Now you would get a trace of file I/O activity of Delphi loading the package of yours (and some other background activity noise - the faster you do the less noise there'd be). In that trace look for all the errors and see where and which package Delphi tries to find.
You can also try Microsoft Dependency Walker or similar tools to se if your Design-Time BPL has all the DLL-dependency tree resolvable. Personally I usually use Unreal/Total commander with FileInfo plugin or ntCore CFF Explorer.

Easy way to solve this issue is to add a post build action to your run time project:
copy "$(OUTPUTDIR)\$(OUTPUTFILENAME)" "$(BDSCOMMONDIR)\Bpl"
The command above copies your run time file to the default IDE Bpl location.

I had a similar issue. In my case I had the same library name in a different Delphi version BPL path. I found out the solution for my issue looking at the comments above, so this is only a reminder for basic things to check:
BPL path have to be included in your OS path variable;
Search for a BPL module with the same name in other OS path before the right one (mutiple Delphi version installations).

Try to change the register procedure to uMyTestRun unit.
unit UMyTestRun;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyTest = class(TFrame)
private
{ Private declarations }
public
{ Public declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponents', [TMyTest]);
end;
end.
Now, the package will install correctly.
Regards.

Related

'Property Align does not exist' when inheriting from TCustomControl

I have created a custom control inherited from TCustomControl and published the property Align of TControl. But, when I used this custom control in a C++Builder project, it raised the exception
Project Launcher.exe raised exception class EReadError with message 'Property Align does not exist'.
This is the code for the custom control.
unit GameListCtrl;
interface
uses
SysUtils, Classes, Controls;
type
TGameList = class(TCustomControl)
private
protected
procedure Paint; override;
public
{ Public declarations }
published
property Align default alLeft;
end;
implementation
{ TGameList }
procedure TGameList.Paint;
begin
inherited;
end;
end.
Often this kind of error occurs if the package was not properly rebuilt. Then you need to open the package project that includes the unit "GameListCtrl" an rebuild the package. Make sure to activate the option to let RAD Studio create the C++ Builder files.
If that doesn't help the linker maybe picks a wrong / old DCU or obj file. Search all your drives and delete all GameListCtrl.dcu and GameListCtrl.obj files that you can find. I use UltraSearch from JAM Software to quickly search my local drives, it is much faster than Windows Search as it works directly on the NTFS structures.
You may also try to switch to static linking for your project in the project options.

EFilererror exception in Delphi 7

I have registered the package TMS Unicode Component Pack in my Delphi 7 containing TNT components.
This package contains a class named TTntCustomComboBox which I use to create my own custom component named Combobox2 :
unit Combobox2;
interface
uses
Windows, Messages, Classes, Graphics, Controls, StdCtrls, ImgList, ActiveX, SysUtils, TntStdCtrls, TntWindows;
type
TCombobox2 = class(TTntCustomComboBox)
...
procedure Register;
begin
RegisterComponents('Standard', [TCombobox2]);
end;
...
I've added this component (TCombobox2) to the package dclusr.dpk.
Compiling dclusr.dpk works but installing the package raises an exception :
Registration procedure Combobox2.Register in package C:\program files\Delphi7\Projects\Bpl\dclusr.bpl raised an exception class EFilererror : A class named TTntCustomComboBox already exists
So, how do I fix that ?
Thanks for help.
The error message indicates that your package is trying to register a component that is already registered, namely TTntCustomComboBox.
It's not obvious from the details that you have provided why this would happen. One possible reason would be if you included the TNT components in your package instead of referencing that in your package's requires clause. Another possible reason would be if your Register function attempted to register TTntCustomComboBox. This could happen if your actual declaration of TCombobox2 was like so:
TCombobox2 = TTntCustomComboBox;
Put {$WEAKPACKAGEUNIT ON} after unit caption.

Delphi Xe2 Package x64

Let's admit, I create new package in Delphi Xe2. I keep under a name "My". I add a simple component "MyComponent". I compile, I receive file Bpl in C:\Users\Public\Documents\RAD Studio\9.0\Bpl\My.bpl.
I add a platform "Win x64".
I compile, I receive C:\Users\Public\Documents\RAD Studio\9.0\Bpl\Win64\My.bpl.
...\Bpl\Win64\My.bpl to establish as new package does not give, writes "is not windows x32 applications".
The first is established normally and on a palette the component appears "MyComponent".
If to bring to are mute the index of a mouse will appear hint where it will be written, that it x32-compatible.
And at native component Delphi - at all x32-64 compatible.
Together with a disk to Xe2 there is a free disk with Free and Tral components if to put therefrom for example OverByteIcs or Ip*Works, that at them at all components will be 32-64х compatibility.
Questions:
1. How to establish the x64 the version package?
2. How to achieve, that the component had a compatibility 32-64, and not just 32?
P.S. Bad English language: ON
The Delphi IDE is 32 bit and so can only load 32 bit designtime packages. You can of course create 64 bit runtime packages.
Has earned, has understood!
We create empty package
We add the component, for example Button and it is specified what platforms for a component (the key moment are necessary!)
Example
unit GuButton;
interface
uses
System. SysUtils, System. Classes, Vcl. Controls, Vcl. StdCtrls;
type
[ComponentPlatformsAttribute (pidWin32 or pidWin64)] // !!!!!!!!!!!!!!!
TButtonGu = class (TButton)
private
{Private declarations}
protected
{Protected declarations}
public
{Public declarations}
published
{Published declarations}
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents (' Gu ', [TButtonGu]);
end;
We keep, we compile under x32. We add a platform x64 (in options should be registered, that directories under platforms different).
We compile under x64. We receive 2 BPL (as in the first question). We establish x32. We look - new component ButtonGu - 32-64 compatible was added.
Here I that wanted, all thanks.
In addition http://docwiki.embarcadero.com/RADStudio/en/64-bit_Cross-Platform_Application_Development_for_Windows

Unable to open file 'STDCTRLS.OBJ'

First of all, sorry for my bad english.
I started with Delphi today, created a simple form example named test.
unit teste;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
end.
I searched at google, then here and did not find an answer for this problem, I´m not able to run it, because the logs return these errors:
[ILINK32 Error] Fatal: Unable to open file 'STDCTRLS.OBJ'
I had no idea how to fix it, could you help me?
Thanks!
best regard´s.
It looks like you've created a C++Builder project, but written/pasted in Delphi code. Delphi doesn't use ILINK at all, and it doesn't use STDCTRLS.OBJ (it would complain about StdCtrls.dcu instead).
Since you have no functional code in the project, I'd just start over. Use File|Close All, and don't save changes. Then use File|New|VCL Forms Application - Delphi for Win32, and hit F9 to see if you can run that project.
Make sure the IDE's search paths are configured correctly, and that the project has correct references to the RTL and VCL packages.

BPL File needs Run-Time Packages !

I have created a Package and i want to use the BPL File of my Package ...
My Package have VCL.dcp and RTL.dcp as Required libraries , i load this Package in my application without any errors but when i want to unload it , an Access Violation shown !
If i Build my Application with Run-Time Packages ( "vcl" and "rtl" ) , Access Violation not shown !
What is this mean ?! My Application need VCL and RTL Libraries to Load BPLs ?! I want to Load my Package like a DLL File , is there any solution ?
I`m using Delphi 2010
thanks a lot ...
Your BPL requires the RTL and VCL packages. If your Application doesn't require them, then that means the RTL and VCL units are compiled into your EXE file. When your EXE loads your BPL, you now have two copies of the RTL and VCL units — one set of copies comes from within the EXE, and the second copies come from the RTL and VCL packages that your package implicitly causes to be loaded.
Delphi isn't intended to accommodate that situation. It's possible that you have memory that was allocated by one RTL and attempted to get freed by the other RTL. Or there might be function pointers in the EXE that refer to functions that were in the VCL package.
I see three options for you:
Compile your EXE to use packages. Specifically, it should require the same RTL and VCL packages that your BPL requires.
Make your BPL not require any other packages. If it doesn't require RTL and VCL, then any RTL and VCL units that your package uses will get compiled into your BPL. You'll end up with two separate copies again, but it should work better since neither copy will think it's supposed to be shared.
Load your package like a real DLL instead of like a package. You said you wanted to use it like a DLL, so do that. Use LoadLibrary, and then use GetProcAddress to get whatever functions you want to call. If you go this route, it's probably better to not make your code be a package at all. Make it a DLL, and export functions that only use parameter types that you'd expect to find in other DLLs, like integers, character pointers, and record pointers, not strings or objects.
It should be clear that the first option is the easiest. The second could probably work, and it sounds like that's the way you'd prefer, but I expect it will generate more headaches before it finally works. The third option is best if you'll ever have to use other development environments during the lifetime of this project.
What have your package inside?
What work do you do with it?
How do you charge and discharge? What's in it?
What do you do with the package before unload it?
When you Unload it, all the objects/forms/components/... that yo've used is released?
ADDED: I Think that you are using anything of the package when you try to Onload. This is the reason of AV.
In an EXE compiled without runtime package, I load the package:
OutputDebugString(PChar('Loading the package'));
hand := LoadPackage('r:\rrrrrrr\Package1.bpl');
I Unload the package with this code:
OutputDebugString(PChar('Ready to Unload Package'));
UnloadPackage(hand);
OutputDebugString(PChar('Unloaded'));
The package has a unit with a form (form1) and a unit Init.pas, for initialization like this:
unit Init;
interface
// prototipos
procedure Start_P;
procedure Finish_P;
implementation
uses
Unit1, Windows;
procedure Finish_P();
begin
OutputDebugString(PChar('Finish_P form free'));
Form1.Free;
end;
procedure Start_P();
begin
OutputDebugString(PChar('Start_P Creating form'));
Form1 := TForm1.Create(nil);
Form1.Show;
end;
Initialization;
Start_P();
Finalization;
Finish_P();
end.
The package is loaded and the form visualized without problems, and the same with the operation of Close and Unload. The project is compiled with "Build with rutime packages" unchecked.
Can you post any code.
The result of OutputDebugString is this (no AV error):
[2644] Loading the package
[2644] Start_P Creating form
[2644] Ready to Unload Package
[2644] Finish_P form free
[2644] Unloaded
Regards.
Thanks for your helps ...
I put an example of my package and my Application here to Find what is the problem !
We have a package without requiring to Run-Time Packages like VCL and RTL , in other words i removed all libraries from the Requires section in my package :
my package contains a form with code below :
unit MyUnit;
interface
uses
Windows, Forms, StdCtrls, Buttons, Controls, Classes, Dialogs;
type
TMyForm = class(TForm)
MyLabel: TLabel;
MyEdit: TEdit;
PostBtn: TBitBtn;
procedure PostBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MyForm: TMyForm;
implementation
{$R *.dfm}
function ShowForm(FCaption, LCaption : String) : String;
var
F : TMyForm;
begin
F := TMyForm.Create(nil);
try
F.Caption := FCaption;
F.MyLabel.Caption := LCaption;
F.ShowModal;
finally
Result := F.MyEdit.Text;
F.Free;
end;
end;
procedure TMyForm.PostBtnClick(Sender: TObject);
begin
if MyEdit.Text <> '' then
Close
else
ShowMessage('Please Enter Value !');
end;
exports
ShowForm;
end.
I Load this Package and Call ShowForm Function and then Unload package :
var
ShowF : function(FCaption, LCaption : String) : String;
MyPkg : HMODULE;
FC, LC : String;
begin
MyPkg := LoadPackage(ExtractFilePath(Application.ExeName)+'MyPackage.bpl');
FC := 'Enter Value ... ';
LC := 'Value : ';
if MyPkg <> 0 then
begin
try
#ShowF := GetProcAddress(MyPkg, 'ShowForm');
if Assigned(ShowF) then
Edit1.Text := ShowF(FC, LC)
else
ShowMessage('Function not found !');
finally
UnloadPackage(MyPkg);
end;
end;
end;
After the Procedure above done , the AV Shows !
#Neftalí : If I just do loading and unloading the Package , no AV Shows , but i think that is because i don`t call some routines or objects or ... that they need VCL or RTL Libraries , if i use objects and functions and ... of this package , after using them i will get an AV ...
is it true ?!
If I Build my application with Run-Time package ( VCL and RTL ) no AV will shown !
I`m confusing !! , I want to use an BPL package without any Run-Time package needed ...
thanks a lot ...
Yes, if you want to use runtime packages in your application you have to build it with runtime packages, and then it requires them (links statically with them).
The solution to your problem depends on what the problem actually is (which is unclear at the moment).
Ohhhhh, great oversight/neglect (mine).
With the code that you have posted, made a simple change a test it (use PChar).
function ShowForm(FCaption, LCaption : String) : PChar;
...
Result := PChar(F.MyEdit.Text);
...
The same when you define the sitaxis of the function:
ShowF : function(FCaption, LCaption : String):PChar;
Test it and say the result.
Regards.

Resources