Page 1 of 1

Creating Custom Control

Posted: Fri Apr 03, 2009 9:51 am
by wxND
Hello dear forum,

I try to create my own control (graph). Therefore derive my class from wxControl according to the 'Custom Control' section in the SVN Ref manual.

I get the following error messages:
obj\release\LogViewMain.o:LogViewMain.cpp:(.text+0xf1c)||undefined reference to `simpleGraph::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)'|

obj\release\LogViewMain.o:LogViewMain.cpp:(.text+0x283c)||undefined reference to `simpleGraph::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)'|
||=== Build finished: 2 errors ===|

I guess this problem is related to the two-step-creation of a wxWindow, but have no clue since I'm a wxWidgets and C++ newbie.

Thank you for any help.

System: Code::Blocks, MinGW, WindowsXP

Posted: Fri Apr 03, 2009 1:49 pm
by Auria

if your component is to behave panel-like, I would first and foremost recommend deriving from wxPanel and not wxComponent, this will save you work from implementing some basic features, and you can then concentrate only on the drawing aspects.

The errors you get probably come from declaring methods (the ones mentionned in the message) but never actually defining them.

Code: Select all

// header
class Foo
  void foo();
  void bar();
  void foobar();

// code file
void Foo::foo()
  // do something
void Foo::bar()
  // do something
void Foo::foobar()
  // do something

Posted: Fri Apr 03, 2009 7:31 pm
by wxND
Thanks a lot :)

Posted: Sat Apr 04, 2009 12:13 am
by Auria
wxND wrote: Wouldn't the compiler generate a compiler error when a declared member was not defined (or in the case of a methode/function: implemented) ? I would assume so.
No, because the declaration and definition can be in different files; even in different librairies -- and the compiler doesn't get to see all of them, only the linker does.
It seems as the generated objects can't be linked due to missing definition of reference regarding Creat() member function.
As I don't have a deep insight in internal wxWidgets procedures and compiler/linker, I can't see the element to cause the build failing.
Not sure i get what you mean. This has nothing to do with wxWidgets internals, this is plain C++. Declaring a function and not defining it is a C++ error, no matter if you're using wx or not. If you don't understand the code example I posted, then sorry, you're not ready to create a custom wxWidgets control; I would strongly recommend studying C++ (especially inheritance) to have a strong basis on which to build. BTW, the syntax you posted as example is plain wrong, it won't compile, and i can't really figure what's it's supposed to mean.