0

I recently made some minor changes within my c++-builder-project-settings to distribute a built application, however now some kind of initialisation seems to be missing.

Before I was using this (worked properly):

TPngImage *img=new TPngImage;
img->LoadFromFile(pfad);
Image1->Picture->Assign(img);

However, suddenly I get the error: access-violation... access to 0x0000000. I checked and noticed that Image1->Picture is Null. Image1 is of course a TImage-Object added per designer. I'm using embarcaderos XE2 16 c++-Builder.

Is there a setting for this or could you tell me, what I have to do? I thought of Image1->Picture=new TPicture(); already, but that is also Null...

Kromster
  • 7,181
  • 7
  • 63
  • 111
Julian
  • 493
  • 4
  • 22
  • 2
    Where is `Image1` initialized? If at all ? – FailedDev Aug 16 '12 at 22:57
  • @FailedDev Well, I used the c++-builder-designer, so I thought it would be automatically initialized somewhere... Well, within my .h-file there is an Entry __published: ... TImage *Image1;... but that's more like a declaration... – Julian Aug 16 '12 at 23:01
  • Well you'll have to find the missing code part where `Image` is defined and post that. Also I have never heard of `embarcaderos XE2 16 c++-Builder` so I can't really suggest anything. Edit: yes that's your problem. You have a pointer which is not initialized to anything usefeul :) – FailedDev Aug 16 '12 at 23:03
  • @FailedDev well, it automatically makes some code... like class TForm1:public TForm{__published: TImage *Image1;}... the design-file, dfm, only contains general properties in its own style: object Image1:TImage Left=19 Top=215 ... end... So, in normal case there isn't anywhere a normal define-phrase... Even when I try to create a new TImage the Picture-member is Null... is that normal? – Julian Aug 16 '12 at 23:14
  • At the time you try to access `Image1->Picture`, is `Image1` also `NULL`? `Picture` is intialized in the `TImage` constructor, so that suggests the `TImage` itself is not being constructed correctly. – Remy Lebeau Aug 16 '12 at 23:16
  • No, it is not normal for the `Picture` property to ever be `NULL`. – Remy Lebeau Aug 16 '12 at 23:16
  • And you cannot do `Image1->Picture = new TPicture` because that will just invoke the `Picture` property setter, which makes a copy of the source `TPicture`, and so you would just leak `TPicture` object that you `new`'ed. – Remy Lebeau Aug 16 '12 at 23:17
  • @RemyLebeau Well, Image1 is not Null... I think I may have deleted some important include or set something in the settings accidentally... – Julian Aug 16 '12 at 23:20
  • Do you have multiple IDE versions installed? There is nothing in the includes or settings that would normally cause this, which makes me think that maybe your project is linking to the wrong VCL libraries. – Remy Lebeau Aug 16 '12 at 23:29
  • @RemyLebeau No... I have only one installed and also only one vcl.h on my computer. I created another project, added a TImage-Object there and copied the code to it and everything works there... so I think I messed up the settings... I don't seem to have some includes left out, so I think it is the settings... of course I have tons of additional includes. I hope they don't mess with it... – Julian Aug 16 '12 at 23:33
  • well, I exported the settings of a new project and replaced my current with it and everything seems to work now again... – Julian Aug 17 '12 at 00:02

1 Answers1

0

It seems that it was my settings...
Somehow I messed some setting up.

I exported the settings of a new project, copied my include-paths, overwrote the settings with the exported one and inserted the includes.

Now everything works again.

Julian
  • 493
  • 4
  • 22