PDA

View Full Version : سوال: حرکت و یا تغییر سایز کامپوننت ها(مثلا TEdit) در fireMonkey به صورت runtime



adel1369
دوشنبه 04 فروردین 1393, 19:15 عصر
سلام دوستان
کسی میدونه با چه کدی و به چه صورت میشه کامپوننتی مثل TEdit رو در fireMonkey به صورت runtime جابه جا کرد یا تعییر سایز داد؟
من کد زیر رو از دلفی درباره این موضوع پیدا کردم ولی متأسفانه نمی فهمم چیکار کرده؟ مخصوصا کار با پارامترهای event ها؟
http://delphi.about.com/library/weekly/aa102505a.htm

Ananas
سه شنبه 05 فروردین 1393, 11:10 صبح
سلام. کدی دلفی ای که لینک دادید، به c++ نوشتم:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Button1->OnMouseDown = ControlMouseDown;
Button1->OnMouseMove = ControlMouseMove;
Button1->OnMouseUp = ControlMouseUp;

Edit1->OnMouseDown = ControlMouseDown;
Edit1->OnMouseMove = ControlMouseMove;
Edit1->OnMouseUp = ControlMouseUp;

Panel1->OnMouseDown = ControlMouseDown;
Panel1->OnMouseMove = ControlMouseMove;
Panel1->OnMouseUp = ControlMouseUp;

Button2->OnMouseDown = ControlMouseDown;
Button2->OnMouseMove = ControlMouseMove;
Button2->OnMouseUp = ControlMouseUp;
}; /*FormCreate*/


void __fastcall TForm1::ControlMouseDown(
TObject *Sender,
TMouseButton Button,
TShiftState Shift,
int X, int Y)
{
if (
(chkPositionRunTime->Checked) &&
(Sender->InheritsFrom(__classid(TWinControl)))
)
{
inReposition = true;
SetCapture(((TWinControl*)(Sender))->Handle);
GetCursorPos(&oldPos);
};
}; /*ControlMouseDown*/
//---------------------------------------------------------------------------
void __fastcall TForm1::ControlMouseMove(
TObject *Sender,
TShiftState Shift,
int X, int Y)
{
const minWidth = 20;
const minHeight = 20;
TPoint newPos;
TPoint frmPoint;

if (inReposition)
{

TWinControl * obj = (TWinControl *)Sender;
{
GetCursorPos(&newPos);

if (Shift.Contains(ssShift))
{ //resize
Screen->Cursor = crSizeNWSE;
frmPoint = ScreenToClient(Mouse->CursorPos);
if (frmPoint.X > minWidth)
obj->Width = frmPoint.X;
if (frmPoint.Y > minHeight)
obj->Height = frmPoint.Y;
}
else //move
{
Screen->Cursor = crSize;
obj->Left += newPos.X - oldPos.X;
obj->Top += newPos.Y - oldPos.Y;
oldPos = newPos;
};
};
};
};

void __fastcall TForm1::ControlMouseUp(
TObject *Sender,
TMouseButton Button,
TShiftState Shift,
int X, int Y)
{
if (inReposition)
{
Screen->Cursor = crDefault;
ReleaseCapture();
inReposition = false;
};
};
//---------------------------------------------------------------------------


و فایل هدر:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TEdit *Edit1;
TPanel *Panel1;
TButton *Button2;
TCheckBox *chkPositionRunTime;
void __fastcall FormCreate(TObject *Sender);

private: // User declarations
bool inReposition;
TPoint oldPos;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall ControlMouseDown(
TObject *Sender,
TMouseButton Button,
TShiftState Shift,
int X, int Y);
void __fastcall ControlMouseMove(
TObject *Sender,
TShiftState Shift,
int X, int Y);
void __fastcall ControlMouseUp(
TObject *Sender,
TMouseButton Button,
TShiftState Shift,
int X, int Y);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

adel1369
شنبه 09 فروردین 1393, 20:14 عصر
ممنون از لطفتون
ولی من این کد رو توی fireMonkey ازش جواب نمیگیرم
توی TForm1::FormCreate به ControlMouseDown ارور میده(Undefined symbole 'ControlMouseDown)
یا مثلا توی TForm1::ControlMouseDown بهTWinControl ارور میده (type name expected)