Callback in C++ Builder

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Callback in C++ Builder

Postby Lena » Mon Apr 27, 2015 6:58 am

Hi.
Please explain how to create C++ callback and then use in code like this:
Code: Select all
nit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIRegClasses,  uniguiclasses, uniGUIForm, uniMemo, uniGUIBaseClasses, uniButton;

type
  TMainForm = class(TUniForm)
    UniButton1: TUniButton;
    UniButton2: TUniButton;
    UniMemo1: TUniMemo;
    procedure UniButton1Click(Sender: TObject);
    procedure UniButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowCallBack(Sender: TComponent; AResult:Integer);
  end;

function MainForm: TMainForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication, Unit1;

function MainForm: TMainForm;
begin
  Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniForm1.Show(ShowCallBack);
end;

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
  UniForm1.ShowModal(ShowCallBack);
end;

procedure TMainForm.ShowCallBack(Sender: TComponent; AResult:Integer);
begin
  UniMemo1.Lines.Add('Form: '+(Sender as TuniForm).Name+', Result: '+IntToStr(AResult));
end;

initialization
  RegisterMainFormClass(TMainForm);

end.

Lena
BCBJ Master
BCBJ Master
 
Posts: 583
Joined: Sun Feb 06, 2011 1:28 pm

Re: Callback in C++ Builder

Postby rlebeau » Tue Apr 28, 2015 1:02 am

Lena wrote:Please explain how to create C++ callback and then use in code like this


Your question is too vague. What exactly are you trying to accomplish? What have you actually tried so far?
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1544
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Callback in C++ Builder

Postby Lena » Tue Apr 28, 2015 1:55 am

What exactly are you trying to accomplish?


Hi.
I use uniGUI Trial Edition: http://forums.unigui.com
I found this example in Demo folder uniGUI (example in the first post).
How it will be in C++?
Thank you.
Lena
BCBJ Master
BCBJ Master
 
Posts: 583
Joined: Sun Feb 06, 2011 1:28 pm

Re: Callback in C++ Builder

Postby rlebeau » Tue Apr 28, 2015 9:12 pm

Lena wrote:I found this example in Demo folder uniGUI (example in the first post).


First post of which forum exactly? There are 17 forums on that server.

Please, either show the actual code you are interested in, or point out the exact discussion/URL. Please don't make people hunt for things.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1544
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Callback in C++ Builder

Postby Lena » Wed Apr 29, 2015 12:50 am

Sorry for my bad English. I talked about the example of the first post of this topic.
I will be more accurate.
1. I installed uniGUI Trial Edition in C++ Builder XE7.
2. In folder Demos many examples. They are simple and understandable.
3. There are two examples callback of difficult to understand. How to translate them into C++?
Please show at least one piece of code in C++.
These examples I attach the following link:
link to examples
Lena
BCBJ Master
BCBJ Master
 
Posts: 583
Joined: Sun Feb 06, 2011 1:28 pm

Re: Callback in C++ Builder

Postby rlebeau » Wed Apr 29, 2015 8:55 pm

Main.hpp:

Code: Select all
//---------------------------------------------------------------------------

#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <uniGUITypes.hpp>
#include <uniGUIAbstractClasses.hpp>
#include <uniGUIRegClasses.hpp>
#include <uniguiclasses.hpp>
#include <uniGUIForm.hpp>
#include <uniMemo.hpp>
#include <uniGUIBaseClasses.hpp>
#include <uniButton.hpp>
//---------------------------------------------------------------------------
class TMainForm : public TUniForm
{
__published:
    TUniButton *UniButton1;
    TUniButton *UniButton2;
    TUniMemo *UniMemo1;
    void __fastcall UniButton1Click(TObject *Sender);
    void __fastcall UniButton2Click(TObject *Sender);
private:
    // Private declarations
public:
    // Public declarations
    void __fastcall ShowCallBack(TComponent *Sender, int AResult);
};
//---------------------------------------------------------------------------
TMainForm* __fastcall MainForm();
//---------------------------------------------------------------------------
#endif


Main.cpp:

Code: Select all
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <uniGUIVars.hpp>
#include <MainModule.hpp>
#include <uniGUIApplication.hpp>
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
TMainForm* __fastcall MainForm()
{
    return (TMainForm*) UniMainModule->GetFormInstance(__classid(TMainForm));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UniButton1Click(TObject *Sender)
{
    UniForm1->Show(&ShowCallBack);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UniButton2Click(TObject *Sender)
{
    UniForm1->ShowModal(&ShowCallBack);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ShowCallBack(TComponent *Sender, int AResult)
{
    UniMemo1->Lines->Add("Form: "+(static_cast<TuniForm*>(Sender)->Name+", Result: "+IntToStr(AResult));
}
//---------------------------------------------------------------------------
void RegisterMainForm()
{
    RegisterMainFormClass(__classid(TMainForm));
}
#pragma startup RegisterMainForm
//---------------------------------------------------------------------------
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1544
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Callback in C++ Builder

Postby Lena » Thu Apr 30, 2015 1:16 am

Thank you veru much!
Now I can set SetFocus after ShowMessage:
Code: Select all
void __fastcall TUniFormAddOrgan::ShowCallBack(TComponent *Sender, int AResult)
{
 UniEditNameOrg->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TUniFormAddOrgan::UniBitBtnAddOrgClick(TObject *Sender)
{
 if(UniEditNameOrg->Text == "")
 {
  ShowMessage(L"Enter Name", &ShowCallBack);
  return;
 }
Lena
BCBJ Master
BCBJ Master
 
Posts: 583
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 4 guests

cron