Welcome!

Joe Barr

Subscribe to Joe Barr: eMailAlertsEmail Alerts
Get Joe Barr via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Article

Taking Kylix 3 for a test drive

Joe Barr overcomes two small problems (not knowing C++ or X programming very well) when compiling his app.

(LinuxWorld) — Last week I wrote about problems getting Kylix 3 Open Edition (K3OE) working on Red Hat 7.3. This week, I'll be describing my experiences actually using K3OE, particularly its brand-spanking-new C++ IDE. Previous versions of Kylix have been for Delphi only.

I know, I know — true Linux geeks never use RAD tools, or even IDEs. Not unless you consider Emacs to be an IDE, that is. For the rest of the world, RADs and IDEs are very handy tools that provide real productivity gains. Management likes that.

Kylix 3 is a truly visual development tool. You use its components and design tools to create a visual representation of the window(s) you want to create, and it generates the code required for you. Now that C++ code can be produced as well as Delphi, Kylix is going to become even more important for Linux-development efforts. Whether you use it or not — and whether you like it or not — its success will mean more applications more quickly for Linux.

Choosing a small project with which to exercise K3OE wasn't hard. I've done very little C++ coding, and I worried I might get in over my head quickly. I decided on an approach that would allow me (hopefully) to create a small GUI app in the shortest time possible.

The project

The itch I decided to scratch was one I've had for some time: create a real-time display of active TCP/IP sessions. For the under-the-hood code I turned to Freshmeat, looking for a GPL'd app that does something similar. I found a program to cannibalilze almost immediately. It's called LCDnetstat. Its sole purpose being to display filtered netstat output on an LCD.

After downloading the LCDnetstat-2.0.1 tarball and decompressing it, I set to work. I hacked and simplified the code considerably until I got it doing only what I wanted to see in the GUI. Then I set that source code aside and entered K3OE.

Shown below are the four primary windows you see when you start Kylix 3:

  • The bright blue window is the form, which provides you with a view of the application appearance as you work.
  • The wide and narrow gray window across the top is the main Kylix toolbar.
  • The gray window in the bottom left is the Object Inspector.
  • The large white (mostly hidden by the others) window is what holds the source code that Kylix has created for you or that you've entered yourself.

Kylix 3 IDE
Editor's note: The above image is reduced in size and color palette to allow it to load quickly. Click on the above image to see the original.

I began by starting the IDE and then clicking on the form. The Object Inspector follows your focus, so when I clicked on the form, the form appeared in it. The Object Inspector contains a column for all the properties of the object and another column for all the events which may interact with it. Now that I had the Object Inspector's attention where I wanted it, I clicked on the Color property and selected clBlue. The form changed color as soon as I entered the change. I clicked on Caption and entered "VisNetstat." The form immediately reflected the new property. Changes you make to the form itself are reflected by the Object Inspector just as quickly.

After dragging the form around a bit, I resized it by tugging at its corners. Since I'm running on an unsupported platform, I decided to save what I had before going too far. On the toolbar, I clicked on File-->SaveProjectAs and followed the dialog. That saved my new project in the directory I wanted it. From that point on, getting back to the project when restarting Kylix was always as easy as clicking File-->Reopen and selecting my project from the list.

The toolbar hides the real power of Kylix. Along the bottom, you can choose all sorts of goodies to work with. Standard components include frames, menus, edit (text entry) boxes, labels and all manner of controls. You can choose from buttons, checkboxes, radio buttons, list boxes, and more. In fact, there are more tabs than just the Standard one. There is one for additional components, another for common controls, and yet another for dialogs to handle ordinary tasks such as selecting a file from a directory.

Time and space prevent me from exploring all the tabs completely in this column. Keep in mind that this is the free (as in price) version. The Kylix Pro edition contains considerably more components than the Open Edition, and the Enterprise edition still more.

Back to my project!

I clicked on Label from the Standard components tab on the tool bar, then clicked somewhere on the form. The label appeared, and, using the Object Inspector, I changed its color, selected a font, font size, and font style, then entered a caption. But that's eye candy. I needed a container in which to display netstat results.

From the Additional components tab, I selected a StringGrid, which, according to the documentation, "Creates a grid that you can use to display string data in columns and rows." It sounded perfect for my needs. Clicking on the form gave me the starting point for the grid. Using the Object Inspector, I set the number of columns and rows. I left one fixed row to use for column headings and did away with the fixed column.

After wasting some time trying to find a way to set the text for the column headings using the Object Inspector, I learned that column headings would need to be set in the code. I searched the net looking for sample code and finally found something that did exactly what I needed.

I double-clicked "OnEntry" in the Events column of the Object Inspector. Kylix created an empty function (or is that method?) in the code window for me. I clicked inside of it and entered the following code:

AnsiString sPort = "Port";
AnsiString sAddr = "Remote";
AnsiString sProg = "Program";
AnsiString sStat = "State";

StringGrid1->Font->Height = 18; StringGrid1->Font->Color = clBlack;

StringGrid1->Cells[0][0] = sPort; StringGrid1->Cells[1][0] = sAddr; StringGrid1->Cells[2][0] = sProg; StringGrid1->Cells[3][0] = sStat;

Back on the toolbar, I clicked on Run-->Run and watched the nearly empty application compile and come to life. Sure enough, there was my application window, including the column headings, exactly as advertised.

Getting down and dirty

Now it was time to get my hands dirty. No more of that wimpy "click this, click that" stuff. We're talking code ugly code at that, by the time I got finished with it. I had left my barebones C source code as a module of its own. Now I had to cut-and-paste the essential code from its main() and assorted functions and put it all together in the OnEntry function I created above. It went from about 300 lines of code to about half of that.

The Kylix IDE was quick to find and point out errors for me as I tried to compile the mix of code from Kylix and the C module. It only took me 10 or 15 minutes to get almost all the errors resolved. All but one, that is.

I ran into a problem getting the pipe between the netstat program and my module working and had to ask Borland for help. The cure was simply to add #include <stdio.h> to my Kylix program. Then I was back on track and in no time at all the first version of VisNetstat was done.

Later versions of VisNetstat may refine the process, but in the initial release I am only displaying tcp session data. When the user clicks "Do It" (see the screen image below) netstat is executed with -tapn as the arguments.

VisNetstat 1.0
Editor's note: The above image is reduced in size and color palette to allow it to load quickly. Click on the above image to see the original.

I said earlier the real power of Kylix was in the tool bar, but that may not be right. It may be in the Object Inspector. In my case, it soon became clear my grid for displaying netstat output would have to be larger than a single screen. I would need to make it scrollable.

Remember, I've never written a GUI for X without Kylix. Adding a functional scroll bar could be more work for me than all the rest of the program combined. But not with Kylix. I select the grid so that it appears in the Object Inspector, click on Scroll Bars, then on vertical. That's it. It's done. Now the app displays ten rows in the application window and the user can scroll as needed through all 100 rows in the grid.

In short, Kylix 3 has allowed me to develop this simple C++ GUI app for X in just a few days. Given how little C++ and X development experience I have, and the fact that I've never worked with pipes except from the command line, that's pretty good time. Kylix has demonstrated to me it deserves its RAD label.

More Stories By Joe Barr

Joe Barr is a freelance journalist covering Linux, open source and network security. His 'Version Control' column has been a regular feature of Linux.SYS-CON.com since its inception. As far as we know, he is the only living journalist whose works have appeared both in phrack, the legendary underground zine, and IBM Personal Systems Magazine.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.