Board index » cppbuilder » Dynamically creating TImage

Dynamically creating TImage

I want to create an instance of a TImage object and fill them with a
picture at runtime.
I think, that this must work and should not be a problem. But when I
code this simple action, my surface shows no image.

Image = new TImage(Owner);
Image->LoadFromFile("Picture1.bmp");
Image->Repaint();

If I use a TImage component at design time and load the picture at
runtime, it works.
But I can't believe, that it doesn't work with creating an intance at
runtime.
Have anybody an idea, what's wrong?

Thanks
Didi

 

Re:Dynamically creating TImage


Quote
On Thu, 14 Nov 2002 22:47:33 +0100, IDAKO GmbH wrote:
>I want to create an instance of a TImage object and fill them with a
>picture at runtime.
>I think, that this must work and should not be a problem. But when I
>code this simple action, my surface shows no image.

>Image = new TImage(Owner);
>Image->LoadFromFile("Picture1.bmp");
>Image->Repaint();

>If I use a TImage component at design time and load the picture at
>runtime, it works.
>But I can't believe, that it doesn't work with creating an intance at
>runtime.
>Have anybody an idea, what's wrong?

You need to give the control a parent, and set its position.

--
 - Mike

Remove 'spambegone.net' and reverse to send e-mail.

Re:Dynamically creating TImage


The Image Needs a Parent.

  Image->Parent = this;// or any other Parent.

The Parent is the component where the Image should be placed.

Hans.

Quote
IDAKO GmbH wrote:

> I want to create an instance of a TImage object and fill them with a
> picture at runtime.
> I think, that this must work and should not be a problem. But when I
> code this simple action, my surface shows no image.

Re:Dynamically creating TImage


In article <3DDF7088.FDD12...@idako.de>, i...@idako.de says...

Quote
> Ok! That' s right! I thought, the Parent is given with the parameter
> "Owner" in the
> constructor. No when I set the Parent to "this", the Image is shown.

The Owner is responsible for the deletion of your control. Parent and
Owner are two different thing.
Michel
--
-------------------------------
Michel Leunen
http://www.leunen.com/cbuilder/
-------------------------------

Re:Dynamically creating TImage


Nope.  The Owner and the Parent are not the same thing.  The Owner handles
memory management.  The Parent manages onscreen visibility and placement.

Gambit

Quote
"IDAKO GmbH" <i...@idako.de> wrote in message

news:3DDF7088.FDD12373@idako.de...
Quote
> I thought, the Parent is given with the parameter "Owner"
> in the constructor.

Other Threads