Tomas Hajny wrote 25 lines
Marc Santhoff wrote:
Hi,
> I' like to know how I should write code for different system. SInce I'm
> no Linux user nor have any experience on MacOS I need to know how to
> wrap platform dependant code.
>
> Since I'm still fiddling with reading the serial port I have the idea
> that linux and even MacOS may be very similar to my main os FreeBSD.
>
> I do know Win32 is different, but how similar are the other os'ses?
>
> Is there any code in the FCL or the like I can study for getting my
> ifdefs right?
If you really want to create it prepared for current and future platforms,
don't do it via IFDEFs first of all. The procedural solution would be to
design a logical layer for functionality you need (get permissions for
accessing port, open port, set characteristics, read data, write data,
close port) in common interface part of a unit created as an include file,
possibly create (an)other include file(s) with shared parts of the
implementation too and create standalone units for the different platforms
you need to support.
This is what I'm beginning to do at the moment, after some information retrieval about how serial ports on Win32 work I've come to the conclusion that porting the unit rtl/unix/serial.pp would be the best thing for my special task.
I'm only bothered by the design of that stuff, no result codes (procedure not function) in some important areas. But I will not make changes breaking old code, I hope some exception throwing will do ...
Show quoted text 5 lines
Alternative solution (slightly more OOP-like and, somewhat easier to
implement and providing more flexibility) is to use create a "manager"
record for your particular functionality - see e.g. the heap management
and thread management routines, plus keyboard, mouse and video management
provided in units of the same name.
Yes, if I had to design it from the start I would think about making it a really universally usable and technically perfect solution. But for now my goal is to get some very simple communication running on windows (slow, no handshake).
Thanks,
Marc