The Smallest Program
byon 3-Aug-2009 at 07:00 AM (1806 Views)
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:
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.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"
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:
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:
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.Code:Showln "Hello, world" inkey windowindex
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.
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 oFrog is a cObject Procedure SayHello Showln "Ribbit, ribbit" End_Procedure End_Object Send SayHello to oFrog 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.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