Thread: WHY, WHY, does this hate me?!

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    180

    Exclamation WHY, WHY, does this hate me?!

    Alright, this is my problem. (i'm using Borland C++ builder 6,windows XP)

    I have decleared my variables globaly.
    I have made a function that is passed a class and a TImage(both are global).

    It compiles, BUT when i click the button, it nukes.

    Here is the function code
    Code:
    void move_ship_left(Ship_1 *U_Ship, TImage *U_sprite)
    {
    int x1;
    int y1;
    
    //adds to the x,y values
    x1 = (U_Ship->x1) - 5;
    y1 = (U_Ship->y1) + 0;
    
    //sets up new x,y values
    U_Ship->x1 =x1;
    U_Ship->y1 =y1;
    Form1->Repaint();
    Form1->Canvas->Draw(x1,y1,U_sprite->Picture->Graphic ) ;
    
    }
    Here is the function call

    Code:
     move_ship_left(User_Ship,Ship_sprite);
    here is the variable that's declared globally in another .h file
    Code:
    extern        Ship_1 *User_Ship;
    extern        TImage *Ship_sprite;
    Please help me! This is due for a project, and I NEED to fix it!

    thx for the help

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >extern Ship_1 *User_Ship;
    >extern TImage *Ship_sprite;
    Are there any real objects behind these pointers? Your description of the program "nuking" suggests a bad pointer reference. Also remember that extern says that the variables are defined elsewhere. This is good for a header file, but you also need to make sure that you define them somewhere before using them.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    class ship_1

    Code:
    class Ship_1
    {
    public:
            TImage *Ship_sprite(Owner);
            TRect *recSprite;
            int *health;
            int x1;
            int y1;
    
    };
    defining the stuff

    Code:
    //Creats new ship
    User_Ship = new Ship_1;
    Ship_sprite = new TImage(Owner);

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Here Owner is used as a type:

    public:
    TImage *Ship_sprite(Owner);

    but here Owner is used as an Object:

    Ship_sprite = new TImage(Owner);


    Owner can't be both a type and an object.

    Both rectSprite and health are left uninitialized in your code snippets. Was this intentional?

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    >>Both rectSprite and health are left uninitialized in your code snippets. Was this intentional?

    yup. Havn't gotten that far yet!

    I'm looking off a Pong example which is showing me how to do stuff. WTF is Owner anyways? And how would you reccomend I solve my problem?

    chers

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I've only done a minimal amount of work in Windows using BCB and that was several years ago. My recollection is that Owner stands for the object that owns the current method, in a way analagous to the this pointer that each object has. However, I'd suggest you go to the Windows section of this site or to bytamin-C.com (a site specializing in BCB) and ask your question about Owner there. You're much more likely to an answer at either one of those places than here, and it's much more likely to be accurate than mine.

    Good luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  2. Pet Peeves
    By Srg Pepper in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 10-03-2002, 11:34 AM
  3. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM
  4. Man, I really hate Microsoft...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 09-12-2001, 08:50 AM