• about
  • features
  • examples
  • requirements
  • download
  • installation
  • contact
  • SourceForge

  • SourceForge Logo

    example :: simple dialog

    This example uses only a few options, but it is sufficient to illustrate the basic concepts of of Xorph. The source file looks like this:

    Xorph source code

    <?xml version="1.0" encoding="UTF-8"?>
    <xorph:environment name="SimpleDialogEnvironment" 
            <group label="Player Information" name="PlayerInfo">
                <option label="Player Name" name="Name">
                    <text case="any" defaultValue="Player 1"/>
                    <description>Enter your name here.</description>
                <option label="Password" name="Password">
                    <text case="any" password="true"/>
                    <description>Please enter your game password here.</description>
                <option label="Skill Level" name="Level">
                    <selectNumeric standardDisplay="radiobuttons" defaultValue="2">
                            <value label="Beginner" value="1"/>
                            <value label="Intermediate" value="2"/>
                            <value label="Expert" value="3"/>
                    <description>Select your experience level.</description>
        <interface name="Options" title="Game Options">
                <text>Please enter the following information in order to start the game.</text>
                <includeGroup name="PlayerInfo" withFrame="false"/>

    If you prefer using some graphic XML editor, you might want to try XAmple. The following screenshot shows how the definition might look like.

    SimpleDialog source in XAmple XML Editor

    Generating the code

    Now, we need to generate our X++ code. This is trivial:

    vwegert@sinclair SimpleDialog $ Xorph SimpleDialog.xorph
    Xorph 1.0 - see http://xorph.sourceforge.net for additional information
    Compiling SimpleDialog.xorph...
    Unimplemented block at xmlschemastypes.c:2213
    SimpleDialog.xorph validates
      Generating header file...
      Generating C++ source file...

    Setting up a test frame

    Now we're ready to use the generated classes. Here's a simple test frame.

    #include <qapplication.h>
    #include "SimpleDialog.h"
    int main( int argc, char ** argv )
    	QApplication app( argc, argv );
    	SimpleDialogEnvironment * env;
    	env = new SimpleDialogEnvironment( "Volker Wegert", "XorphSimpleDialogDemo" );
    	qDebug("Player name is " + env->getName() );
    	qDebug("Password is " + env->getPassword() );
    	qDebug("Level is " + QString::number( env->getLevel() ) );


    Running this test frame display the following dialog.

    generated dialog window

    After the window is closed, the program prints out the following debugging information:

    Player name is Player 1
    Password is Hugo
    Level is 2

    © 2005 Volker Wegert