Thread: What am i doing wrong?

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22

    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,

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Last edited by matsp; 06-04-2009 at 06:28 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    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?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    UK
    Posts
    22
    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,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM