Sunday, June 27, 2021

FreePascal and Lazarus Development will switch to GIT

The Free Pascal and Lazarus teams are in the process of switching to Gitlab to manage their source code and issue reports.

In order to lower maintenance of their own infrastructure, a hosted solution
has been chosen, and an open source license was granted to the teams.

You can see the current progress at:

https://gitlab.com/freepascal.org

2 subgroups have been made:

https://gitlab.com/freepascal.org/fpc
https://gitlab.com/freepascal.org/lazarus-ide

Several testconversions of the SVN history to a Git repository have been
done, with ever improving results. All repositories will be switched to git.


A program has been written to convert Mantis bug reports to Gitlab issues;
it is very complete, and all available info will be converted.
You can see (partial) conversion results on the above projects.


The date for the final conversion has been established as the weekend of
17/18 july. People that wish to report bugs after that will have to create a
gitlab account in order to do so. (Those with a github account can normally
also use that account to log in with gitlab, see the gitlab login page.)

If you are a user on our Bugtracker (Mantis):

The conversion program will attempt to convert existing bugs using the
account of the new gitlab user. To map your gitlab user name (or ID) to the
mantis user
, we ask that you file an issue in the mantis project of the
current bugtracker, assign it the category gitlab, and set the summary of
the bugreport to your gitlab account name
or ID number (not both!).


All accounts that can be collected in this manner by 17 july will be used in the final conversion.


All necessary information to connect to gitlab will be collected in the FPC &
Lazarus Wiki. Several pages have already been set up:

https://wiki.freepascal.org/FPC_git
https://wiki.freepascal.org/FPC_git_concepts
https://wiki.freepascal.org/SVN_to_GIT_Cheatsheet

These pages will be updated with the correct URLS when the final conversion happens. The FPC & Lazarus websites will also be adapted with new instructions.

For the FPC & Lazarus teams,
Martin (Message originally by Michael)

Tuesday, February 24, 2015

Updates to LHelp the CHM help viewer for Lazarus

LHelp is the help viewer that is included with Lazarus to view the chm files usually included in releases.

Some time ago some changes were made so that when F1 is pressed and LHelp is started, LHelp would load several help files such as the Lazarus Component Library(LCL) the Runtime Library(RTL) the Free Component Library(FCL) and several others. This is nice because then it's possible to search all the open files for keywords.

The down side to this is that every time a chm is loaded, the Table of Contents updates and the default page of the help file was rendered. So it was very visible as each help file was loaded in LHelp and not very pretty.

Additions the the protocol used for communication between LHelp and Lazarus, made by Reinier Olislagers, allowed LHelp to load the files while it was not yet visible and then be shown afterwards. This worked well but there was a long delay in the time F1 was pressed and the time LHelp became visible. Almost ten seconds on a modern multi-core desktop computer.

Investigation into the cause revealed a couple of slowdowns. The major cause was the speed at which the IPCServer.PeekMessage routine was polled. Only every 200 milleseconds. Sending commands to open 10 files would take 2 seconds. Also it used the syntax if IPCServer.PeekMessage(5) then ... which was not ideal. Changing this to while IPCServer.PeekMessage(5) do ... allows it to handle another message immediately if one is available.

Another factor was the way that Lazarus looked up the chm files to open. It would collect all files in any folder that could contain a chm file without using a file mask. Adding a mask for *.chm files sped this up significantly.

Speedups in LHelp were implemented by adding BeginUpdate and EndUpdate to the protocol. This allows chm's to be loaded without rendering the default page for each chm as it's loaded. When the last EndUpdate is sent, the final requested help topic is the only one rendered.

All of this results in a startup time of ~2 seconds. A big improvement over 10 seconds. The changes are committed in the svn version of Lazarus and will be available in Lazarus 1.4 Release Candidate 2


Saturday, May 10, 2014

(De-) Bug wars - A new hope

 "This are not the bugs you are looking for"

Well hopefully in future it will get easier to find those parts of your code, that joined the dark side.
The Lazarus Team is currently working on improving the Debugger in the IDE. And not just improving, but adding an all new shiny debugger.
In fact not just one either.

Here is what we are currently working on. In future we will offer 3 kind of debuggers in the IDE.

  1. The existing gdb based debugger: "GdbmiDebugger".
    And it's variations for gdbserver, and gdb over ssh.
    We will continue to maintain them, as they support additional targets (arm, powerppc, ...) that the new debuggers do not (or not yet) have.
  2. A gdb free debugger: "FpDebugger".
    This is still in its very early alpha stage. So far it will be for Intel targets only. And initial work concentrates on supporting Mac (which no longer comes with GDB, and urgently needs a replacement), and Windows 32 bits. But Win64 and Linux are planned too.
  3. A hybrid: "FpGdbmiDebugger".
    Like the existing GdbmiDebugger it uses GDB. In fact it inherits much of the functionality from GdbmiDebugger.
    But it will have its own routines to evaluate watches itself (without GDB). So it will be able to deal better with Pascal data. As a side effect watch evaluation will also be faster.
    Other debugging tasks, such as running or stepping the exe, and handling breakpoints are handled by the GdbmiDebugger code using GDB.

    But why this one at all?
    The same watch evaluation is available when using FpDebugger?
    Well, with FpGdbmiDebugger being GDB based, it will be easier to support more of the targets that GDB can support (like arm). It will still need some additions (e.g. a reader for arm executables, to read debug info) in order to do this. And FpGdbmiDebugger also has the potential to be extended to be gdbserver based and support remote debugging in future.

    The progress of FpGdbmiDebugger can be watched on its wiki page: FpGdbmiDebugger on our wiki.
    A page for FpDebugger does not yet exist.

The two new debuggers are developed in our SVN version (1.3). And if all goes to plan, then they will be part of Lazarus 1.4 (Probably sometime in 2015)

May Pascal live long and prosper (Oops wrong source).
May the force be with Pascal.

Sunday, August 25, 2013

Threads with Lazarus

It seems every time I use threads in a program I make, I need to lookup again how threads work. So if you're like me perhaps this will help you.

Here's a more complete tutorial to read.

Threads are a great way to do a large amount of processing in your program while allowing the visual part of your program to remain responsive. If you can split up the processing into several threads you can take advantage of modern processors multi core capability and complete a job in a fraction of the time.

Lazarus programs can use threads in GUI and Console programs. If you use threading in your program you should define the compiler option -dUseCThreads. This can be done in Project->Options->Compiler Options->Other - Custom Options. This does nothing under Windows but on any *nix it includes a needed threadmanager. If your program crashes with the first use of thread.Start; then this is probably your problem.

Now that your program is thread enabled here's some basic information about threads. You must subclass the TThread type and make your own thread type and override the Execute method.

The Execute method is never called directly in your program. It is the method the thread will run on it's own when it is started. If you are using MyThread.Execute then you are making a mistake.

Here's a basic example of a new thread type

type 
  TFooThread = class(TThread) 
  protected
    procedure Execute; override;
  end;

... 

implementation 

procedure TFooThread.Execute;
begin
  // do stuff 
end;

 
To create an instance of your thread you can use

FooThread := TFooThread.Create(True);

The argument True creates the thread in suspended state, meaning the OS thread is created but not yet run. If you use False then the thread begins and Execute is called immediately.  You can of course make your own constructor with whatever parameters you need and use inherited Create(False) there.

To start a thread you should use FooThread.Start. FooThread.Resume is deprecated as well as .Suspend which is not reliable on *nix's and can cause your program to hang.

Now your thread is running and working and making your life easier. Your program is snappier and you decide that you need to make your program display the progress your thread is making processing some data.

So in TFooThread.Execute you add Form1.ProgressBar1.Position := SomeValue.
Bad idea. It may work or your program could immediately crash or it might cause some other harder to find error that happens later. Never ever do this.

The reason this is so bad is because the GUI part of your program is run in a separate thread (duh!) and has it's own memory area. Changing the memory in one thread from another needs to be coordinated carefully. You should never change a LCL control value from a thread other than the main process.

A way to update the main thread from another thread is the Synchronize(@SomeProc) method. The Syncronize method, which is called within a created thread, causes the thread to pause and wait for the main thread to call a procedure. Also see CritialSections from the link at the beginning of this article

When your thread terminates you should assume that any code in it's destructor may be called a thread other than your main process thread, especially if you set FreeOnTerminate to True. If you assign a handler for the OnTerminate property then that procedure will be run in the main thread.

After all the code in the Execute method is run your thread cannot be restarted. You will have to free and create another instance of the thread type you need. It's common to include while not Terminated do begin ... end around the code inside the Execute method in order to use a thread multiple times without having to recreate it.

Most of the basic stuff I have run into is now covered. Go code, or read some more: Threading Tutorial on the Wiki

Tuesday, August 28, 2012

Gtk3, GObject Introspection and Free Pascal

A while back the Gtk community started a project called GObject Introspection. In short it exports the Gtk and Glib api, as well as many others, to an easily parsed xml format.

The result is gir2pascal.

gir2pascal can create bindings to pascal from any library that supports gobject introspection in just a few moments! The result is that Gtk3 bindings have been created fairly easily for pascal and can easily be updated simply by running gir2pascal against the latest version.

Here is part of the XML code from the Gtk3.gir file relating to the caption of the button:

<class name="Button"
           c:symbol-prefix="button"
           c:type="GtkButton"
           parent="Bin"
           glib:type-name="GtkButton"
           glib:get-type="gtk_button_get_type"
           glib:type-struct="ButtonClass">      
      <implements name="Atk.ImplementorIface"/>
      <implements name="Actionable"/>
      <implements name="Activatable"/>
      <implements name="Buildable"/>
      <constructor name="new" c:identifier="gtk_button_new">
        <return-value transfer-ownership="none">
          <type name="Widget" c:type="GtkWidget*"/>
        </return-value>
      </constructor>
      <method name="get_label" c:identifier="gtk_button_get_label">
        <return-value transfer-ownership="none">
          <type name="utf8" c:type="gchar*"/>
        </return-value>
      </method>      <method name="set_label" c:identifier="gtk_button_set_label">
        <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
        </return-value>
        <parameters>
          <parameter name="label" transfer-ownership="none">
            <type name="utf8" c:type="gchar*"/>
          </parameter>
        </parameters>
      </method>
      <property name="label"                construct="1"
                transfer-ownership="none">
        <type name="utf8"/>
      </property>
 </class>
  
One improvement over the current (Gtk2) bindings in use is that Pascal objects (not classes) have been used in place of records. The advantage is that GObjects, a C style quasi-object, can be accessed in an object oriented way instead of the flat C functions we use currently.

Here is the corresponding generated pascal code from the XML above:

type
  TGtkButton = object(TGtkBin)
    priv3: PGtkButtonPrivate; 
    function new: PGtkButton; cdecl; inline; static;
    function get_label: Pgchar; cdecl; inline;
    procedure set_label(label_: Pgchar); cdecl; inline;
    property label_: Pgchar read get_label write set_label;
  end;

function gtk_button_new: PGtkButton; cdecl; external;
function gtk_button_get_label(AButton: PGtkButton): Pgchar; cdecl; external;
procedure gtk_button_set_label(AButton: PGtkButton; label_: Pgchar); cdecl; external;

implementation

