Typhon Programing Example - Process Messages

Let’s call Typhon. Our IDE pops up. If we were working on another project, it will open it as default. Otherwise we should create or open one. In this case we create one. At the menu select File | New…

A form pops up listing all possible kinds of projects. By selecting one of these, the project is filled up with template code by the development environment. Select Project | Application and Ok.

This creates an Application Project, with some already done code. To continue working on it we must save it in a directory like /home/user/Documents/Projects/ProcessMessages with name ProcessMessages.lpi and unit as unit1.pas at the current directory.

On Designer Tab, Unit1, we can see Form1 by default.

From IDE’s Components menu we add two buttons (TButton). One for Start and another for Stop, with these same captions. Then Add a CheckBox (TCheckBox) with Caption “Process Messages”. Add an Edit Box (TEdit), and fill Text attribute with text “10000”. Add a Label (TLabel) with caption “0”. Above the Edit Box put Label with Caption “Count”, and above the first Label add another label with Caption “Actual”.

Double click on Start Button, and code editor shows up.  Add the following code to the function:

procedure TForm1.Button1Click(Sender: TObject);
begin
     exitRepeat:=false;
      count:=0;
      repeat
          if (count mod 50)=0 then
               if CheckBox1.Checked then Application.ProcessMessages;
          Label1.Caption:=inttostr(count);
          inc(count);
      until (exitRepeat or (count>strtoint(Edit1.Text)));
end;

Click on the Designer Tab. Then double click on the other button, and add the following code:

procedure TForm1.Button2Click(Sender: TObject);
begin
      exitRepeat:=true;
end;

Also add the following variable declaration before implementation declaration and after Form1 declaration:

...
var
     Form1: TForm1;
      exitRepeat:boolean;
      count:integer;
implementation
...

Save with (Ctrl-S o Ctrl-Shift-S) and we are ready to execute our project, by pressing F9, or Run|Run. Our applications shows up running on top our development environment. At the same time, an executable was created at the projects’ directory.

Now, there is an application working. It doesn’t do much, but I’m going to explain what it is showing us more than it is doing.

If we want to generate the application for another environment (for example Windows) we can select the objective operating system. For that we click on Project | Project Options or (Ctrl-Shift-F11) and a new window shows up. We choose Compiler options | Config and Target.

For Target OS select Win64. Target CPU Family as Default, and Target Processor as Default. Also on Additions and Overrides set LCLWidgetType to win32. If you want to generate a new alternative from these options, just select them. Then click Ok. And choose Run | Compile.

If we look at Project’s Directory, there is a new Windows’s executable, ProcessMessages.exe. We can repeat the procedure for other operating systems. If it complains that doesn’t find a configuration file, I’ll show a solution later.

With this solution we can code once and compile for several environments.

Related posts