[fpc-devel]Method overloading

Peter Vreman peter at freepascal.org
Tue Apr 29 12:55:03 CEST 2003


> Hi!
>
> I've got another problem with the compiler. Stripped down the problem,
> it comes out that the compiler doesn't work correctly with overloaded
> methods.
>
> For example: Serial transmission of data, a base class:
>   CSerialInterface
> which implements some methods for sending.
>   Send(Buf:Pointer;Length:LongInt); virtual; abstract;
>   Send(St:String);                  virtual;
>   Send(Buf:CCharBuffer);            virtual;
> (CCharBuffer is a class which is a "smart" char buffer)
>
> Each serial interface type gets a descent class.
> Type CRS232 = class(CSerialInterface) ... End;
> Type CRS485 = class(CSerialInterface) ... End;
> Type CRS422 = class(CSerialInterface) ... End;
> (as examples). They only implement Send(Buf:Pointer;Length:LongInt);
>
> And CSerialInterface implements the other Send methods which are only
> wrappers for the above one (look at "virtual" and "virtual abstract"
> declarations in CSerialInterface):
> Procedure CSerialInterface.Send(St:String);
> Begin
>   Send(@St[1],Length(St));
> End;
> (and analogous for the CCharBuffer method).
>
> CRS232 now has 3 Send methods:
>   Send(Buf:Pointer;Length:LongInt);     { implemented there }
>   Send(St:String);        { inherited from CSerialInterface }
>   Send(Buf:CCharBuffer);  { inherited from CSerialInterface }

Please try it with 1.1 compiler. Also for inherited overloading you need
to specify the overload keyword explicitly.





More information about the fpc-devel mailing list