Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-08

Abstract class implementation on different platforms

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

How do I do the following using FPC with Makefile's or a Lazarus Package?

I have a TGfxCanvas abstract class (something like the TFPCustomCanvas class in the graphics.pp unit) and it gets implemented differently for different platforms. Currently Win32 and X11, but others will follow later.

How do I structure my source directories and units so that I can compile my library under both platforms with the same Makefile or Lazarus Package.

At the moment I have two different Lazarus Packages. One for each platform, but this is really not ideal, because if an application uses the Linux package, all is fine. Now if you want to compile that project under Windows, you need to change the Project Requirement, to now include the Windows package. :-(

I don't want to use IFDEF's in my code if possible. A bad example is the gfxbase.pp unit in Lazarus's LCL, which I think is a nightmare... It is full of {$IFDEF Win32} ... {$else} .... statements. What happens to all that code, when more platforms get added?

At the moment my library is in the following directory structure:

src/
/common <- some common units for all platforms. /x11 <- X11 implementation of TGfxBase /gfximpl.pp
/gfx_x11.pp
/win32gdi <- win32 implementation of TGfxBase /gfximpl.pp
/gfx_gdi.pp
/gfxbase.pp <- initial library unit (start of project)

The library includes a unit called "gfximpl.pp" which gets set differently for each platform, aliasing the classes to a common classname.

example "gfximpl.pp" for X11:
  type
    TDefWindow = TXWindow;
    TDefDisplay = TXDisplay;
example "gfximpl.pp" for Win32 GDI:
  type
    TDefWindow = TGDIWindow;
    TDefDisplay = TGDIDisplay;

So now any project using this library can refer to TDefWindow, and depending on which platform it was compiled, it will include the correct implementation of TGfxCanvas.
I still have the issue with the Lazarus Packages though. Each platform needs a different search path to find the "gfximpl" unit, hence the two packages (one for each platform).

Is there a better way to do this? Makefiles or Lazarus Packages? Surely it is done somehow in FPC considering it supports so many platforms...

Many thanks for any help.

Regards,
- Graeme -

There's no place like 127.0.0.1

Reply by email

Graeme Geldenhuys

Apologies! That unit came from a different project (LPTK) and not Lazarus. To many files open at once in the editor.

Regards,
Graeme

Vincent Snijders wrote 9 lines
Graeme Geldenhuys schreef: > I don't want to use IFDEF's in my code if possible. A bad example is > the gfxbase.pp unit in Lazarus's LCL, which I think is a nightmare... > It is full of {$IFDEF Win32} ... {$else} .... statements. What > happens to all that code, when more platforms get added? gfxbase.pp? Vincent
There's no place like 127.0.0.1

Reply by email