-
What am i doing wrong?
Im creating a dll which can be called from java.
My program has no purpose at the moment im just trying to learn more about c++.
I have a simple Function. Which should display a form.
I didnt use a void so i know that it has been called file
Its called three because its my third function in the class.
The TForm2 class is the default code which the IDE has created.
Im using CodeGear C++ Builder.
Code:
extern "C" __declspec(dllexport) JNIEXPORT int JNICALL Java_JNITest_three(JNIEnv *, jobject){
TForm2 tform1 = new TForm2(0); // line 41
tform1.Show();
return 3;}
My error is:
Code:
[BCC32 Error] File4.cpp(41): E2459 VCL style classes must be constructed using operator new
Anyhelp would be great thanks,
-
tform1 is not a pointer, so you either should make it so, or not use new.
This is fairly common when moving from Java to C++ - Java has a hybrid of "regular variable and reference", where C++ something is EITHER a pointer, a reference (which is similar to what Java has, but not the same) or a direct variable. The difference is where the memory of the actual object is.
- a pointer is a variable that contains the address of an object. In itself, the pointer only has enough space to store the address. Before it can be used, it must be assigned an address, either the constant NULL (or zero) to indicate that it's not pointing to anything, or allocated using new, or set to another existing object by using the address-of operator (&).
- a reference is a variable that REFERS to another variable. Internal representation is like a pointer, so the space of the reference itself is only big enough to hold the address of another object, but a reference MUST be assigned to another existing object when it is instantiated. Can NOT be NULL. [1]
- a direct variable represents in itself the storage for the object.
[1] It is often said that a reference can not be invalid. Whilst it is guaranteed that the instance of a reference is valid when the reference is created, it is POSSIBLE to come up with code where a reference is invalid at some later stage, for example, create an object using new, assign a reference from the object, and then delete the original object. Now the reference is not valid - but there is no way to determine that by looking at the reference itself.
--
Mats
-
ok thanks,
So it should be like this:
Code:
TForm2 *tform1 = new TForm2(0);
tform1->Show();
However this gives me 83 [ILINK32] errors.
The first 1 is:
Code:
[ILINK32 Error] Error: Unresolved external '__tpdsc__ Forms::TForm' referenced from ...\RAD STUDIO\PROJECTS\RELEASE\TFORM2.OBJ
Nearly all the errors are Unresolved external __fastcall.
Is this problem with my TForm2 class?
-
That linker error tells you that either you should have implemented those functions, or you haven't linked against some library that contains that code.
--
Mats
-
ahh thanks.
yea when i created the project i didnt tick a check box which said i was going to use VCL classes so it hadnt written in all the code.
thanks again,