Click here to Skip to main content
15,845,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to handle dynamically created form's MouseDown or MouseUp event? Using:
C++
TMouse * event= dynamic_cast<TMouse*>(Sender);

does not throw any error but doesn't do the work either. According to C++ Builder's reference TMouseEvent is the function type for either an OnMouseDown event or an OnMouseUp event. I don't know what to do here.

Thanks in advance.

What I have tried:

This throws the error: E2031 Cannot cast from 'TObject*' to 'TMouseEvent'
C++
void __fastcall TfMain::dyn_formMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
	int X, int Y){
	TMouseEvent * event= dynamic_cast<TMouseEvent *>(Sender);
	if (event) {
		old_x = X;
		old_y = Y;
		mouseState = MOUSE_DOWN;
	}
}
Posted
Updated 4-Nov-19 22:55pm
v2

1 solution

Such a cast is invalid, of course, since TMouseEvent is the type of the event handler (that is the function, it has nothing to do with the sender). See this page for sample code: TControl.OnMouseUp Event[^].
 
Share this answer
 
Comments
peytuk 5-Nov-19 3:58am    
Yeah!? I //commented casting and if statements. It is working, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900