[Lazarus] Delphi-Lazarus compatible code including serial port?

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Oct 10 12:03:42 CEST 2010


On Sun, 10 Oct 2010 11:46:43 +0200
Bo Berglund <bo.berglund at gmail.com> wrote:

> I have a rather extensive comm unit created in Delphi for
> communication with a data acquisition instrument via RS232.
> The task is to port a project using this file to Lazarus on Linux.
> Thanks to advice here I have found a serial port component that works
> in similar ways to the one I have used in Windows, so now I am
> embarking on the porting task.
> 
> In the existing unit the serial port communication component is
> instantiated in code rather than being dropped on a form.
> 
> Now I believe I have two options:
> 1) Sprinkle the code with conditionams for Delphi/Lazarus and use the
> 5dpo component and its specific calls for Lazarus and the existing
> code for Delphi. This will be rather ugly since the comm object FComm
> is used in many places in the code.
> 
> or
> 2) Maybe I can somehow disguise the actual implementation of FComm
> from my existing code and instead create a 5dpo object in Lazarus and
> the other type in Windows, but give the wrapper the same properties
> and methods as the existing component has.
> This would involve wrapping 5dpo in a superclass, which translates the
> used properties/methods into 5dpo specifics.
> Then I would be able to select the proper one to make based on
> conditionals inside a different unit from my main unit.

Many projects did 2).

 
> But how would this be done more specifically? Is there some
> description available on making code compatible between Delphi and
> Lazarus when there are component differences in the two systems as I
> described above?

There are many ways. For example:

uses
  {$IFDEF LCL} // or use ifdef FPC
  fpcunit
  {$ELSE}
  delphiunit
  {$ENDIF};

or you can put the whole unit into ifdefs:

myserial.pas:

{$IFDEF FPC}
{$INCLUDE fpcserial.pas}
{$ELSE}
{$INCLUDE delphiserial.pas}
{$ENDIF}

 
> (I don't know if this is off-topic here and should be posted to the
> fpc list instead, but since GMANE does not yet allow posting to the
> fpc group I hope you will not be offended by me posting this question
> here. It seems like it is both a Lazarus vs Delphi question and one
> regarding subclassing...)


Mattias




More information about the Lazarus mailing list