[archived content]
Dfl /

DFL Tutorial (Part 2)

On the previous page we covered setting up your D compiler and DFL, choosing an editor or IDE, and compiling example DFL source files. Now we will cover writing some of your own DFL code.

Hello World

Below is the helloworld.d from the examples:

import dfl.all;

int main()
{
        Form myForm;
        Label myLabel;

        myForm = new Form;
        myForm.text = "DFL Example";

        myLabel = new Label;
        myLabel.font = new Font("Verdana", 14f);
        myLabel.text = "Hello, DFL World!";
        myLabel.location = Point(15, 15);
        myLabel.autoSize = true;
        myLabel.parent = myForm;

        Application.run(myForm);

        return 0;
}

This code can be compiled with the following command:

dfl -gui helloworld.d

Then run it with helloworld to get the following program:

Explanation

Now we will go through the above code and see what it means. The parts of the code will be linked to the documentation, so you can easily click to get more information about it and what's related.

  • Line one contains import dfl.all; - gives you access to all of DFL's public interface.

  • Next is int main() { - the program's entry point function.

  • Now we have Form myForm; Label myLabel; - declaring a couple variables; a Form (window/dialog) and a Label (text display widget).

  • myForm = new Form; - to construct the Form.

  • myForm.text = "DFL Example"; - sets the Form's text property, which sets the window caption/title.

  • Now we get to the label with myLabel = new Label; - constructing the Label.

  • myLabel.font? = new Font("Verdana", 14f); - sets the Label's Font: font "Verdana" at 14 points.

  • myLabel.text = "Hello, DFL World!"; - sets the text property of the Label, which is what is displayed on the control.

  • myLabel.location = Point(15, 15); - sets the location property of the Label to a Point, with x = 15 and y = 15 offset, in pixels, from the top left of its parent.

  • myLabel.autoSize = true; - enables the autoSize property of the Label, which causes it to automatically resize its width and height to precisely fit the text at all times.

  • myLabel.parent = myForm; - sets the parent property of the Label, making the label a child control of the form; this makes the label be contained within the form and be bound and relative to its dimensions.

  • Finally we kick off the window and start things with Application.run(myForm); - this enters the main event loop and shows the form; it does not return until it gets an exit signal, such as by closing the main form (the one passed to run).

  • And last return 0; } - we return from the main function.

Entice Designer is a drag-and-drop GUI builder and code editor. Entice can be used to create the above example without writing a single line of code, simply by using point and click RAD.

More Information

  • Using events in DFL.

  • Here are CodeTips; good tips to check with when creating your DFL programs.

  • The online documentation can be used to find the available classes, members, and related information. The bottom of the documentation home page lists all the main items contained within the DFL library for quick documentation access.

  • There are several ways to get DFL support: DFL Forum, Contact Form, and IRC Chat.

  • Entice Designer, a Form Designer for DFL, is also helpful to newcomers because the properties are easily accessible in a convenient list including descriptions. Entice also has a tutorial available.

  • A brief FAQ (frequently asked questions and answers) can be found on the DFL page.

  • The installer will give you start menu shortcuts, one of which takes you to the Examples Folder. The provided DFL examples show how to use a lot of the features, as they are used to test the library between releases.

  • Part 1 of this tutorial gives extensive help with setting up a D compiler, setting up DFL, compiling DFL programs, choosing an editor, and more.

  • Other versions of DFL are also available on the DFL page, notably the Snapshots.

  • There are several DFL AddOns, helpful user code not officially part of or supported by DFL.

  • Here is online ExampleCode to suppliment other examples and addons.

Continue on to the next page; using events...

Page last modified on September 16, 2007, at 04:23 PM