Witam. Chcę stworzyć klasę z obiektami, które będą zawierać obraz (Timage czy jest lepszy sposób?). Program kompiluje mi bez błędów, ale gdy klikam przycisk tworzący obiekt, to wyskakuje mi komunikat:
Access violation at address 50DBFCC in module 'vcl270.bpl'. Read of address 000001D8.
Pytanie 1: Jak sobie z tym poradzić?
Main.cpp:
#include <vcl.h>
#include <iostream>
#pragma hdrstop
#include "Main.h"
#include "Envi.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void __fastcall Startgame()
{
Envi Tree1("tree",100,100);
Tree1.Postaw();
}
void __fastcall TForm1::BOKClick(TObject *Sender)
{
Startgame();
}
Envi.cpp:
#include <Classes.hpp>
#include <vcl.h>
#include "Envi.h"
#include <Main.h>
Envi::Envi(AnsiString typ, int to, int le)
{
typek=typ;
tto=to;
lle=le;
}
Envi::~Envi()
{};
void __fastcall Envi::Postaw()
{
TImage *Image1;
if(typek=="tree")
{
Image1 -> Picture = Form1 -> Tree0 -> Picture;
}
Image1 -> Top = tto;
Image1 -> Left = lle;
}
Gdzie Tree0 jest częścią Main.h:
TImage *Tree0;
Pytanie 2: Czy w Envi.cpp linijkę:
Image1 -> Picture = Form1 -> Tree0 -> Picture;
zamienić na:
Image1 -> Picture ->LoadFromFile("source/drzewo.png");
i nie powoływać się na Tree0 (w zasadzie będzie niepotrzebny i można usunąć)?
Envi.h:
#include <Classes.hpp>
#include <Controls.hpp>
#include <vcl.h>
class Envi
{
public:
AnsiString typek;
int tto, lle;
Envi(AnsiString="tree", int=0, int=0);
~Envi();
void __fastcall Postaw();