[fpc-devel]Class definition overrides definition in implementation

Ralf Paaschen paasch01 at marvin.cs.uni-dortmund.de
Fri Mar 15 11:28:41 CET 2002


Hi,

the following example program demonstrates the situation.
Have a look at the comment at the beginning of the code:

--- SNIP --- HERE FOLLOWS THE CODE ------------ SNIP -------


{
 This is a small example program.
 The Function "getComment" is declared in the following way:
 in the class          :   function getComment : AnsiString;
 in the implementation :   function Parser.getComment : char;
 
 Nevertheless the program seems to compile and work correctly.
 
 Compiler was    : Free Pascal Compiler version 1.0.4 [2000/12/18] for
i386
 Operating System: Linux
 Compileroptions : -Sd
 
 Note: The Borland Delphi compiler complains about this situation. 
}

program test;

type
   Parser=class(TObject)
   public
      function getComment : AnsiString;
      //function getComment : char;
      function setComment(_text:AnsiString);

   private
      Comment: AnsiString;
      
   end;
   
   function Parser.setComment(_text:AnsiString);
   begin
      Comment := _text;
   end;
      
   function Parser.getComment : char;
   begin
      getComment := Comment;
   end;
   
{----- main program---------------------------------}

Var p:Parser;

var SourceBuffer : AnsiString;

begin
   
   sourceBuffer := 'Just some text.';
   WriteLn('The source buffer is:',sourceBuffer);
   
   p:=Parser.create;   
   p.setComment(sourceBuffer);   
   WriteLn(p.getComment);
   
   p.free;
end.






More information about the fpc-devel mailing list