function TGtkButton.new: PGtkButton; cdecl;
begin
  Result := Gtk3.gtk_button_new();
end;

function TGtkButton.get_label: Pgchar; cdecl;
begin
  Result := Gtk3.gtk_button_get_label(@self);
end;

procedure TGtkButton.set_label(label_: Pgchar); cdecl;
begin
  Gtk3.gtk_button_set_label(@self, label_);
end;

You can see that we are using objects instead of records, compare this to the current Gtk2 bindings:

type
  PGtkButton = ^TGtkButton;
  TGtkButton = record
    bin : TGtkBin;
    event_window : PGdkWindow;
    label_text : Pgchar;
    activate_timeout : guint;
    flag0 : word;
  end; 

function gtk_button_new:PGtkWidget; cdecl; external gtklib;
procedure gtk_button_set_label(button:PGtkButton; _label:Pgchar); cdecl; external gtklib;
function gtk_button_get_label(button:PGtkButton):Pgchar; cdecl; external gtklib;


Before, our code would look like this:

procedure Foo;
var
  Button: PGtkWidget;
begin
  Button := gtk_button_new;
  gtk_button_set_label(PGtkButton(Button), 'Hello World!');
end;


But now it's possible to use this instead:

procedure Foo;
var
  Button: PGtkButton;
begin
  Button := TGtkButton.new;
  Button^.label_ := 'Hello World!';
end;

As you see it's a bit shorter to type the second way. Although either will work since the 'flat' functions are still available to use.

Using objects instead of records it is of course possible to access inherited methods and properties with greater ease than before, especially when using the code completion feature of Lazarus (which is extremely close to 1.0 now!). Button in the example above descends from GtkWidget which has the property tooltip_text.

This can be accessed with
Button^.tooltip_text := 'Don''t click me unless you want to!';
whereas before you had to do
gtk_widget_set_tooltip_text(PGtkWidget(Button) ,'Don''t click me unless you want to!');  

Here's the HelloWorld example included with the bindings, modified to have a tooltip.


 The Pascal Gtk3 bindings are not yet well tested. There are a couple of examples in the Lazarus-ccr repository in the folder /bindings/gtk3/examples/ including an example of GtkWebkit.

Perhaps you would like to try it out :)

Thursday, August 2, 2012

Preparing for Lazarus 1.0 (RC1)

Just to announce: Lazarus is preparing to go 1.0.

The first release candidate for the new Version has just been made public on sourceforge. Please test it.

You can find the announcement for the RC here: http://forum.lazarus.freepascal.org/index.php/topic,17717
And a list of what changed is here: http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes

Friday, February 17, 2012

Pascal does a strong showing in the Linux Questions Members Choice

Of course that internet quiz is not something scientific but it is nevertheless good news. Both Pascal and Lazarus made a strong showing in the Linux Questions Annual Members Choice Awards, competing with software sponsored by huge corporations. Other software written in Lazarus also appeared in the show, such as Double Commander and LazPaint.

Let's start with Lazarus itself running against other IDEs:



And how Pascal / Object Pascal as a language fared well too (despite someone mistakenly having added it as "Free Pascal"). It is pretty hard to see because of so many multiple lines, so I added a bigger line connector, but anyone can check in the full description of the results here: http://www.linuxquestions.org/questions/linux-news-59/2011-linuxquestions-org-members-choice-award-winners-928502/



See also how Double Commander fared:



And LazPaint:



If there was a category for Accessibility probably the Virtual Magnifying Glass would appear =)

Felipe Monteiro de Carvalho

Wednesday, February 15, 2012

Exploring the iPhone

As all should know, since my previous post I managed to finish off all the missing bits and get a decent initial support for Android in the LCL. But of course we are not stopping there, so I started exploring the iPhone. I haven't yet done any programming, but I already found a lot of interesting thing. Many good things, but also many bad things.

So let's start with the good things:

I was expecting something similar to Android, just more expensive, but while the user interface is remarkably similar, I must say that Apple has an extremely good taste for designing things. Everything in the iPhone is just beautiful. Each small detail seams well though out to look good, while in Android everything exists in a similar shape, it just looks OK in Android while it look great in the iPhone. Sure that some manufacturer like HTC and Sony Ericsson changes radically the user interface and even UI widgetset look, but in all cases they don't come close to looking as good as the iPhone.

The available RAM in the iPhone is pretty excellent. The iPhone 4 comes with 512MB of RAM of which aprox. 300MB are free for user applications. That's a huge amount in comparison to Android devices where you might even have 300MB or RAM, but the system is already eating 250MB =( The iPhone is also free of all that crapware which manufacturers like to fill the scarce ROM memory of Android phones, and the iPhone has a huge common memory for both media files and applications, which makes it able to run bigger apps without problems.

Now some things which are different:

The start screen is nearly identical with horizontal scrolling except that the iPhone home screen is much less configurable. You cannot place those nice widgetset to turn on/off mobile network or WiFi on a single click. The iPhone is also not very intuitive to use at times, with only icons and no perceived way for me to find out what an icon does except by guessing or testing, while in Android text labels are used much more often. There are no hints either.

And now the bad:

Frankly I am appalled that I have never heard of the evil side of the iPhone before. Why is nobody commenting that?? Am I the only one deeply bothered by this!? For me this was so terrible that I will never buy an iPhone again, for sure my next smartphone will be Android again. The iPhone is just the most restricted device, the most DRM filled, the most anti-freedom, the most monopolist, the most anti file owning device I have seen in my life. Let's start with the basic. On Android you put a SDCard in the phone and then you connect it with a USB cable to the computer and voilà! It opens as a mass media device with zero drivers installation in *any* operating system. Windows, Linux, Mac, works just as great in all! Then you can copy your music there, copy APK packages, you can copy your personal documents, you can copy source code, I don't know, you can do whatever you want! Sadly Android doesn't come with a File Browser but you can easily install the "OI File Browser" and then with it you see all your files on the phone and manage them. You can install any app to read your files. You can use the phone as a pen drive, you can create a new application to open, view and modify any file extension in the world and share that application. You can share your files. That's freedom! That's general computing! The freedom that any computer should offer.

