| xHarbour Reference Documentation > Statement Reference |
![]() |
![]() |
![]() |
Declares and implements an inline method that spans across multiple lines.
INLINE METHOD <MethodName>( [<params,...>] ) <.. program code ..> ENDMETHOD
Methods are declared within the class declaration. When a method is also implemented between CLASS and ENDCLASS, it is called an INLINE method. The INLINE METHOD declaration declares an inline method whose implementation spans across multiple lines. The end of this implementation must be indicated with the ENDMETHOD statement.
INLINE METHOD exists for compatibility reasons. It is recommended to declare a method with METHOD (declaration) and implement it separately with METHOD (implementation).
Note: if a method can be implemeted with one line of code, the INLINE option of the METHOD (declaration) can be used.
| See also: | CLASS, METHOD (declaration), METHOD (implementation) |
| Category: | Class declaration , Declaration , xHarbour extensions |
| Header: | hbclass.ch |
| Source: | vm\classes.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example implements a class whose methods are entirely implemented
// INLINE. Objects of the class extract subsequent lines of an ASCII text
// until no more text lines are available.
#include "hbclass.ch"
PROCEDURE Main
LOCAL obj := LineParser():new( Memoread( "Test.prg" ) )
DO WHILE .NOT. obj:eof()
? obj:line
obj:nextLine()
ENDDO
RETURN
CLASS LineParser
PROTECTED:
DATA text
INLINE METHOD extract
LOCAL i := At( Chr(13)+Chr(10), ::text )
IF i == 0
::line := ::text
::text := ""
ELSE
::line := SubStr( ::text, 1, i-1 )
::text := SubStr( ::text, i+2 )
ENDIF
RETURN self
ENDMETHOD
EXPORTED:
DATA line INIT "" READONLY
METHOD init( cText ) INLINE ( ::text := cText, ::extract(), self )
METHOD eof INLINE ( Len( ::text + ::line ) == 0 )
INLINE METHOD nextLine
::extract()
RETURN ::line
ENDMETHOD
ENDCLASS
http://www.xHarbour.com