tsamisa@gmail.com Guest
|
Posted: Tue Mar 20, 2007 4:36 pm Post subject: vector of a custom class and mouse events |
|
|
I created a class that contains a TImage component and with an event
handler for mouse up . I declared a vector in my main program (form)
of my classe's type. When i create the images everything works fine.
If i press a mouse button (the event handler in my class is for
mouseup) i get in to the desired function but the properties of the
class are not correct.
The class:
class pdtls
{
private: // User declarations
bool pdcreated;
public: // User declarations
int pid,originalleft,originaltop,myindex;
TImage *pdimg;
AnsiString imgdata;
__fastcall pdtls();
__fastcall ~pdtls();
void __fastcall init(TScrollBox* owner,TColor clr,int l,int t,
AnsiString data,int orgnllft,int
orgnltp,
int imgtype);
void __fastcall init(TForm* owner,TColor clr,int l,int t,
AnsiString data,int orgnllft,int
orgnltp,int imgtype);
void __fastcall testfn(TObject *Sender,TShiftState Shift, int
X, int Y);
void __fastcall checkfordelete(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall deletethis();
void __fastcall setlefttop(int lft,int tp);
void __fastcall setmyindex(int indx);
};
in the init functions i have the following lines:
pdimg=new TImage(owner); //The owner is a scrollbox of the main form
pdimg->Parent=owner;
pdimg->ShowHint=true;
this->pdimg->OnMouseUp=checkfordelete;
in the function checkfordelete i just have this line:
Form1->waypointindex=myindex;
where waypointindex is an integer in my main form
the declaration in my main form is
vector <pdtls> pds;
vector <pdtls>::iterator p=pds.begin();
int crrvctr=pds.size();
pds.push_back(pdtls());
pds[crrvctr].init(Form1->ScrollBox1,clRed,X-5,Y-5,Edit4->Text,X,Y,0);
pds[crrvctr].setmyindex(crrvctr);
when i move my mouse over te images the hint display (ahint box that
displays some data) is correct on all the images.
when i click the last created image myindex, originaltop, pid etc are
correct. When i click on the first created image or any other except
the last i get random values for the same values. |
|