And the iPhone!? Where are the file managers? I haven't yet found a single one which will show my photos, movies and music. WTF!?!? There are some file managers which require installing extra programs in the desktop and essentially are a sort of hack around the limitations imposed by Apple. Is music just a product you consume from bigshot producers? Can you even run you own music there? Where is my freedom to run my MP3 which I generated myself from a CD I bought in Paraguay? Those guys are not in the iTunes Mr. Jobs and I don't want to restrict myself to your iWorld. Cloud storage as an extra option, OK, but ban file owning, copying and sharing!? That's the evil dream of any monopolist. I don't want to be part of that evil iWorld, I want a general computer. But that's what the iPhone certainly does not want to be.

So, well, let's say you are conformed with the iPhone having zero file owning capabilities. What's next? It only docks to your computer via the iTunes after installing a plethora of drivers and does not work at all in Linux. You cannot freely install applications which you wrote yourself without joining the Apple Developer Program and go through a complicated process. In Android you can write apps and share them easily without any of this non-sense.

And to make it worse: Apple is monopolistic. It banned 3rd party browsers. Where is the freedom? I don't want to be stuck with Safari. I already like Opera Mobile, but they banned it. Sure there is Opera Mini, but Mobile is much more what I want.

So here we are: A superb phone, the best looking GUI and design I have ever seen. Excellent quality of the touch screen. All ruined by monopolistic, anti-freedom non-sense! All ruined by a company which wants to ban people from owning files.

Felipe Monteiro de Carvalho

Friday, November 25, 2011

LCL for Android

As the maintainer of LCL-WinCE of course I was quite shocked when Microsoft dropped Windows Mobile into the limbo and announced that native applications would be restricted to a very small list of favorite partners. Because of this, since almost 1 year now I have been trying to port the LCL for Android.

My first success was in 19th January 2011 when I first built a good x86-linux -> arm-linux cross-compiler which I have been using ever since and I hosted here: http://sourceforge.net/projects/p-tools/files/Free%20Pascal%20for%20ARM/

