Welcome, Guest
Guest Settings
Help

Thread: A class named TUniMenuItem already exists with BPL!


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Feb 18, 2017 8:11 PM Last Post By: Alex Belo Threads: [ Previous | Next ]
Ahmed Sayed

Posts: 132
Registered: 8/9/07
A class named TUniMenuItem already exists with BPL!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2017 3:40 AM
Hi all,

I don't know if this is an IDE bug or what?
I have been trying to load a Form from a dll or BPL to be created dynamically by user.
I have both projects host and package linked with run-time packages so every thing should work just fine. But it is not i get the error in the subject when I only load the package file in the main form constructor. I tried doing the same thing with VCL and Intraweb and they worked fine.

My code is below:

Host App Main Form Header:

//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <uniGUIForm.hpp>
#include "uniButton.hpp"
#include "uniGUIBaseClasses.hpp"
#include "uniGUIClasses.hpp"
#include "uniPanel.hpp"
#include "uniCheckBox.hpp"
#include "uniComboBox.hpp"
#include "uniEdit.hpp"
#include "uniMemo.hpp"
#include "uniMultiItem.hpp"
#include "uniRadioButton.hpp"
//---------------------------------------------------------------------------
typedef void (*__declspec(dllimport) __stdcall TExecuteForm)(TUniGUIMainModule *Owner);
//---------------------------------------------------------------------------
class TMainForm : public TUniForm
{
__published: // IDE-managed Components
TUniButton *UniButton1;
TUniButton *UniButton2;
TUniCheckBox *UniCheckBox1;
TUniRadioButton *UniRadioButton1;
TUniComboBox *UniComboBox1;
TUniEdit *UniEdit1;
TUniButton *UniButton3;
TUniMemo *UniMemo1;
void __fastcall UniButton1Click(TObject *Sender);
void __fastcall UniFormDestroy(TObject *Sender);
private: // User declarations
HMODULE Package;
TExecuteForm ExecuteForm;
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
TMainForm *MainForm(void);
//---------------------------------------------------------------------------
#endif


Host App Main Form Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <UniGUIVars.hpp>
#include <UniGUIRegClasses.hpp>
#pragma hdrstop
 
#include "Main.h"
#include "MainModule.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "uniButton"
#pragma link "uniGUIBaseClasses"
#pragma link "uniGUIClasses"
#pragma link "uniPanel"
#pragma link "uniCheckBox"
#pragma link "uniComboBox"
#pragma link "uniEdit"
#pragma link "uniMemo"
#pragma link "uniMultiItem"
#pragma link "uniRadioButton"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
TMainForm *MainForm(void)
{
   return( (TMainForm *)UniMainModule()->GetFormInstance(__classid(TMainForm)));
}
//---------------------------------------------------------------------------
void T5C53000F51AF494C885E366C84DB5F46__RegisterFormClass() {
  Uniguivars::RegisterAppFormClass(__classid(TMainForm));
  Uniguiregclasses::CPPInit();
}
//---------------------------------------------------------------------------
#pragma startup T5C53000F51AF494C885E366C84DB5F46__RegisterFormClass
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TUniForm(Owner)
{
if ( ParamCount() > 0)
{
Package = reinterpret_cast<HMODULE>(LoadPackage(ParamStr(1)));
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UniButton1Click(TObject *Sender)
{
if (Package)
{
ExecuteForm = (TExecuteForm)GetProcAddress(Package, "ExecuteForm");
 
if (ExecuteForm == NULL)
throw Exception("function ExecuteForm not found");
 
ExecuteForm(UniMainModule());
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UniFormDestroy(TObject *Sender)
{
if (Package)
{
UnloadPackage(reinterpret_cast<unsigned>(Package));
Package = 0;
}
}
//---------------------------------------------------------------------------

BPL Package Form Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
 
#include "UniFormBPL.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "uniButton"
#pragma link "uniCheckBox"
#pragma link "uniComboBox"
#pragma link "uniEdit"
#pragma link "uniGUIBaseClasses"
#pragma link "uniGUIClasses"
#pragma link "uniMemo"
#pragma link "uniRadioButton"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
__fastcall TUniBPLForm::TUniBPLForm(TComponent* Owner)
: TUniForm(Owner)
{
}
//---------------------------------------------------------------------------
extern "C" {
//---------------------------------------------------------------------------
#define DLLEXPORT __declspec(dllexport) __stdcall
 
void DLLEXPORT ExecuteForm(TUniGUIMainModule *Owner)
{
TUniBPLForm *Form = (TUniBPLForm*)Owner->GetFormInstance(__classid(TUniBPLForm), true);
 
//TUniBPLForm *Form = new TUniBPLForm(Owner->UniApplication);
try
{
Form->ShowModal();
}
__finally
{
    delete Form;
}
 
}
//---------------------------------------------------------------------------
}
//---------------------------------------------------------------------------
void RegForm()
{
RegisterClass(__classid(TUniBPLForm));
}
//---------------------------------------------------------------------------
void UnRegForm()
{
UnRegisterClass(__classid(TUniBPLForm));
}
//---------------------------------------------------------------------------
#pragma startup RegForm
#pragma exit UnRegForm


What am I doing wrong? Should i use a dll instead of packages BPL?
Also how can I make a package created in C++ builder
to add Bpi files automatically to the project in the requires section
without adding them one by one?

Any help will be appreciated

Regards;
--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 7,500
Registered: 12/23/01
Re: A class named TUniMenuItem already exists with BPL!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2017 4:56 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

I have both projects host and package linked with run-time packages
so every thing should work just fine.

In theory, but your error message would suggest otherwise. The error message
comes from the Classes.RegisterClass() function, and it means the name of
the specified class type is already registered but its class type doesn't
match the specified class type. IOW, they are using different RTTI, which
means they are coming from different modules insted of a shared module.
So, you clearly have duplicate copies of the TUniMenuItem class, whihc could
mean you are not linking to the Uni package correctly, or maybe the host/package
accidentally linked to the Uni source code instead of an existing package.

Should i use a dll instead of packages BPL?

Absolutely not. A BPL is the correct solution when runtime packages are
involved.

Also how can I make a package created in C++ builder to add Bpi
files automatically to the project in the requires section without
adding them one by one?

AFAIK, you cannot.

--
Remy Lebeau (TeamB)
Ahmed Sayed

Posts: 132
Registered: 8/9/07
Re: A class named TUniMenuItem already exists with BPL!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 18, 2017 7:30 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
How can i make sure that i am linking a package
correctly and to the BPL not its source. Actually,
I don't have the source I am still using the trial version
to whether the framework is good or not?

How can I investigate this even further? All i get in the call
stack is errors on ASM lines no Delphi. I tried enabling debug DCUs
but still nothing.

Just to make sure that i have done every thing right.

After i created my form in BPL. I add the following Bpi files
from Lib path in RAD studio 18.

vcl.bpi
rtl.bpi
uniGUI24.bpi
uniGUI24Core.bpi
uniTools24.bpi

Is there any other kind of files that needs to be added too
the package in order to work? Because the package compiles
just fine.

--
The limits of my language mean the limits of my world
Alex Belo

Posts: 452
Registered: 10/8/06
Re: A class named TUniMenuItem already exists with BPL!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 18, 2017 8:11 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed Sayed wrote:

How can I investigate this even further?

Try tdump (or even Dependency Walker) to get list of exported
functions/symbols.

--
Alex
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02