Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TCloseDialogHandler again


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Nov 11, 2016 12:30 PM Last Post By: Yves Depreitere
Yves Depreitere

Posts: 61
Registered: 5/20/02
TCloseDialogHandler again  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2016 3:50 AM
Refering to this thread: https://forums.embarcadero.com/message.jspa?messageID=851482#851482

//---------------------------------------------------------------------------
void __fastcall TFrmFrameManage::ActionManageClearSelectedExecute(TObject *Sender)
{
struct TCloseDialogHandler : public TCppInterfacedObject<TInputCloseDialogProc>
{
void __fastcall Invoke (const System::Uitypes::TModalResult AResult)
{
switch (AResult)
{
case mrYes : FrmFrameManage->Do_Clear_Selected ();
break;
}
}
};

_di_TInputCloseDialogProc handler = new TCloseDialogHandler ();

String Message = "Clear all selections?";
TDialogServiceAsync::MessageDialog (Message, TMsgDlgType::mtInformation, TMsgDlgButtons() << TMsgDlgBtn::mbYes << TMsgDlgBtn::mbNo, TMsgDlgBtn::mbNo, 0, handler);
}
//---------------------------------------------------------------------------

This works great if FrmFrameManage is created using the extern PACKAGE variable, but not if a private variable is used to create the frame.

.h
private:
TFrmFrameManage *FFrmFrameManage1;
TFrmFrameManage *FFrmFrameManage2;

.cpp
FFrmFrameManage1 = new TFrmFrameManage (this);
FFrmFrameManage2 = new TFrmFrameManage (this);

How can I access the correct Do_Clear_Selected function of the correct frame?
Is there a possibility to pass extra parameters?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TCloseDialogHandler again  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2016 11:39 AM   in response to: Yves Depreitere in response to: Yves Depreitere
Yves wrote:

How can I access the correct Do_Clear_Selected function of the
correct frame? Is there a possibility to pass extra parameters?

Of course. Simply passing the calling frame's 'this' pointer to your handler
class, eg:

void __fastcall TFrmFrameManage::ActionManageClearSelectedExecute(TObject
*Sender)
{
struct TCloseDialogHandler : public TCppInterfacedObject<TInputCloseDialogProc>
{
TFrmFrameManage *m_frame;

TCloseDialogHandler(TFrmFrameManage *frame)
: m_frame(frame)
{
}

void __fastcall Invoke(const System::Uitypes::TModalResult AResult)
{
if (AResult == mrYes)
m_frame->Do_Clear_Selected();
}
};

_di_TInputCloseDialogProc handler = new TCloseDialogHandler(this);
TDialogServiceAsync::MessageDialog("Clear all selections?", TMsgDlgType::mtInformation,
TMsgDlgButtons() << TMsgDlgBtn::mbYes < TMsgDlgBtn::mbNo, TMsgDlgBtn::mbNo,
0, handler);
}
{code}

--
Remy Lebeau (TeamB)
Yves Depreitere

Posts: 61
Registered: 5/20/02
Re: TCloseDialogHandler again  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2016 12:30 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Boy I wish a had one tenth of a brain like yours Remi.
Thanks a million, you saved my bacon once again !!!

Remy Lebeau (TeamB) wrote:
Yves wrote:

How can I access the correct Do_Clear_Selected function of the
correct frame? Is there a possibility to pass extra parameters?

Of course. Simply passing the calling frame's 'this' pointer to your handler
class, eg:

void __fastcall TFrmFrameManage::ActionManageClearSelectedExecute(TObject
*Sender)
{
struct TCloseDialogHandler : public TCppInterfacedObject<TInputCloseDialogProc>
{
TFrmFrameManage *m_frame;

TCloseDialogHandler(TFrmFrameManage *frame)
: m_frame(frame)
{
}

void __fastcall Invoke(const System::Uitypes::TModalResult AResult)
{
if (AResult == mrYes)
m_frame->Do_Clear_Selected();
}
};

_di_TInputCloseDialogProc handler = new TCloseDialogHandler(this);
TDialogServiceAsync::MessageDialog("Clear all selections?", TMsgDlgType::mtInformation,
TMsgDlgButtons() << TMsgDlgBtn::mbYes < TMsgDlgBtn::mbNo, TMsgDlgBtn::mbNo,
0, handler);
}
{code}

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02