After that I slowly started exploring Android and the SDK with many pauses. My free time floats a lot depending on the work load, my mood and my current interests. I have other hobbies which alternate as my biggest interest from time to time. The most important ones are: trains (reading news and discussing in skyscrapercity as well as travelling), politics (I'm right wing / conservative), keyboard playing and Pascal programming.

Ok, so next thing around in August I got some bounties which motivated me to make a good push. When I started we were in Android 2.2 still, and I bought a HTC Wildfire which came with 2.1 and can be upgraded only up to 2.2. At this time the perspectives for native applications were quite doomed, you had to interface with Java via the horrible JNI, I got pissed off by that and I developed an alternative system which worked by running a native executable and communicating with pipes with a Java machine. I posted about it in the android-ndk Google group and the Google guys hated my idea, they told me to buy and iPhone and try programming for that instead =D Well, I could do that, but seriously the Lazarus community is on a high mood for Android support, I don't remember yet anyone asking about iPhone support ... even requests of WebOS and Bada were heard. My hacky development strategy might sound like a bad idea, but I had many motivators for it:
1> If you can only have a library then the way LCL applications work changes dramatically =( I'm not sure yet how this will be worked around. You cannot keep the same main project file if Android requires a library and you also need changes in the project code flow.
2> FPC has a lot more bugs for library development then for executable development, specially in ARM-Linux
3> Using my method I could access the entire SDK without JNI! A true blessing. So I could quickly push some controls and get things working.
4> I also hoped that if people pushed then Google would flexibilize and support executables, but now I think I was too optimistic. At that time Android 2.3 was released and it brought a lot of improvements for native applications, but ever since there were very few changes in the NDK, so I lost my hope that Google would support native executables.

The alternative way would be creating a native library which draws all controls, and there are enourmous challanges in doing this. So, fast forwarding a bit into the future, after a bounty I got some expertise in NDK development with OpenGL so I got quite animated and I started a huge push to see how far I can push LCL-CustomDrawn until I run out of steam.

These days I feel like soldiers must have felt in the Market Garden operation, running against time to take all bridges in the way. I am not trying to consolidate the entire area, I just need to make as many breakthroughs as possible in as many key areas as possible to make sure that my development strategy works. Every time that we start doing something which was never done before, like LCL in Android you have a huge uncertainty about whether or not it will actually be possible to work, or if I will face a huge wall somewhere, like a compiler bug or a problem which needs a lot more steam then I got to solve ... so I want to clear the way and establish that my strategy indeed will work.

So far I have already taken the following bridges:

1> Lazarus Custom Drawn Controls - The first one to be tackled, it is far from complete, but I advanced it so well and so fast that it is clearly proven that we can have our own set of custom drawn controls inside Lazarus

Reference: http://wiki.lazarus.freepascal.org/Lazarus_Custom_Drawn_Controls

2> Developing the major structure of LCL-CustomDrawn to allow painting with a non-native Canvas into a native surface. I already implemented this for Win32, X11 and Cocoa, so we are quite advanced here.

3> Develop a system to clip the painting of sub-controls and also clip events from sub-controls inside a form. In LCL-CustomDrawn TWinControl will be non-native, because some platforms like the Android surface do not support it. I have achieved success here too.

Now I am trying to push into a last bridge, which is resisting heavily:

4> Achieving a minimal LCL-CustomDrawn application which can run in Android and paint at least a rectangle or something.

I am facing big challanges in this task, the major ones being that when I simply include the LCL the application starts to crash, even if I don't call anything from it =( I have narrowed down to cwstrings, which is a major source of crashes, so I disabled it, but now the application crashes when clicking on it. I tryed to comment out all initialization sections in the LCL, but it didn't help. My greatest fear is a compiler bug somewhere which would reproduce only in big programs like LCL apps and stop me =( But so far it appears that I am going well, let's hope we will succeed here and clear 1 more obstacle in this difficult road.

Edit: I managed to get it working now, the second problem was introduced while debugging the cwstring issue. Now it works fine =) So we are each day closer to have LCL-CustomDrawn running in Android. From what I can see my snapshot compiler has no bug which could defeat us, so the path is ready =)

Edit2: Now it loads the application and it can draw some green stuff =D Really exciting days for LCL-CustomDrawn-Android. It still doesn't do anything useful, but the entire fact that it loads without crashing and can render something is excellent.

Monday, May 16, 2011

Remember, Remember ... The History of Debugging


Debugging your application can be an intriguing task. And analyzing what happens in your application, and what went wrong (or maybe right), often requires the developer to keep an eye on quite a lot of data.
Sometimes that means not only to look at the data as it is on the current step of execution, but also to compare it to what it was on the previous step(s).





Lazarus does now provide a history overview for watched values, locals, and call-stack. Each time your application stops, a record of this data is made and stored.
By default Watches and Locals are recorded for the current stack-frame/thread. But if you browse other frames or threads by selecting them in the stack or threads overview windows, then Lazarus will notice this and keep track of those too.

A new debug window "History" provides access to all recorded values. Currently this is up to 25 history entries. And you can even browse the history after you program terminated.
If you have a history entry selected, you can use the stack-window to change the current stack. If any data was collected for the selected frame, it will be shown. Currently data for extra stack frames is only collected if the frame was selected, while your app was running, and if the watches or locals window where open and active.

There is however a little twist to it. Collecting all the data takes some time. To avoid any slowdown of the debugger, this new feature works on idle time only. It collects data, only if the debugger has no other work. This even means that you can continue the execution of your application, without having to wait the full time it would have taken to get all the data. In this case the snapshot will be incomplete.
If you want to ensure complete snapshots, you can open the watches, locals and stack window, and observe when the information has been fully fetched, as it gets displayed to you.

This feature is available in Lazarus 0.9.31

Monday, November 15, 2010

Profiles for Build Lazarus

The dialog opens from Tools --> Configure "Build Lazarus".
It is meant for building Lazarus or parts of it, using the given parameters.
The original dialog looked about like this.



The dialog was made by the same developers that actually use it all the time. Thus the GUI is little confusing, it's main design goal was not "ease of use".

Then some people made an effort to simplify the GUI. They didn't touch the original GUI but instead added another "Quick" tab sheet to the dialog.



The original GUI was named "Advanced" tab sheet (as seen in the first picture).
A problem was that this Quick page was not very intuitive either.
There were radiobuttons for options which is OK but then also 2 settings for LCL Interface, Target and IDE. They were never both enabled at the same time. So weird. If some Lazarus user really was so "non-advanced" that he needed this simplified page, how could he understand the difference between Target and IDE LCL Interfaces?

The worst problem however was that the Quick settings modified directly the Advanced settings, but there was no visual feedback about it. It took some time to realize it. A generally accepted GUI convention is that tabs have individual separate sheets. I remember I started using the Advanced page very soon although I was not an advanced user yet. I dare to say very few people used the Quick page.

Already a year ago I created a big patch implementing Build Profiles. It kind of extended the idea of quick selections and made it configurable. It also made the GUI more intuitive. In fact the sane GUI was my main motivation, the profiles were more like an extra bonus.
It was my first substantial patch for Lazarus and I had to study lots of code for it. At the same autumn I had started evening school (although I am not young). Now I can reveal that I made the Lazarus patch partly when I should have read to my math exam. Under pressure my mind goes into a hyper-active state or something. A psychologist could maybe explain it better. Anyway, I scored well in the math exam, too, no problem.

My feature got attention and mails were written but it was not accepted. Actually I created many versions of the GUI based on feedback.
The first version had everything at the same page in 2 panes, Profiles pane and Details pane. That was intuitive but big and crowded.
The second version had a clear list of profile names and a button that opened a details form for the selected profile. That is still my favourite. It is the most intuitive GUI for such things.
It was rejected because the (hard-)core developers want to use the settings as before. The dialog has to be "settings oriented", not "profile oriented". The third version (= the current dialog) follows that idea.

For a while the patch was forgotten but I salvaged it using a local git branch. Recently, finally, it was accepted to Lazarus trunk! After that it was changed some more based on feedback. Widgetset is now selected using a combobox instead of radiobuttons. Options have more room in a multi-line memo and there is a user-configurable list of defines to select from. Etc...
The latest (for now) version looks like this:



There is another dialog for managing the profiles:



I got positive feedback especially from people who cross-compile. The GUI is still complex but it is intuitive and very usable.

A more philosophical point can be made, too. GUIs should be designed and implemented by different people. As a mind-set, GUI design is more close to graphics design than to computer programming.
If no such designers are available, at least comments from outsiders (not Lazarus user) should be listened. I noticed myself that one gets used to confusing GUIs very quickly. A month or two passed and I didn't pay attention to it myself.
Open source projects with financial backing usually concentrate more on visual appearance. And commercial SW, too, of course, but sometimes they consider visual appearance more important than code quality which is not good either.


Juha

Monday, September 27, 2010

Delphi Converter improves

Converter has taken a big step forward during the past few months. The main features I had in mind are now implemented. Most details are configurable in Settings dialog. All settings are saved in file delphiconverter.xml in local Lazarus configuration directory and thus are persistent.

This is the settings dialog:




There is a wiki page with detailed explanation of conversions: Delphi_Converter_in_Lazarus

Here is a brief list of them.

Conversions for Unit file


* All unit source files get a {$mode delphi} directive. It makes the compiler support language syntax exactly like Delphi has it.

* {$R *.DFM} is replaced with {$R *.lfm} if the form file is renamed and converted. Conditional compilation is used if the target is "Lazarus and Delphi".

* Unit names in Uses section and include file names are fixed to match the real case sensitive name found in the file system. This is needed for case sensitive file systems.

* Some unit names in Uses section are either replaced or removed.

* Some Delphi types are replaced with "fall-back" LCL types (same as in form files).

* Some function names called in the code are replaced.

Conversions for Form file


* Older Delphi versions used a binary format for .dfm form files. The converter always converts them to ascii text format.

* .dfm form file is renamed or copied to .lfm and converted as needed. There is also an option to use the same Delphi form file directly. See section Target below.

* Unknown properties are removed.

* Some Delphi types are replaced with "fall-back" LCL types (same as in unit files).

* Top and Left coordinate offset adjustment for controls inside visual containers.

Implementation details


Codetools are used a lot when changing the source code and .lfm form file.

One challenge was to replace function calls inside the source code, using parameters from the original call as defined in configuration. Codetools create a parse tree of the code but it includes only definitions, not function calls or other code constructs.
It means that the source code must be parsed char by char when looking for function calls to replace. Fortunately there was TFindDeclarationTool.FindReferences which I could use as the base for my TConvDelphiCodeTool.ReplaceFuncCalls. I copied the code, studied and debugged it for some time, then stripped useless parts out and added more code for replacing the function calls.

Another challenge was adjusting Top and Left coordinates of controls inside visual containers.
I based my TConvDelphiCodeTool.CheckTopOffsets on TStandardCodeTool.CheckLFM.
Again, I copied, studied, stripped, modified and added code.

The huge code-base of codetools looks first almost incomprehensible. The code browsing features of Lazarus are a big help here. They let you jump around code with no delays. After jumping and debugging for some time the code starts to make sense, piece by piece.

It is funny. When you first look at complicated code in a big project, you think: "oh, who is able create such code?". Then you make some code yourself and then have a month or 2 pause, and then look at the code and think: "oh, who has made this? Must be a clever person! ... oops, it is my own code...".
I guess other coders have similar feelings. Nobody can handle big amounts of code at one time. Sometimes you concentrate on the big picture and forget the details, sometimes you fiddle with the details and forget everything else.
In the end, for an outsider, the code may look like some intelligent person had made it. :-)

