Garder en mémoire un object TBitmap
Bonjour à tous,
J'utilise pour mon projet une grille (TStringGrid) dans laquelle j'insère des petits icônes au format bitmap en utilisant l'événement OnDrawCell(), jusqu'ici pas de problème.
Pour l'instant, OnDrawCell me sert à charger et à dessiner les Bitmaps:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
void __fastcall TForm_Main::StringGridDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
Graphics::TBitmap *Icone = new Graphics::TBitmap;
Icone->LoadFromFile(Images//IconeRouge.bmp);
// fonction me permettant de dessiner l'icône à l'endroit désiré et fond tranparent.
DrawTransparentBitmap(StringGrid->Canvas,Icone,0x00ff0000,Rect.Left+5,Rect.Top+17);
delete Icone;
} |
Pour des raisons d'optimisation, j'aimerais ne plus devoir charger ces Bitmaps à chaque évenements OnDrawCell, mais seulement le faire à l'initialisation.
.h
Code:
1 2 3 4 5 6
|
class TForm_Main : public TForm
{
public:
Graphics::TBitmap *m_Icone;
} |
.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void TForm_Main::initMainForm()
{
Graphics::TBitmap *m_Icone = new Graphics::TBitmap;
m_Icone->LoadFromFile(Images//IconeRouge.bmp);
}
void __fastcall TForm_Main::StringGridDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
Graphics::TBitmap *IconeTest = new Graphics::TBitmap;
IconeTest = m_Icone;
DrawTransparentBitmap(StringGrid->Canvas,IconeTest,0x00ff0000,Rect.Left+5,Rect.Top+17);
delete IconeTest;
} |
Malheureusement, dès que je quitte la fonction d'initialisation, m_Icone devient NULL, pourtant je ne la supprime pas, où est mon erreur?
Bonne journée!
Frédéric