Thread: Creating Images in Borland C++ 6

  1. #1
    stovellp
    Guest

    Creating Images in Borland C++ 6

    Gidday

    I'm using borland CBuilder 6 on windows 2000 and I want to create an array of Images, the same as the VCL TImage.

    It lets me create an array of TImages, but It wont let me write

    Code:
    TImage * MyImages[10];
    
    MyImages[0] = new TImage;
    because TImage has no default constructor (which I found a bit strange, as I though all classes have constructors as default).

    Any Ideas how I could get around this?

    Paul

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You could derive a class from TImage and give it a default constructor. Then you can make an array of instances of it rather than of TImage.

    EDIT: Didn't notice you were dynamically allocating. You shouldn't have a problem -- see later reply...
    Last edited by Polymorphic OOP; 01-23-2003 at 03:19 AM.

  3. #3
    stovellp
    Guest
    Thanks mate! I never thought of that. Thanks very much.

  4. #4
    stovellp
    Guest
    Sorry, I just tried it. It wont compile because theres no Constructor for TImage. This is what I have:

    Code:
    // PImage is the name of my derived class
    PImage * myImages[10];
    
    myImages[0] = new PImage;
    Error: Could not find constructor for base class TImage...

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    There has to be at least 1 constructor otherwise you wouldn't be able to make instances of the class at all.

    How do you normally go about making an instance the TImage class?

  6. #6
    stovellp
    Guest
    Normally I just click "Image" and drag it where I want it on the form, the IDE takes care of all the code stuff as far as creating objects goes.

    When the IDE creates a TImage, it writes "TImage * Image1" or whatever you chose to call it, into te header file. Then (I think) it creates data files that hold info about the object. Trouble is, I can create instances of other object like TBitmap (Part of a TImage) just fine.

  7. #7
    stovellp
    Guest
    I just did a search through every file in the Include directory for "class TImage" and it couldn't find it.

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You're dynamically allocating, why don't you just call the constructor explicitly when you allocate each one? You shouldn't be having any problems. You shouldn't need to create a child class or anything (I only suggested this because I though you were making an array of objects, not pointers).
    Last edited by Polymorphic OOP; 01-23-2003 at 03:20 AM.

  9. #9
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You should be able to find information about the constructor somewhere. It has to be in the headers somewhere, you must've missed it. If you can't find it, I'm sure there's plenty of documentaiton you should be able to find. Are you sure it has a public constructor? Perhaps you're not supposed to have direct access to any of it's constructors.

    Don't search for "class TImage" because it might be a struct, union, or a typdef of one of them, etc.
    Last edited by Polymorphic OOP; 01-23-2003 at 03:06 AM.

  10. #10
    stovellp
    Guest
    Okay, so Instead on myImages[0] = new PImage, I have now got myImages[0]->PImage();

    Now It is telling me there is no such thing as PImage, and if even if i specify it, I get the same message I was getting earlier plus PImage() doesn't exist, WHEN I JUST DECLARED IT! lol.

  11. #11
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by stovellp
    Okay, so Instead on myImages[0] = new PImage, I have now got myImages[0]->PImage();

    Now It is telling me there is no such thing as PImage, and if even if i specify it, I get the same message I was getting earlier plus PImage() doesn't exist, WHEN I JUST DECLARED IT! lol.
    No, not like that. You can't call a constructor like that -- besides you still have to dynamcially allocate memory for it.

    You have to do something like:

    myImages[0] = new PImage( parameters go here );

    But I have a strong suspicion that you're working with TImage completely wrong. The constructors are probably not public functions. Look for documentation on that class and find out what its constructors are, or just use that "drag and drop" and then look at the corresponding code it creates.
    Last edited by Polymorphic OOP; 01-23-2003 at 03:24 AM.

  12. #12
    stovellp
    Guest
    Yeah, looks like I'll have too. I was hoping not to have to use the documentation because its soooo long. Thanks anyway mate, see ya next month when I've finished looking (and haven't solved it).

  13. #13
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    To create a TImage at runtime, do the following:

    Code:
    TImage *img = new TImage(NULL);
    It's only contructor accepts TComponent pointer to hold as reference of the object responsible for destroying the TImage. You can pass it NULL(0) if you like. I wouldn't bother deriving a class from TImage for what you want to do.

    Because you have created a TImage instance yourself at runtime, don't forget to destroy it - it won't be destroyed automatically like components dragged onto the form in the IDE.

    If you want your TImage object to be shown, you need to attach it to a parent window, like so:

    Code:
    img->Parent = Form1;
    That's all there is to it. However, if you just want to hold an array of bitmaps, you could use TBitmap instead of TImage. A bitmap can be copied into an TImage component at anytime using:

    Code:
    Image1->Picture->Assign( bmp );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating images with c++
    By pastitprogram in forum C++ Programming
    Replies: 1
    Last Post: 08-03-2008, 07:43 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Onclick Event(), On creating Images Componnets
    By Leite33 in forum Windows Programming
    Replies: 0
    Last Post: 10-09-2006, 03:16 PM
  4. CBitmap + big images = bad?
    By dug in forum Windows Programming
    Replies: 18
    Last Post: 06-28-2003, 11:53 PM
  5. Creating a VCD to Show Images
    By Davros in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2003, 04:02 PM