developer's mag
main page
article
part 1
part 2
part 3
part 4
part 5
|
2 - A Real Sample Program (or a Sample 'Real' Program)
Rather than slowly building a program piece
by piece, we'll look at a working example,
and take it apart. The source code for this example program can be downloaded and installed, preferably
to a directory called 'eg_2'. The only piece
missing is the output from the Form Editor.
The Franklin form file (eg_2.fff) has been included, so you can load that
and export it as eg_2.cpp. At that point, the resulting files can
be compiled, and the program run.
Although simple, the program code answers
some of the questions raised in the
last
article:
- how do I initialize objects?
-
how do I handle objects settings
like checking
a checkbox, or coloring a rectangle?
- how do I set up my source so I can modify
my form in the Editor, but not erase
my source
code?
The key to all of this is to arrange your
source files so the Form Editor's source
output remains a separate file, and all other
coding goes into a second file. This requires
'cracking open' the object definition to
add functions and variables, so the Form
Editor provides a way to edit this, via the
menu option Source/Class Text. This displays
a dialog where you can add text which is
pasted into the source code in the header,
and is updated with each exporting. Specifically,
the text is placed in the public section
of the class definition. The example source
shows how this works - look at the eg_2.fff file to see what the text looked like originally,
and then eg_2.h file to see the result:
class CWindow1 : public CWindow
{ private:
public:
CRect *Rect1; CButton *Button1; CCheckbox *Checkbox1; CTextEdit *TextEdit1; CWindow1();
// text here is from the 'class text' menu option of the Form Editor int m_count; S32 MsgHandler( MSG_TYPE type, CViewable *from, S32 data ); void Initialize(void); // text end };
This option allows you to add other
functions,
variables, etc, and have the source
code
maintained by the Form Editor.
Previous Section
Next Section
|