Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: A class named TUniMenuItem already exists with BPL!


This question is answered.


Permlink Replies: 11 - Last Post: May 19, 2017 3:48 PM Last Post By: Ahmed Sayed Threads: [ Previous | Next ]
Ahmed Sayed

Posts: 171
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: 8,950
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: 171
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: 563
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
Ahmed Sayed

Posts: 171
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 21, 2017 12:45 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I posted about this issue on Unigui forum and Admin replied
that "I could observe some incompatible layers in uniGUI core library"

But i didn't understand what layers he was talking about.
Here's the link:

http://forums.unigui.com/index.php?/topic/7959-a-class-named-tunimenuitem-already-exists/

--
The limits of my language mean the limits of my world
Farshad Mohajeri

Posts: 118
Registered: 12/28/06
Re: A class named TUniMenuItem already exists with BPL!
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2017 11:30 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed Sayed wrote:
I posted about this issue on Unigui forum and Admin replied
that "I could observe some incompatible layers in uniGUI core library"

But i didn't understand what layers he was talking about.
Here's the link:

http://forums.unigui.com/index.php?/topic/7959-a-class-named-tunimenuitem-already-exists/

Today, I was investigating your problem which you have reported to us. I could identify your problem. Actually, it is not related to "incompatible layers in uniGUI".

Here is the issue:
When you create a new CPP uniGUI app, not all uniGUI runtime packages are added by default to the "Runtime Package Import libraries".

For example for XE5 list of uniGUI Runtime Packages are:

uniTools19
uIndy19
uniGUI19Core
uniGUI19
uniGUI19Chart
uniGUI19m

You must make sure all of these packages are in the package list and they are dynamically linked with your application. Otherwise, your app will be statically compiled with some of uniGUI libraries while your custom BPL will try loading same packages dynamically.
That's why you get the error message: "A class named TUniMenuItem already exists". It shows that same class is being registered more than once, in different instances of same library. If you link your app statically with uniGUI19Core and your BPL tries to load it dynamically then two instances of uniGUICore will be instantiated which is cause of this error.
Farshad Mohajeri

Posts: 118
Registered: 12/28/06
Re: A class named TUniMenuItem already exists with BPL!
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2017 11:43 AM   in response to: Farshad Mohajeri in response to: Farshad Mohajeri
Farshad Mohajeri wrote:

For example for XE5 list of uniGUI Runtime Packages are:

uniTools19
uIndy19
uniGUI19Core
uniGUI19
uniGUI19Chart
uniGUI19m

Let me emphasis, above packages must be added to both host app and custom BPL, so they will share same libraries at runtime.
Farshad Mohajeri

Posts: 118
Registered: 12/28/06
Re: A class named TUniMenuItem already exists with BPL!
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2017 10:44 PM   in response to: Farshad Mohajeri in response to: Farshad Mohajeri
Farshad Mohajeri wrote:
Farshad Mohajeri wrote:

For example for XE5 list of uniGUI Runtime Packages are:

uniTools19
uIndy19
uniGUI19Core
uniGUI19
uniGUI19Chart
uniGUI19m
Also this one:

uniGUI19mCore
Ahmed Sayed

Posts: 171
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 27, 2017 4:12 AM   in response to: Farshad Mohajeri in response to: Farshad Mohajeri
Shouldn't these packages be included automatically
whenever I use UniGui Apps like other frameworks?
Is it an IDE, C++ Builder or framework problem?

--
The limits of my language mean the limits of my world
Farshad Mohajeri

Posts: 118
Registered: 12/28/06
Re: A class named TUniMenuItem already exists with BPL!  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2017 9:59 AM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed Sayed wrote:
Shouldn't these packages be included automatically
whenever I use UniGui Apps like other frameworks?
Is it an IDE, C++ Builder or framework problem?

--

I will investigate it, but until then they must be included manually if not added by the IDE.
Ahmed Sayed

Posts: 171
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: May 19, 2017 3:48 PM   in response to: Farshad Mohajeri in response to: Farshad Mohajeri
Any news about fixing this issue? Is it fixed in last release or not?

--
The limits of my language mean the limits of my world
Ahmed Sayed

Posts: 171
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 26, 2017 1:49 PM   in response to: Farshad Mohajeri in response to: Farshad Mohajeri
Thanks for your support

--
The limits of my language mean the limits of my world
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02