Know in wich control is the mouse over  

Send By: Alex Colinas
Web : N.A.
Email: ea3ayp@teleline.es
Date: 12/03/00

Tip accessed 575 times

 


  • Put two TLabels in your form (Label1 and Label2)
  • Put a TPopUpMenu and asociate it to the form
  • Put this code in the OnPopUp event of the PopUpMenu:


     procedure TForm1.PopupMenu1Popup(Sender: TObject);
     var
        Cur : TPoint;
     begin
        {Al parecer sólo para componentes que puedan recibir el foco}
    
        {Obtiene la posición del ratón}
        GetCursorPos(Cur);
        {Obtenemos el nombre del control}
        label2.caption:=FindControl(windowfrompoint( Cur )).Name;
        {Si són tedit o tdbedit muestra el contenido de la edición}
        if FindControl(windowfrompoint( Cur )).ClassType =TEdit then
           label1.caption:=TEdit(FindControl(windowfrompoint( Cur ))).Text;
        if FindControl(windowfrompoint( Cur )).ClassType =TDBEdit then
           label1.caption:=TDBEdit(FindControl(windowfrompoint( Cur ))).Field.AsString;
     end;
    



    When pressing the right button of the mouse, in the Label2 we will obtain the name of the component.
    If it is a TEdit or TDBEdit in the Label1 we obtain the text that is editing.
    I use it in a TDBEdit connected to a " currency " field so that it shows me the conversion of PTA <-->Euro