Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Handle events from browser control DG::Browser

Martin Walter
Enthusiast
How can I recognize an event from the browser control DG::Browser, for example the URLChanged which is declared in BrowserBase?
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Martin Walter
Enthusiast
Obviously the callback function can not be defined in a class. I got it working finally this way:

void handleURLChanged(const DG::BrowserBase& source, const DG::BrowserURLChangedArg& eventArg);

m_browser.urlChanged += DGEventNotifier<DG::BrowserBase, DG::BrowserURLChangedArg>::Runnable(&handleURLChanged);
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD

View solution in original post

6 REPLIES 6
Use the += operator of BrowserBase::urlChanged to add a Runnable callback function to respond to this event.
Ralph Wessel BArch
Central Innovation
Martin Walter
Enthusiast
Sorry I'm not able to make it. My code does not compile in this line:
DGEventNotifier<BrowserBase, DG::BrowserURLChangedArg>::Runnable func = &UIBrowser::URLChanged;
Can you please tell me what is wrong?

My whole code is:

class UIBrowser: public DG::Browser
{
public:
	UIBrowser(const DG::Panel& panel, short item);

private:
	virtual void URLChanged(const DG::BrowserURLChangedArg& eventArg) override;
};

UIBrowser::UIBrowser(const DG::Panel& panel, short item) :
	DG::Browser(panel, item)
{
	DGEventNotifier<BrowserBase, DG::BrowserURLChangedArg>::Runnable func = &UIBrowser::URLChanged;
	this->urlChanged += func;
}

void UIBrowser::URLChanged(const DG::BrowserURLChangedArg& eventArg)
{
...
}
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
Martin wrote:
I'm not able to make it. My code does not compile in this line:
DGEventNotifier<BrowserBase, DG::BrowserURLChangedArg>::Runnable func = &UIBrowser::URLChanged;
Try changing this to:
this->urlChanged += DGEventNotifier<DG::BrowserBase, DG::BrowserURLChangedArg>::Runnable(UIBrowser::URLChanged);
Ralph Wessel BArch
Central Innovation
Martin Walter
Enthusiast
that doesn't compile too.
and neither:
this->urlChanged += DGEventNotifier<DG::BrowserBase, DG::BrowserURLChangedArg>::Runnable(&UIBrowser::URLChanged);
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
The urlChanged function should look more like this:
void UIBrowser::URLChanged(const DG::BrowserBase& source, const DG::BrowserURLChangedArg& eventArg)
Ralph Wessel BArch
Central Innovation
Solution
Martin Walter
Enthusiast
Obviously the callback function can not be defined in a class. I got it working finally this way:

void handleURLChanged(const DG::BrowserBase& source, const DG::BrowserURLChangedArg& eventArg);

m_browser.urlChanged += DGEventNotifier<DG::BrowserBase, DG::BrowserURLChangedArg>::Runnable(&handleURLChanged);
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD