Board index » cppbuilder » Assigning TImages on form to a TImage Array

Assigning TImages on form to a TImage Array

I want to be able to quickly access TImages that I have placed on a
form.
Is their anyway of assigning them to an array of TImages. I think I have
correctly created a TImage array but I am having trouble assigning the
different TImages to it

Thanks

Col

 

Re:Assigning TImages on form to a TImage Array


Hi Col --

Quote
> I want to be able to quickly access TImages that I have placed on a
> form.  Is their anyway of assigning them to an array of TImages. I
> think I have correctly created a TImage array but I am having trouble
> assigning the different TImages to it

Use the STL map class for managing the list of Images.  For example...

// in header...

#include <map>

typedef std::map<int, TImage*> TImages;
class TForm1 : public TForm
{
__published:
   TImage *Image1;
   TImage *Image2;
   TImage *Image3;
   TImage *Image4;
   TImage *Image5;
   TBitBtn *BitBtn1;
   void __fastcall BitBtn1Click(TObject *Sender);
private:
   TImages MyImages;
public:
   __fastcall TForm1(TComponent* Owner);

Quote
};

// in source...
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
   MyImages[0] = Image1;
   MyImages[1] = Image2;
   MyImages[2] = Image3;
   MyImages[3] = Image4;
   MyImages[4] = Image5;

Quote
}

Then, you can access the Images as if MyImages was a regular array...

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
   MyImages[0]->Canvas->FillRect(MyImages[0]->Canvas->ClipRect);  

Quote
}

Good luck!

--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com

Other Threads