View RSS Feed

Development Team Blog

The Smallest Program

Rate this Entry
A Visual DataFlex program doesn't have to consist of windows, views and dialogs, you can write command line style programs in VDF too. And the best part is that the VDF Studio (12.x and later) fully supports programs that have no graphical user interface as first class citizens. All the wonderful features, such as CodeSense, the CodeExplorer, the Properties panel, all treat any source code the same, afterall, it's all source code and source code rules. This may seem obvious unless you've been exposed to the earlier generations of the VDF development tools (VDF 11 and earlier), where such programs would often be rejected or ignored by the IDE.

We'll take this for a test drive in the Order Entry sample workspace. Create a new Basic project, File -> New Project and select Basic Project, let's call it Test.src. You'll end up with Test.src that looks like this:

Code:
Use Windows.pkg
Use cHtmlHelp.pkg
Use cApplication.pkg

Object oHtmlHelp is a cHtmlHelp
End_Object

Object oApplication is a cApplication
    Set pbPreserveEnvironment to False
    Set peHelpType to htHtmlHelp
End_Object

Send Info_Box "Hello World" "Visual DataFlex Basic Project"
Place a breakpoint on the Send Info_Box line, and run it. You'll notice that it stops in the debugger, if you press F5 to continue execution it displays the messagebox. This is a simple program that has no views or dialogs or other user interface, it simply displays a messagebox. The really cool thing is that the Studio treats this as a first class citizen program, you have the code outline in Code Explorer, integrated debugging, CodeSense and everything.

But this program still has a bunch of "magic" code, could we make it smaller? Yes, we can. It turns out that the smallest and yet still valid program is this:

Code:

Yup, that's right, no code at all. Try it out, remove all the code from Test.src, and compile & run it. It compiles happily, and runs just as happily. Of course, it doesn't do anything interesting, it just starts and then exits. Let's make it a little more interesting:

Code:
Showln "Hello, world"
inkey windowindex
Run this and "Hello, world" is displayed in the showln window, and then a little dialog with an OK button pops up, you click OK and the program exits.

Now your mind probably starts going, wow, look at that, it's like character mode program code! And you'd be right, it's a reasonable comparison, except you can't display character mode user interfaces. In VDF you can write programs with a GUI or without a GUI, but you can't display character mode user interfaces. Just like in character mode, you can write programs with a character mode user interface or without user interface, but you can't display GUI windows and dialogs.

And of course you can create non-visual objects and use all the OO features of VDF.

Code:
Use DfAllEnt.pkg

Object oFrog is a cObject
    Procedure SayHello
        Showln "Ribbit, ribbit"
    End_Procedure
End_Object

Send SayHello to oFrog
inkey windowindex
If your program will open and work with tables and stuff, you also need to set up the data path with a .ws file. This is usually handled automatically by the cApplication object, like this:

Code:
Use DfAllEnt.pkg

Object oApplication is a cApplication
End_Object

Open Customer

Procedure TestIt
    Clear Customer
    Find GT Customer by 1
    Showln Customer.Name
End_Procedure

Send TestIt
inkey windowindex
Most of the test programs that I write when implementing a new feature or fixing a bug in VDF are some sort of variation of the above. It gives you a very small scratch program with minimal interference from other unrelated code, while at the same time you have all the capabilities of the Studio at your disposal, compiler, debugger, CodeSense, Code Explorer, Properties Panel etc.

Comments

  1. flxkid's Avatar
    Sonny,

    Why not allow console based apps in VDF? Just curious. I can certainly see where they could come in handy. I'm doing more multi-language apps all the time. Many times console redirection and console based output prove to be very valuable.

    Maybe VDF should include a 3.2 console based compiler/license. Has the 3.2 system been kept up to date on the langauge side of things?

    OLIVER
  2. Ola Eldoy's Avatar
    Thanks for an interesting article, Sonny.

    It's nice to see VDF "non-gui programming" highlighted. For testing purposes and for "business logic", it is good practice to exercise your code outside the gui.
  3. Bob Cergol's Avatar
    I noticed long ago that VDF's FMAC pretty much contains all of the DF commands and VDF can compile a lot DF code -- sans the user interface stuff.

    I still prefer to use 3.2 console mode for maintenance routines. Over the years I've developed a collection of tools I really depend on. I do not want to rewrite them. I could easily port them to the VDF environment, except that most of them do showln's to give me feedback. My first attempt to port one ran into the problem that the VDF object that displays "showln" output has a rather small maximum capacity and once it is reached I can no longer tell what is going on with the program. (Yes I could write a BP and use the sentinel, etc. -- but that takes me a whole lot longer than some of my maintenance jobs can justify.)

    So -- yes I'd love some minimal capability to do a character-mode interface within VDF -- understanding that it would not be intended for full-blown end-user, interactive database applications.

    There's been some talk on the forums about enhancing DF3.2 -- and whether users would pay for an upgrade. If the upgrade was that it could be embedded within VDF -- I'd definitely pay!

    Bob
  4. ivansc's Avatar
    a little bug? i was debugging an excel reader program when i've recieved three messages one after another:
    1. Unhandled exception in debugged application
    ACCESS_VIOLATION(0xc0000005) at address 0x10066564 while reading from address 0xa42149b8 ocurred in the program being debugged. .....
    2. Studio Debugger
    The debugger is now in limited break mode ...
    3. Microsoft windows
    Visual Dataflex 2009 Studio 15.0 has stopped working

    Searching the data, was that a big number was assigned to a date variable.
    I tested using your "smallest program" (A great help!!!) writing this:

    Register_Procedure prufe
    Procedure prufe
    Date dfecha
    Move 99999999 to dfecha
    Show dfecha
    End_Procedure
    Send prufe

    press F5 and the same results. I try in three machines one with windows vista home premium, another with windows vista bussiness and the last with windows xp.
    I know the value is very big, but i think the program must send a message error, not hang.
    regards
    Ivan
  5. Sonny Falk's Avatar
    Quote Originally Posted by ivansc
    ...
    3. Microsoft windows
    Visual Dataflex 2009 Studio 15.0 has stopped working

    Searching the data, was that a big number was assigned to a date variable.
    I tested using your "smallest program" (A great help!!!) writing this:

    Code:
     
    Procedure prufe
        Date dfecha
        Move 99999999 to dfecha
        Show dfecha
    End_Procedure
    Send prufe
    Thanks, Studio/debugger crash fixed for next revision.

    P.S. Just because I really enjoy receiving bug reports that are so simple and isolated, I took the unusual step and responded to the bug report right here. It doesn't mean I'll do that in the future, it was only this time for Ivan and and because it was using the "smallest program" approach.