Juha Manninen

Wednesday, June 2, 2010

User defined color-schemes

As the lazarus community grows people yearn for more customizations to please their personal habits.



To help creating a wider choice of readily available settings, user defined color schemes have been introduced.

So now, your community needs you.

Get the latest Lazarus snapshot, load your favourite color settings (or create the perfect scheme from scratch) and then make it available to all of us. All you need is press "Export", enter a Name and save it.
Upload it to your home page, or a place of your choice and link it on our wiki so everyone will find it.

Thursday, April 22, 2010

"Page-Locking" or "multiply Editor-Windows (part 2)"

Following up the article about "Using multiply Editor-Windows", let's look at some more advanced scenarios.

You may want to use two editors, so that one shows you the interface of your class, while in the second you can work on the implementation of it.


The only thing is, once you have carefully positioned the first editor, you must always make sure, that you don't move it by accident. If it gets focus and you trigger a jump-to-implementation (or a jump to history/bookmark in this file), it will move away from your chosen location and you have to re-position it again.

This is where page-locking comes in. You can tell Lazarus, that it shouldn't move this editor away from your chosen location. The context menu has an entry "Lock Page" which will toggle the lock for the page. If the page is locked the entry in the context menu has a checked mark, and the editor tab will show an "#" in front of the file-name. (The command can also be assigned to the keyboard.)

Once your page is locked, Lazarus will no longer move it to other locations. You can still go to the editor and use the cursor keys or page up/down to reposition it. But if you try to jump between interface and implementation, go to declaration, bookmarks, etc, the IDE will automatically change to the other editor showing this file and move the other editor to the location you want to see.

So now in the example with the class declaration in one window, you can choose any method declaration of the class in the fixed window, and then trigger a jump to it's implementation. And it will always end you up in the 2nd window, in which you want to edit the code.

But what if you are in the 2nd window and jump back to the interface of your class? You don't need to have both windows showing the same code. By default Lazarus will recognize that your first (locked) window, already displays the interface. And the IDE will take you back to this first window.
Lazarus offers you some settings, to change this behaviour, if you like a different behaviour. (See Options / Editor / Multi Window)

And what happens if you accidentally lock an editor that has no 2nd view of the file? or you lock all editors of a given file? If that happens, Lazarus will open a new editor in a new tab (in an existing or even in a new window) for you. And if you don't like that, you can change the options so lazarus will ignore the locks, if this case arises.

Tuesday, April 20, 2010

Using multiply Editor-Windows

During development a programmer encounters many different tasks. Some of them require you to work locally on the implementation of a single method. Code completion and hints can provide you with anything you need to know about other methods or objects that you access.

Other work requires you to frequently work on many different places in your code. Refactoring is a good example:
  • Comparing different methods side by side to find duplication.
  • Extracting functionality and moving it to a new location. Viewing both locations at the same time.
  • Changing the interface of your class, viewing interface and implementation next to each other

Multiply Windows

Lazarus can now open as many Source-Editor-Windows as you want, and you can freely move files between them.

Each Window offers you the same functionality as the current Source-Editor-Window. Each window can hold one or more files, accessible through editor-tabs.


You can move a file by using the context menu and selecting "Move to new Window".
Once you have more than one Window open, you can also choose "Move to other Window".

Or you can drag and drop the editor tabs between the windows. If you prefer using the keyboard, you can assign your own key-shortcuts.

If you often have a window with just one tab open, you may find it helpful to hide the tab header and get more space for the editor. An option to do so can be found on the misc editor options.

Editing the same file in multiply Windows.

Sometimes it is not enough to view two different units side by side. Sometimes you need to see different parts of the same unit.

Lazarus can do that too. You can open as many editors for the same file as you want.
Choose "Copy to new Window" from the context menu. Or once you have several windows open drag and drop while pressing the CTRL key.

How it works:

Lazarus will keep one single instance of the file open. This instance is shared by all the editors that you opened for this file.
If you type in one editor, the changes are always made in all open editors at the same time.

Actions like saving or reverting your code always act on the file. It does not matter in which of the opened editors you trigger them, they will affect all the editors that display the file.


Other actions are done per editor. For example you can select a different block of text in each editor, and the selection(s) will be kept while you can edit the text in an other editor.

Limitations

Lazarus only allows you one copy of a file per window. You can not have two tabs with the same file in the same Window. But you can open as many windows as you like, each having one copy of the file.

Undo information is combined for all editors of a file.
For example: Modify a file in one editor, then do further modifications in another editor. Now go back to the first editor. If you press undo in the first editor, it will first undo the changes of the other editor, before undoing the changes you applied in this editor.

This is necessary to avoid conflicts. If you had inserted text in the first editor and then deleted this text in the 2nd editor, it would be impossible for the first editor to undo the insert, because the inserted text is no longer there.

A word about adding more windows to Lazarus.

Many people feel that the Lazarus IDE already has to many Windows, and efforts should be made to reduce the amount. So why adding even more Windows?

Very simple. Using multiply Windows did offer the highest amount of flexibility for now. Having to implement all this with splitters inside a single window would have added serious amounts of extra work or more likely cut-backs on the flexibility of this feature.

Once Lazarus will have docking, the Source-Editor-Windows will benefit from this as well.
On top of that there is of course room to think about specific optimizations, such as splitting a single tab, for two views of the same file. When and if this will be done, remains to be seen.

Thursday, April 15, 2010

Delphi Converter

The converter has improved during past few months. The main focus has been in Delphi project conversion. Delphi package conversion should get most of the same improvements automatically but it is not tested much.

I think Delphi converter is a very important piece of Lazarus because new people coming from Delphi often want to try it. They get their first impression of Lazarus from it.
When I started to learn Lazarus last year, it was one of the first things to test. Then it failed to convert most projects. Its quality was not equal to the rest of Lazarus.

On February 2010 I got write access to SVN trunk converter directory. I made the converter code more object oriented. Using object member variables instead of function parameters made it easier to extend the code later. I refactored the code heavily, actually more than really necessary, partly to organize it better and partly to learn what it does.

The initial dialog shows there are three possible targets for the conversion:
* "Lazarus/LCL" -- One way conversion.
* "Lazarus/LCL for Windows only" -- Does not remove or convert windows specific unit names.
* "Both Lazarus/LCL and Delphi" -- Tries to maintain the code compatible with both Delphi and Lazarus using conditional compilation.



Source file conversion


Initially the main goal was to reduce messageboxes and other notifications. Converting a big Delphi project was not realistic because there were so many messages. Now useless questions are removed and notifications go to IDE messagewindow.



Earlier it was possible to comment out not-found unit names in USES section. Now that is extended. The user can either comment them out or search for a unit path during conversion. If the units are found, their path is added to project settings. If user chooses to comment them out, the same units are then commented automatically in following source files.

Used unit names can also be replaced by other unit names. Regular expression syntax for replacement is supported.


Form file conversion



The other big part of conversion is the DFM form file conversion. Some properties of Delphi components do not exist in the equivalent LCL components. They can be deleted, either automatically or interactively.
A bigger problem are Delphi components which don't exist in LCL at all. It is important to replace them with a "fall-back" LCL component, especially if they are containers and have more components inside them.
Now the components can be replaced and regular expression syntax is supported, just like for unit name replacement.



Issues


The converter is not ready yet. These are some issues and problems I must solve.

Replacement names for both units and components are hard-coded. Soon they will be stored in a XML configuration file and the user can edit them.

A complex codetools function CheckLFM is used for scanning the form file. It stops working when there are errors in source. There are often errors in a unit under conversion so this is a problem.
I must study and fix the codetools functions or even replace them with something.

Replacing a component with a "fall-back" LCL component leads to more unknown properties. It must be solved somehow.

Juha

Friday, February 12, 2010

Work on 0.9.30: changes in resource handling

One of the big changes we have in the svn trunk (you'll get it with the 0.9.30 release) is the modified resource subsystem. Since the first time I tried Lazarus I felt a big displeasure regards the resource handling. I believe you had similar feeling too if you are an old Delphi developer. The main problem was that each lfm stream (Lazarus form) must be duplicated in a .lrs file which is included in unit initialization section. What is bad in this?
  • First of all lrs needs to be stored with your project and therefore eats the free space.
  • The second bad thing is initialization section - a special routine which is called on your program start. Thus your application will run 200 routines at the start if you have 200 forms. Not very nice if you care about the speed.
  • And the last is the amount of memory required for resources and how this memory is allocated. Lrs resources are stored both in the code of your executable (which loads on start) and a TList. Thus each resource is stored twice. Moreover when you add a new resource TList code needs to reallocate the memory used for all resources it has (look at TList.Grow).
All these problems are perfectly solved by the native resource support which is finally implemented by FPC 2.4.0 Starting from 2.4.0 release of FPC it is possible to include a form resource using the {$R *.lfm} (or {$R *.dfm} if you want to include a Delphi form resource) directive. Of course we don't need to store lrs file anymore, we don't initialization section and each resource is stored once in some section of your executable.

Since this way of resource handling is more effective we decided to use it by default in Lazarus. Of course we don't deprecate or remove in anyway lrs support. You are able to choose how to store the form resources in the project options dialog.

Warning: FPC 2.4.0 has 2 small bugs which are already fixed in the svn trunk (revisions 14805 and 14824). It opens all the resource files during linking and if you have small ulimit value you may see a linker error. To workaround the problem set ulimit to a bigger value. The second problem is that your project can't contain special symbols (like spaces) in the path.

Another rework we've made regards resources are the xp manifest, version info and project icon handling. Previously we created up to 5 files to add those resources to an executable: lrs file with an icon resource, rc file which included in turn manifest, version info and project icon files. So you had a whole zoo in the project directory. Now you have only a res and an icon files. We are building the res files ourself using the new FP package fcl-res. This mean also that we don't need finally to use windres. Res file is now used for all platforms while previosly rc was used for windows only and lrs for other platforms.

Warning: you need to remove {$ifdef windows}{$R you_project.rc}{$endif} from your lpr file manually (if you have it there). Maybe we'll implement a way to detect and remove that automatically before the release.

I want to summarize what advantages we have with the new resource support:
  1. Less garbage in the project directory and smaller size.
  2. Smaller and faster executables (because of no initialization sections).
  3. Less memory usage.
  4. Unified resource handling on all platforms.
As as special bonus for component developers I can note a possibility to use one form resource for both Delphi and Lazarus which can be included by {$R *.dfm} :)

This is a resource handling revolution, isn't it?

Tuesday, June 23, 2009

Vote for Lazarus

Thank you, people from the Lazarus community! For the first time of our project history Lazarus has been nominated for SourceForge's Community Choice Award in the category "Best Tool or Utility for Developers".

Grab your chance to let others know how much you like Lazarus by voting for Lazarus. Spread the news and don't forget to vote, this time to make us winners.

Wednesday, May 13, 2009

Changes with Button Glyphs

If you ever worked with the Lazarus IDE under windows (or just compiled an LCL application for windows) you were probably sickened by the glyphs on the dialog buttons since it is not native for windows. But on linux all is vice versa - most of the buttons have glyphs (and for example gtk and qt suggest an appropriate API to query "stock" images for buttons with various actions like save, open, apply, cancel, ...).
Therefore I needed a solution which can satisfy both windows and linux users. I started from the TBitBtn class which represents a button control with an image inside it. What I have added is a new property "GlyphShowMode" with 4 states:
  • gsmAlways
  • gsmNever
  • gsmApplication
  • gsmSystem
It is clear what the gsmAlways and gsmNever states are for: gsmAlways - to show the glyph always and this is how it worked before, gsmNever - to show the glyph never. Well, you may ask: What do I need the gsmNever state for, if I can use a TButton instead?. And I would answer: TBitBtn is not just a button with an image. It also has a Kind property which is very useful to set the ModalResult and Caption of a button :) But let's return to the other modes. gsmSystem can be used to show glyph depending on current OS - on MS Windows glyph will not be shown and on other system it will. And the last mode which is also default for this property - gsmApplication. In this mode TBitBtn (well, not exactly TBitBtn but TButtonGlyph) will look at the Application object for its value.
So, you can control the visibility of all button glyphs using the Application object. How? There are 2 ways: at run time by changing the Application.ShowButtonGlyphs property or at design time by changing the same property for the TApplicationProperties component. TShowButtonGlyphs is an enumeration too with following elements similar to TGlyphShowMode:
  • sbgAlways
  • sbgNever
  • sbgSystem
The default value for the ShowButtonGlyphs property is sbgAlways and not sbgSystem as one may expect. The reason is compatibility with old applications. Developers don't like surprises after a development tool upgrade and the loss of images is not a nice surprise. Anyway, it is not difficult to change the behavior of your application.
One more thing - glyphs are always visible when you are designing your forms. The glyph visibility mode is applied to the controls only at run time (when you start your application).

And now with regards to the Lazarus IDE. After this change the IDE on windows does not show glyphs on buttons by default, but if you really liked them, you can ask IDE to return them. You need to open the IDE options dialog and select Desktop settings:

Tuesday, April 21, 2009

No updates on the 0.9.26 fixes branch

I have decided to stop merging revisions from Lazarus trunk to the fixes_0_9_26 branch. There are two reasons:
  1. The differences between trunk and the fixes branch have become too many, over a thounds revisions. It is difficult to oversee their relations and dependencies, so I cannot guarantee the quality of the fixes branch just by looking at the patches and revision logs.

  2. I want to focus on the 0.9.28 release rather than maintaining 0.9.26.3 and working on a 0.9.26.4 release.
That said, it doesn't mean 0.9.28 is almost ready, a lot of work still needs to be done. The list of issues with that we want to fix before the 0.9.28 release contains about 50 items.

So, from now on nobody from the current Lazarus team maintains the 0.9.26.3 branch. If somebody from the community is using the Lazarus fixes branch on a daily basis and want to extend its life, then that is possible. The new maintainer would supply me a list of revisions to be merged and tests the fixes branch. I would do the actual merging and keep the snapshots of the fixes branch alive. If you are interested, you can contact me and we can work out the details.