 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
--== Alain ==-- Guest
|
Posted: Mon Sep 25, 2006 5:56 pm Post subject: TListImage and TBitmap |
|
|
Hi,
I would like to know how can i do.
I have a bitmap image stored in my TBitmap *Bmp;
This bitmap is 24x8 and represents 3 small bitmaps.
Now i would like to slice it in 3 parts 8x8, so for that i was thinking
to store it into TImageList *ImgLst; and slice it by giving height and
width = 8.
but it does not work.
when i do it, i have the following error :
violation error in vcl100.bpl
so here is my code :
__fastcall TARListView::TARListView(TComponent* Owner)
: TListView(Owner)
{
LastSortedColumn=0; // none
LastSortedDirection=0; // A-Z (from A to Z)
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Bmp->LoadFromResourceName((reinterpret_cast<int>(HInstance)),"ARROW");
ImgLst->AddMasked(Bmp,TColor(0x000000FF));
ImgLst->Width = 8;
ImgLst->Height = 8;
delete Bmp;
}
where ImgLst is TImageList*
thanks for help,
ALain |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Sep 25, 2006 10:52 pm Post subject: Re: TListImage and TBitmap |
|
|
"--== Alain ==--" <nospam (AT) noemail (DOT) com> wrote in message
news:4517d1db (AT) newsgroups (DOT) borland.com...
| Quote: | but it does not work.
when i do it, i have the following error :
violation error in vcl100.bpl
|
Where exactly does it occur? On which line?
| Quote: | Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Bmp->LoadFromResourceName((reinterpret_cast<int>(HInstance)),"ARROW");
|
If you put the component into a package, and then put the image into the
same package, then that code will fail, as the HInstance will point to the
wrong module. You should use FindClassHInstance() instead:
Bmp->LoadFromResourceName(FindClassHInstance(__classid(TARListView))
,"ARROW");
| Quote: | ImgLst->AddMasked(Bmp,TColor(0x000000FF));
|
Where are you actually instantiating the TImageList object? If it is a
member of the TARListView class, then you are not instantiating it at all,
and thus are trying to access an invalid object. That would explain the
crash, if the above is the line that is crashing to begin with.
| Quote: | ImgLst->Width = 8;
ImgLst->Height = 8;
|
You should be setting those values before loading the image, not afterwards.
Gambit |
|
| Back to top |
|
 |
--== Alain ==-- Guest
|
Posted: Tue Sep 26, 2006 12:25 am Post subject: Re: TListImage and TBitmap |
|
|
The TImageList object is instanciated in constructor of my component,
via new.
like that : ImgLst = new TImageList(this);
Alain
Remy Lebeau (TeamB) wrote:
| Quote: | "--== Alain ==--" <nospam (AT) noemail (DOT) com> wrote in message
news:4517d1db (AT) newsgroups (DOT) borland.com...
but it does not work.
when i do it, i have the following error :
violation error in vcl100.bpl
Where exactly does it occur? On which line?
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Bmp->LoadFromResourceName((reinterpret_cast<int>(HInstance)),"ARROW");
If you put the component into a package, and then put the image into the
same package, then that code will fail, as the HInstance will point to the
wrong module. You should use FindClassHInstance() instead:
Bmp->LoadFromResourceName(FindClassHInstance(__classid(TARListView))
,"ARROW");
ImgLst->AddMasked(Bmp,TColor(0x000000FF));
Where are you actually instantiating the TImageList object? If it is a
member of the TARListView class, then you are not instantiating it at all,
and thus are trying to access an invalid object. That would explain the
crash, if the above is the line that is crashing to begin with.
ImgLst->Width = 8;
ImgLst->Height = 8;
You should be setting those values before loading the image, not afterwards.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Sep 26, 2006 1:47 am Post subject: Re: TListImage and TBitmap |
|
|
"--== Alain ==--" <nospam (AT) noemail (DOT) com> wrote in message
news:45182d29$1 (AT) newsgroups (DOT) borland.com...
| Quote: | The TImageList object is instanciated in constructor of
my component, via new.
like that : ImgLst = new TImageList(this);
|
You did not show that in your earlier code. Your constructor should look
like the following:
__fastcall TARListView::TARListView(TComponent* Owner)
: TListView(Owner)
{
LastSortedColumn = 0; // none
LastSortedDirection = 0; // A-Z (from A to Z)
ImgLst = new TImageList(this); // <-- here
ImgLst->Width = 8;
ImgLst->Height = 8;
Graphics::TBitmap *Bmp = new Graphics::TBitmap;
try
{
Bmp->LoadFromResourceName(FindClassHInstance(__classid(TARListView))
,"ARROW");
ImgLst->AddMasked(Bmp, clRed);
}
__finally {
delete Bmp;
}
}
For future reference, please ALWAYS show all relevent code when you post
snippets.
Gambit |
|
| Back to top |
|
 |
--== Alain ==-- Guest
|
Posted: Tue Sep 26, 2006 8:11 am Post subject: Re: TListImage and TBitmap |
|
|
Sorry if i deleted it.
I had in my code several commented lines, so i removed them when i did
the copy and paste to newsgroups.
for sure i did not use the try and finally command...only when my code
is working i had security such like that.
Al.
Remy Lebeau (TeamB) wrote:
| Quote: | "--== Alain ==--" <nospam (AT) noemail (DOT) com> wrote in message
news:45182d29$1 (AT) newsgroups (DOT) borland.com...
The TImageList object is instanciated in constructor of
my component, via new.
like that : ImgLst = new TImageList(this);
You did not show that in your earlier code. Your constructor should look
like the following:
__fastcall TARListView::TARListView(TComponent* Owner)
: TListView(Owner)
{
LastSortedColumn = 0; // none
LastSortedDirection = 0; // A-Z (from A to Z)
ImgLst = new TImageList(this); // <-- here
ImgLst->Width = 8;
ImgLst->Height = 8;
Graphics::TBitmap *Bmp = new Graphics::TBitmap;
try
{
Bmp->LoadFromResourceName(FindClassHInstance(__classid(TARListView))
,"ARROW");
ImgLst->AddMasked(Bmp, clRed);
}
__finally {
delete Bmp;
}
}
For future reference, please ALWAYS show all relevent code when you post
snippets.
Gambit
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|