Multiplatform Programming Guide

From Lazarus wiki
Revision as of 19:52, 12 December 2005 by Sekelsenmat (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page will be the start for tutorials with regard to writing multiplatform applications with Lazarus. It will cover both the necessary precautions to ensure that a program can be easely ported and the porting process for an already existing program. I invite others to help improve the article.

Introduction to Multiplatform Programming

Porting process between Windows to Linux

On Linux there is no "application directory"

One concern when porting applications between Linux and Windows is the file system. Many programmers are used to call ExtractFilePath(ParamStr(0)) or Application.ExeName to get the location of the executable, and then search for the necessary files for the program execution (Images, XML files, database files, etc) based on the location of the executable. This is incorrect in Linux. The string on ParamStr(0) may not only not contain the directory of the executable, as it also varies between different shell programs (sh, bash, etc).

Even if Application.ExeName could in fact know the directory where the file under execution is, that file could be a symbolic link, so you would get the directory of the link instead.

So what to do? On Linux you should use two different places to store configurations and resource files:

  • A fixed privileged location for the executable and resource files witch will not change.

This location can be something like: /usr/share/app_name or /opt/app_name

Most programs will be executed without root privileges and the fixed directory for a given application usually only available for the root user to write, so don't write on this directory. Only read information from it.

  • The user's home directory

You can create a hidden folder on the user's home directory to store configurations and resource files that may change.

Directories whose name begin with a dot (.) are hidden, so you can create a hidden directory on a place like /home/user_name/.app_name and then store configuration files there.