Graphics with Kylix

Kylix is a new programming language for Linux. It is very similar to Delphi (a programming language for Windows), and in turn a graphical version of the Pascal language. Linux is a open source (free) version of Unix that has become popular with scientists, enthusiasts and web servers. In the past, a major drawback of Linux is that it is difficult to write graphical, easy to use programs. Kylix promises to make writing Linux programs much easier.

Because Kylix is a relatively new language, there is not a huge pool of information about how to write programs in this language (though there are a number of new pages devoted to this language). Because Kylix is similar to Delphi, you can often explore some of the web sites that distribute sample programs for Delphi. Two excellent sites are www.efg2.com and www.torry.net. Unfortunately, in some areas, such as graphics, Kylix is quite different from Delphi. There are some example Kylix programs that demonstrate some of the tricks for writing Linux programs.

Here is a sample program I wrote to learn about controlling graphics with Kylix. I am distributing both a Delphi and Kylix code for this program. Both programs function identically - they animate a gradient color bar and allow you to zoom into a region of the image using a magnifying glass.

This program demonstrates how you can control graphics with Kylix. To download the Kylix source code shift+click here. For the Delphi code, shift+click here.

Alex Reiter and Mohamed Helal independently suggested a technique for reducing the flicker in Kylix programs that can be found in a sample application written by RAPWare. In my code, you can switch this code on or off by usings the {$DEFINE NOFLICKER} directive. If you remove this code and recompile, you will notice that the application shows a lot of flicker. Here is the flicker-reducing code:

  1. add QT to the uses part
  2. add these lines to the type of TMainForm:

    protected
     function WidgetFlags: Integer; override;

  3. add these lines to your program:

    function TMainForm.WidgetFlags: Integer;
    begin
      // To reduce flickering on LINUX
      Result := Inherited WidgetFlags or Integer(WidgetFlags_WRepaintNoErase) or Integer(WidgetFlags_WResizeNoErase);
    end;

The first release of Kylix is fairly rough and does not have the polish of the latest Delphi releases. Here are some problems I have discovered: