Ver Mensaje Individual
  #1  
Antiguo 19-03-2013
DSK25 DSK25 is offline
Miembro
NULL
 
Registrado: jun 2012
Posts: 46
Reputación: 0
DSK25 Va por buen camino
Error al mover componentes en tiempo de ejecución

Hola, sucede que en una aplicación quiero que el usuario pueda mover los componentes, asi que use el siguiente código:

Código:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool Mover = false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   Mover = true;   
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
   Mover = false;   
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
   if(Mover == true) {
      TPoint *nPoint2;
      GetCursorPos(nPoint2);
      ListBox1->Left = (nPoint2->x - Form1->Left) - ListBox1->Width/2;
      ListBox1->Top = (nPoint2->y - Form1->Top) - ListBox1->Width/2;
   };
}
//---------------------------------------------------------------------------
Ahí trato de mover un ListBox pero me manda el error "Access violation at address ...", alguien sabe como solucionarlo
Responder Con Cita