We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

Events and Notifications on dialog items

Mihalcea Bogdan
Contributor
Hello!
How can I use the event notifications in Archicad API?
I created a new Button class based on the DG::Button class which has a "name" variable. When I click this button I want to make something happen.
For now I am using
 if(ev.GetSource() == some button) { do something ... }
My problem is that the ev.GetSource() does not return my Button class pointer but it returns DG::ButtonItem pointer which does not contain the newly created functions like GetName().
I even made a new Observer class which inherits the ButtonItemObserver but I am stuck at this. This button will do only one type of thing like a HTTP request based on the name of this button.
To be more clear I will write the code here:

class MyButton : public DG::Button {
   public:
      GS::UniString GetName();
      void Do_HTTPRequest();//Based on the name of the button
   private:
      GS::UniString name;
}
class MyButtonObserver : public DG::ButtonItemObserver {
}
is there any way to override the OnClick event of a button?
2 REPLIES 2
Viktor Kovacs
Graphisoft
Graphisoft
ev.GetSource() will always return a pointer to the base class, so you have to dynamic_cast it to your inherited class.

Something like this:

MyButton* myButton = dynamic_cast<MyButton*> (ev.GetSource ());
Mihalcea Bogdan
Contributor
Thank you!
I tried it and it works.