Free is now a prop. This makes the program to work

import "LangPrelude.prg"

prop Free :: Tag ~> Row Tag * ~> * where
  Klar :: Free t {}r
  Mehr :: DiffLabel t t' -> Free t r -> Free t {t'=a;r}r
 deriving List(f)

notMentionedIn :: Label a -> Record sh -> Maybe (Free a sh)
notMentionedIn l {} = Just $ Klar
notMentionedIn l {m=v; r} = do
                            diff <- case sameLabel l m of
                                    R x -> Just x
      	      	      	      	    _ -> Nothing
                            r' <- notMentionedIn l r
                            return $ Mehr diff r'
                       where monad maybeM

Just test1 = `a `notMentionedIn` {`g=7, `h='a'}

##test "`a occurs in head position"
  Just test2 = `a `notMentionedIn` {`g=7, `a='a'}

##test "`a occurs in second position"
  Just test3 = `a `notMentionedIn` {`a=7, `b='b'}

data Environment :: Row Tag * ~> * where
  Empty :: Environment {}r
  Extend :: Free t s => Label t -> a -> Environment s -> Environment {t=a;s}r
 deriving Record(e)

verifyEnv :: Record sh -> Maybe (Environment sh)
verifyEnv {} = Just {}e
verifyEnv {l=v; r} = do
                     l' <- l `notMentionedIn` r
                     r' <- verifyEnv r
                     return {l=v; r'}e
                 where monad maybeM

Just test4 = verifyEnv {`g=7, `a='a', `h="hey"}

##test "`g occurs twice"
  Just test5 = verifyEnv {`g=7, `a='a', `g="2"}

import "LangPrelude.prg"

data Free :: Tag ~> Row Tag * ~> * where
  Klar :: Free t {}r
  Mehr :: DiffLabel t t' -> Free t r -> Free t {t'=a;r}r
 deriving List(f)

notMentionedIn :: Label a -> Record sh -> Maybe (Free a sh)
notMentionedIn l {} = Just $ Klar
notMentionedIn l {m=v; r} = do
                            diff <- case sameLabel l m of
                                    R x -> Just x
      	      	      	      	    _ -> Nothing
                            r' <- notMentionedIn l r
                            return $ Mehr diff r'
                       where monad maybeM

Just test1 = `a `notMentionedIn` {`g=7, `h='a'}

##test "`a occurs in head position"
  Just test2 = `a `notMentionedIn` {`g=7, `a='a'}

##test "`a occurs in second position"
  Just test3 = `a `notMentionedIn` {`a=7, `b='b'}

data Environment :: Row Tag * ~> * where
  Empty :: Environment {}r
  Extend :: Free t s => Label t -> a -> Environment s -> Environment {t=a;s}r
 deriving Record(e)

verifyEnv :: Record sh -> Maybe (Environment sh)
verifyEnv {} = Just {}e
verifyEnv {l=v; r} = do
                     l' <- l `notMentionedIn` r
                     r' <- verifyEnv r
                     return (let theorem l' in {l=v; r'}e)
                 where monad maybeM

Just test4 = verifyEnv {`g=7, `a='a', `h="hey"}

##test "`g occurs twice"
  Just test5 = verifyEnv {`g=7, `a='a', `g="2"}


Qlabel:class updated - methods new1 and new2 removed - methods setNum1 and setNum2 removed - method setNum fixed - method setBuddy allow NIL to remove the set

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include "hbclass.ch"
#include "qt5xhb_clsid.ch"

#ifndef QT5XHB_NO_REQUESTS
REQUEST QWIDGET
REQUEST QMOVIE
REQUEST QPICTURE
REQUEST QPIXMAP
REQUEST QSIZE
#endif

CLASS QLabel INHERIT QFrame

   DATA class_id INIT Class_Id_QLabel
   DATA class_flags INIT 1
   DATA self_destruction INIT .F.

   METHOD new
   METHOD delete
   METHOD alignment
   METHOD buddy
   METHOD hasScaledContents
   METHOD hasSelectedText
   METHOD indent
   METHOD margin
   METHOD movie
   METHOD openExternalLinks
   METHOD picture
   METHOD pixmap
   METHOD selectedText
   METHOD setAlignment
   METHOD setBuddy
   METHOD setIndent
   METHOD setMargin
   METHOD setOpenExternalLinks
   METHOD setScaledContents
   METHOD setSelection
   METHOD setTextFormat
   METHOD setTextInteractionFlags
   METHOD setWordWrap
   METHOD text
   METHOD textFormat
   METHOD textInteractionFlags
   METHOD wordWrap
   METHOD heightForWidth
   METHOD minimumSizeHint
   METHOD sizeHint
   METHOD clear
   METHOD setMovie
   METHOD setNum
   METHOD setPicture
   METHOD setPixmap
   METHOD setText
   METHOD onLinkActivated
   METHOD onLinkHovered
   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QLabel
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#include <QLabel>
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_clsid.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#include <QLabel>
#endif

/*
QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
*/
void QLabel_new1 ()
{
  QWidget * par1 = ISNIL(1)? 0 : (QWidget *) _qt5xhb_itemGetPtr(1);
  int par2 = ISNIL(2)? (int) 0 : hb_parni(2);
  QLabel * o = new QLabel ( par1,  (Qt::WindowFlags) par2 );
  _qt5xhb_storePointerAndFlag( o, false );
}

/*
QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )
*/
void QLabel_new2 ()
{
  QString par1 = QLatin1String( hb_parc(1) );
  QWidget * par2 = ISNIL(2)? 0 : (QWidget *) _qt5xhb_itemGetPtr(2);
  int par3 = ISNIL(3)? (int) 0 : hb_parni(3);
  QLabel * o = new QLabel ( par1, par2,  (Qt::WindowFlags) par3 );
  _qt5xhb_storePointerAndFlag( o, false );
}

//[1]QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
//[2]QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )

HB_FUNC_STATIC( QLABEL_NEW )
{
  if( ISBETWEEN(0,2) && (ISQWIDGET(1)||ISNIL(1)) && (ISNUM(2)||ISNIL(2)) )
  {
    QLabel_new1();
  }
  else if( ISBETWEEN(1,3) && ISCHAR(1) && (ISQWIDGET(2)||ISNIL(2)) && (ISNUM(3)||ISNIL(3)) )
  {
    QLabel_new2();
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

HB_FUNC_STATIC( QLABEL_DELETE )
{
  QLabel * obj = (QLabel *) hb_itemGetPtr( hb_objSendMsg( hb_stackSelfItem(), "POINTER", 0 ) );

  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
Qt::Alignment alignment () const
*/
HB_FUNC_STATIC( QLABEL_ALIGNMENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->alignment (  ) );
  }
}

/*
QWidget * buddy () const
*/
HB_FUNC_STATIC( QLABEL_BUDDY )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QWidget * ptr = obj->buddy (  );
    _qt5xhb_createReturnQWidgetClass ( ptr, "QWIDGET" );
  }
}

/*
bool hasScaledContents () const
*/
HB_FUNC_STATIC( QLABEL_HASSCALEDCONTENTS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retl( obj->hasScaledContents (  ) );
  }
}

/*
bool hasSelectedText () const
*/
HB_FUNC_STATIC( QLABEL_HASSELECTEDTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retl( obj->hasSelectedText (  ) );
  }
}

/*
int indent () const
*/
HB_FUNC_STATIC( QLABEL_INDENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->indent (  ) );
  }
}

/*
int margin () const
*/
HB_FUNC_STATIC( QLABEL_MARGIN )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->margin (  ) );
  }
}

/*
QMovie * movie () const
*/
HB_FUNC_STATIC( QLABEL_MOVIE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QMovie * ptr = obj->movie (  );
    _qt5xhb_createReturnClass ( ptr, "QMOVIE" );
  }
}

/*
bool openExternalLinks () const
*/
HB_FUNC_STATIC( QLABEL_OPENEXTERNALLINKS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retl( obj->openExternalLinks (  ) );
  }
}

/*
const QPicture * picture () const
*/
HB_FUNC_STATIC( QLABEL_PICTURE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    const QPicture * ptr = obj->picture (  );
    _qt5xhb_createReturnClass ( ptr, "QPICTURE" );
  }
}

/*
const QPixmap * pixmap () const
*/
HB_FUNC_STATIC( QLABEL_PIXMAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    const QPixmap * ptr = obj->pixmap (  );
    _qt5xhb_createReturnClass ( ptr, "QPIXMAP" );
  }
}

/*
QString selectedText () const
*/
HB_FUNC_STATIC( QLABEL_SELECTEDTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retc( (const char *) obj->selectedText (  ).toLatin1().data() );
  }
}

/*
void setAlignment ( Qt::Alignment )
*/
HB_FUNC_STATIC( QLABEL_SETALIGNMENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setAlignment (  (Qt::Alignment) par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setBuddy ( QWidget * buddy )
*/
HB_FUNC_STATIC( QLABEL_SETBUDDY )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QWidget * par1 = ISNIL(1)? 0 : (QWidget *) _qt5xhb_itemGetPtr(1);
    obj->setBuddy ( par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setIndent ( int )
*/
HB_FUNC_STATIC( QLABEL_SETINDENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setIndent ( (int) hb_parni(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setMargin ( int )
*/
HB_FUNC_STATIC( QLABEL_SETMARGIN )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setMargin ( (int) hb_parni(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setOpenExternalLinks ( bool open )
*/
HB_FUNC_STATIC( QLABEL_SETOPENEXTERNALLINKS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setOpenExternalLinks ( (bool) hb_parl(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setScaledContents ( bool )
*/
HB_FUNC_STATIC( QLABEL_SETSCALEDCONTENTS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setScaledContents ( (bool) hb_parl(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setSelection ( int start, int length )
*/
HB_FUNC_STATIC( QLABEL_SETSELECTION )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setSelection ( (int) hb_parni(1), (int) hb_parni(2) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTextFormat ( Qt::TextFormat )
*/
HB_FUNC_STATIC( QLABEL_SETTEXTFORMAT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setTextFormat (  (Qt::TextFormat) par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTextInteractionFlags ( Qt::TextInteractionFlags flags )
*/
HB_FUNC_STATIC( QLABEL_SETTEXTINTERACTIONFLAGS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setTextInteractionFlags (  (Qt::TextInteractionFlags) par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setWordWrap ( bool on )
*/
HB_FUNC_STATIC( QLABEL_SETWORDWRAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setWordWrap ( (bool) hb_parl(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
QString text () const
*/
HB_FUNC_STATIC( QLABEL_TEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retc( (const char *) obj->text (  ).toLatin1().data() );
  }
}

/*
Qt::TextFormat textFormat () const
*/
HB_FUNC_STATIC( QLABEL_TEXTFORMAT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->textFormat (  ) );
  }
}

/*
Qt::TextInteractionFlags textInteractionFlags () const
*/
HB_FUNC_STATIC( QLABEL_TEXTINTERACTIONFLAGS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->textInteractionFlags (  ) );
  }
}

/*
bool wordWrap () const
*/
HB_FUNC_STATIC( QLABEL_WORDWRAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retl( obj->wordWrap (  ) );
  }
}

/*
virtual int heightForWidth ( int w ) const
*/
HB_FUNC_STATIC( QLABEL_HEIGHTFORWIDTH )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    hb_retni( obj->heightForWidth ( (int) hb_parni(1) ) );
  }
}

/*
virtual QSize minimumSizeHint () const
*/
HB_FUNC_STATIC( QLABEL_MINIMUMSIZEHINT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QSize * ptr = new QSize( obj->minimumSizeHint (  ) );
    _qt5xhb_createReturnClass ( ptr, "QSIZE", true );
  }
}

/*
virtual QSize sizeHint () const
*/
HB_FUNC_STATIC( QLABEL_SIZEHINT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QSize * ptr = new QSize( obj->sizeHint (  ) );
    _qt5xhb_createReturnClass ( ptr, "QSIZE", true );
  }
}

/*
void clear ()
*/
HB_FUNC_STATIC( QLABEL_CLEAR )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->clear (  );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setMovie ( QMovie * movie )
*/
HB_FUNC_STATIC( QLABEL_SETMOVIE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QMovie * par1 = (QMovie *) _qt5xhb_itemGetPtr(1);
    obj->setMovie ( par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setNum ( int num )
*/
void QLabel_setNum1 ()
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    obj->setNum ( (int) hb_parni(1) );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setNum ( double num )
*/
void QLabel_setNum2 ()
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    double par1 = hb_parnd(1);
    obj->setNum ( par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

//[1]void setNum ( int num )
//[2]void setNum ( double num )

HB_FUNC_STATIC( QLABEL_SETNUM )
{
  if( ISNUMPAR(1) && ISNUM(1) )
  {
    PHB_ITEM pNum = hb_param(1, HB_IT_NUMERIC);
    if( pNum )
    {
      if( HB_IS_DOUBLE(pNum) )
      {
        QLabel_setNum2();
      }
      else if( HB_IS_INTEGER(pNum) )
      {
        QLabel_setNum1();
      }
      else
      {
        hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
      }
    }
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

/*
void setPicture ( const QPicture & picture )
*/
HB_FUNC_STATIC( QLABEL_SETPICTURE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QPicture * par1 = (QPicture *) _qt5xhb_itemGetPtr(1);
    obj->setPicture ( *par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setPixmap ( const QPixmap & )
*/
HB_FUNC_STATIC( QLABEL_SETPIXMAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QPixmap * par1 = (QPixmap *) _qt5xhb_itemGetPtr(1);
    obj->setPixmap ( *par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setText ( const QString & )
*/
HB_FUNC_STATIC( QLABEL_SETTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();

  if( obj )
  {
    QString par1 = QLatin1String( hb_parc(1) );
    obj->setText ( par1 );
  }

  hb_itemReturn( hb_stackSelfItem() );
}

#pragma ENDDUMP

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include "hbclass.ch"
#include "qt5xhb_clsid.ch"

#ifndef QT5XHB_NO_REQUESTS
REQUEST QWIDGET
REQUEST QMOVIE
REQUEST QPICTURE
REQUEST QPIXMAP
REQUEST QSIZE
#endif

CLASS QLabel INHERIT QFrame

   DATA class_id INIT Class_Id_QLabel
   DATA class_flags INIT 1
   DATA self_destruction INIT .F.

   METHOD new1
   METHOD new2
   METHOD new
   METHOD delete
   METHOD alignment
   METHOD buddy
   METHOD hasScaledContents
   METHOD hasSelectedText
   METHOD indent
   METHOD margin
   METHOD movie
   METHOD openExternalLinks
   METHOD picture
   METHOD pixmap
   METHOD selectedText
   METHOD setAlignment
   METHOD setBuddy
   METHOD setIndent
   METHOD setMargin
   METHOD setOpenExternalLinks
   METHOD setScaledContents
   METHOD setSelection
   METHOD setTextFormat
   METHOD setTextInteractionFlags
   METHOD setWordWrap
   METHOD text
   METHOD textFormat
   METHOD textInteractionFlags
   METHOD wordWrap
   METHOD heightForWidth
   METHOD minimumSizeHint
   METHOD sizeHint
   METHOD clear
   METHOD setMovie
   METHOD setNum1
   METHOD setNum2
   METHOD setNum
   METHOD setPicture
   METHOD setPixmap
   METHOD setText
   METHOD onLinkActivated
   METHOD onLinkHovered
   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QLabel
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#include <QLabel>
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_clsid.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#include <QLabel>
#endif

/*
QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
*/
HB_FUNC_STATIC( QLABEL_NEW1 )
{
  QWidget * par1 = ISNIL(1)? 0 : (QWidget *) _qt5xhb_itemGetPtr(1);
  int par2 = ISNIL(2)? (int) 0 : hb_parni(2);
  QLabel * o = new QLabel ( par1,  (Qt::WindowFlags) par2 );
  _qt5xhb_storePointerAndFlag( o, false );
}

/*
QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )
*/
HB_FUNC_STATIC( QLABEL_NEW2 )
{
  QString par1 = QLatin1String( hb_parc(1) );
  QWidget * par2 = ISNIL(2)? 0 : (QWidget *) _qt5xhb_itemGetPtr(2);
  int par3 = ISNIL(3)? (int) 0 : hb_parni(3);
  QLabel * o = new QLabel ( par1, par2,  (Qt::WindowFlags) par3 );
  _qt5xhb_storePointerAndFlag( o, false );
}

//[1]QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
//[2]QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )

HB_FUNC_STATIC( QLABEL_NEW )
{
  if( ISBETWEEN(0,2) && (ISQWIDGET(1)||ISNIL(1)) && (ISNUM(2)||ISNIL(2)) )
  {
    HB_FUNC_EXEC( QLABEL_NEW1 );
  }
  else if( ISBETWEEN(1,3) && ISCHAR(1) && (ISQWIDGET(2)||ISNIL(2)) && (ISNUM(3)||ISNIL(3)) )
  {
    HB_FUNC_EXEC( QLABEL_NEW2 );
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

HB_FUNC_STATIC( QLABEL_DELETE )
{
  QLabel * obj = (QLabel *) hb_itemGetPtr( hb_objSendMsg( hb_stackSelfItem(), "POINTER", 0 ) );
  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
Qt::Alignment alignment () const
*/
HB_FUNC_STATIC( QLABEL_ALIGNMENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->alignment (  ) );
  }
}

/*
QWidget * buddy () const
*/
HB_FUNC_STATIC( QLABEL_BUDDY )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QWidget * ptr = obj->buddy (  );
    _qt5xhb_createReturnQWidgetClass ( ptr, "QWIDGET" );
  }
}

/*
bool hasScaledContents () const
*/
HB_FUNC_STATIC( QLABEL_HASSCALEDCONTENTS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->hasScaledContents (  ) );
  }
}

/*
bool hasSelectedText () const
*/
HB_FUNC_STATIC( QLABEL_HASSELECTEDTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->hasSelectedText (  ) );
  }
}

/*
int indent () const
*/
HB_FUNC_STATIC( QLABEL_INDENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->indent (  ) );
  }
}

/*
int margin () const
*/
HB_FUNC_STATIC( QLABEL_MARGIN )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->margin (  ) );
  }
}

/*
QMovie * movie () const
*/
HB_FUNC_STATIC( QLABEL_MOVIE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QMovie * ptr = obj->movie (  );
    _qt5xhb_createReturnClass ( ptr, "QMOVIE" );
  }
}

/*
bool openExternalLinks () const
*/
HB_FUNC_STATIC( QLABEL_OPENEXTERNALLINKS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->openExternalLinks (  ) );
  }
}

/*
const QPicture * picture () const
*/
HB_FUNC_STATIC( QLABEL_PICTURE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    const QPicture * ptr = obj->picture (  );
    _qt5xhb_createReturnClass ( ptr, "QPICTURE" );
  }
}

/*
const QPixmap * pixmap () const
*/
HB_FUNC_STATIC( QLABEL_PIXMAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    const QPixmap * ptr = obj->pixmap (  );
    _qt5xhb_createReturnClass ( ptr, "QPIXMAP" );
  }
}

/*
QString selectedText () const
*/
HB_FUNC_STATIC( QLABEL_SELECTEDTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retc( (const char *) obj->selectedText (  ).toLatin1().data() );
  }
}

/*
void setAlignment ( Qt::Alignment )
*/
HB_FUNC_STATIC( QLABEL_SETALIGNMENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setAlignment (  (Qt::Alignment) par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setBuddy ( QWidget * buddy )
*/
HB_FUNC_STATIC( QLABEL_SETBUDDY )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QWidget * par1 = (QWidget *) _qt5xhb_itemGetPtr(1);
    obj->setBuddy ( par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setIndent ( int )
*/
HB_FUNC_STATIC( QLABEL_SETINDENT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setIndent ( (int) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setMargin ( int )
*/
HB_FUNC_STATIC( QLABEL_SETMARGIN )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setMargin ( (int) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setOpenExternalLinks ( bool open )
*/
HB_FUNC_STATIC( QLABEL_SETOPENEXTERNALLINKS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setOpenExternalLinks ( (bool) hb_parl(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setScaledContents ( bool )
*/
HB_FUNC_STATIC( QLABEL_SETSCALEDCONTENTS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setScaledContents ( (bool) hb_parl(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setSelection ( int start, int length )
*/
HB_FUNC_STATIC( QLABEL_SETSELECTION )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setSelection ( (int) hb_parni(1), (int) hb_parni(2) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTextFormat ( Qt::TextFormat )
*/
HB_FUNC_STATIC( QLABEL_SETTEXTFORMAT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setTextFormat (  (Qt::TextFormat) par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setTextInteractionFlags ( Qt::TextInteractionFlags flags )
*/
HB_FUNC_STATIC( QLABEL_SETTEXTINTERACTIONFLAGS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    obj->setTextInteractionFlags (  (Qt::TextInteractionFlags) par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setWordWrap ( bool on )
*/
HB_FUNC_STATIC( QLABEL_SETWORDWRAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setWordWrap ( (bool) hb_parl(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
QString text () const
*/
HB_FUNC_STATIC( QLABEL_TEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retc( (const char *) obj->text (  ).toLatin1().data() );
  }
}

/*
Qt::TextFormat textFormat () const
*/
HB_FUNC_STATIC( QLABEL_TEXTFORMAT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->textFormat (  ) );
  }
}

/*
Qt::TextInteractionFlags textInteractionFlags () const
*/
HB_FUNC_STATIC( QLABEL_TEXTINTERACTIONFLAGS )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->textInteractionFlags (  ) );
  }
}

/*
bool wordWrap () const
*/
HB_FUNC_STATIC( QLABEL_WORDWRAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retl( obj->wordWrap (  ) );
  }
}

/*
virtual int heightForWidth ( int w ) const
*/
HB_FUNC_STATIC( QLABEL_HEIGHTFORWIDTH )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    hb_retni( obj->heightForWidth ( (int) hb_parni(1) ) );
  }
}

/*
virtual QSize minimumSizeHint () const
*/
HB_FUNC_STATIC( QLABEL_MINIMUMSIZEHINT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QSize * ptr = new QSize( obj->minimumSizeHint (  ) );
    _qt5xhb_createReturnClass ( ptr, "QSIZE", true );
  }
}

/*
virtual QSize sizeHint () const
*/
HB_FUNC_STATIC( QLABEL_SIZEHINT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QSize * ptr = new QSize( obj->sizeHint (  ) );
    _qt5xhb_createReturnClass ( ptr, "QSIZE", true );
  }
}

/*
void clear ()
*/
HB_FUNC_STATIC( QLABEL_CLEAR )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->clear (  );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setMovie ( QMovie * movie )
*/
HB_FUNC_STATIC( QLABEL_SETMOVIE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QMovie * par1 = (QMovie *) _qt5xhb_itemGetPtr(1);
    obj->setMovie ( par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setNum ( int num )
*/
HB_FUNC_STATIC( QLABEL_SETNUM1 )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->setNum ( (int) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setNum ( double num )
*/
HB_FUNC_STATIC( QLABEL_SETNUM2 )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    double par1 = hb_parnd(1);
    obj->setNum ( par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

HB_FUNC_STATIC( QLABEL_SETNUM ) // TODO: int ou double ?
{
  if( ISNUMPAR(1) && ISNUM(1) )
  {
    //if( HB_IS_DOUBLE(1) )
    //{
      HB_FUNC_EXEC( QLABEL_SETNUM2 );
    //}
    //else
    //{
    //  HB_FUNC_EXEC( QLABEL_SETNUM1 );
    //}
  }
  else
  {
    hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
  }
}

/*
void setPicture ( const QPicture & picture )
*/
HB_FUNC_STATIC( QLABEL_SETPICTURE )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QPicture * par1 = (QPicture *) _qt5xhb_itemGetPtr(1);
    obj->setPicture ( *par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setPixmap ( const QPixmap & )
*/
HB_FUNC_STATIC( QLABEL_SETPIXMAP )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QPixmap * par1 = (QPixmap *) _qt5xhb_itemGetPtr(1);
    obj->setPixmap ( *par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
void setText ( const QString & )
*/
HB_FUNC_STATIC( QLABEL_SETTEXT )
{
  QLabel * obj = (QLabel *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QString par1 = QLatin1String( hb_parc(1) );
    obj->setText ( par1 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

#pragma ENDDUMP


[VOEditors] Prevented CLIPPER clause from being added to constructors, if it is already specified to be added in cavowed.inf (https://github.com/X-Sharp/XSharpPublic/issues/913)

#using System.Collections.Generic
#using System.Collections.Generic
#using System.Collections

USING Xide

BEGIN NAMESPACE Xide

CLASS AbstractEditor
	EXPORT aLines AS List<LineObject>
	PROTECT nStart,nEnd AS INT
	PROTECT oBuffer AS EditorBuffer
	CONSTRUCTOR(_oBuffer AS EditorBuffer)
		SELF:oBuffer := _oBuffer
		SELF:oBuffer:FullParse()
		SELF:aLines := SELF:oBuffer:aLines
	RETURN

	METHOD BeginCode() AS VOID
		SELF:nStart := 0
		SELF:nEnd := 0
		IF SELF:oBuffer != NULL
			SELF:oBuffer:BeginAction()
		END IF
	RETURN

	METHOD EndCode() AS VOID
		IF SELF:oBuffer != NULL
			SELF:oBuffer:EndAction()
		END IF
	RETURN

	METHOD ModifiedLine(nLine AS INT) AS VOID
		IF SELF:nStart == 0 .or. SELF:nStart > nLine
			SELF:nStart := nLine
		ENDIF
		IF SELF:nEnd == 0 .or. SELF:nEnd < nLine
			SELF:nEnd := nLine
		ENDIF
	RETURN

	METHOD CheckCreatedCode() AS VOID
		IF SELF:nStart != 0
			SELF:oBuffer:LinesModified(0,0,0)
		ENDIF
		SELF:nStart := 0
		SELF:nEnd := 0
	RETURN

	METHOD AddLine(cLine AS STRING) AS VOID
		SELF:oBuffer:AddLine(cLine)
	RETURN

	METHOD InsertLine(cLine AS STRING , nLine AS INT) AS VOID
		SELF:oBuffer:InsertLine(nLine , cLine)
	RETURN

	METHOD ReplaceLine(cLine AS STRING , nLine AS INT) AS VOID
		SELF:oBuffer:ChangeLine(nLine , cLine)
	RETURN

	METHOD RemoveLine(nLine AS INT) AS VOID
		SELF:oBuffer:DeleteLine(nLine)
	RETURN

	METHOD DeleteAllLines() AS VOID
		SELF:oBuffer:DeleteAllLines()
	RETURN

END CLASS

PARTIAL CLASS CodeGenerator
	PROTECT aLines AS List<LineObject>
	PROTECT nStart,nEnd AS INT
	PROTECT oEditor , oBaseEditor , oDesEditor AS AbstractEditor

	CONSTRUCTOR(oBuffer AS EditorBuffer)
		SELF:aLines := oBuffer:aLines
		SELF:oBaseEditor := AbstractEditor{oBuffer}
	RETURN

	METHOD BeginCode() AS LOGIC
		SELF:oDesEditor := SELF:oBaseEditor
		SELF:oEditor := SELF:oBaseEditor
		SELF:oEditor:BeginCode()
	RETURN FALSE

	METHOD EndCode() AS VOID
		SELF:oEditor:EndCode()
	RETURN

METHOD ModifiedLine(nLine AS INT) AS VOID
	SELF:oEditor:ModifiedLine(nLine)
RETURN

METHOD CheckCreatedCode() AS VOID
	SELF:oEditor:CheckCreatedCode()
RETURN
METHOD GetLine(nLine AS INT) AS LineObject
	RETURN SELF:aLines[nLine - 1]

METHOD EntityExists(eType AS EntityType,cName AS STRING,cClass AS STRING) AS LOGIC
LOCAL nDummy AS INT
SELF:FindEntity(eType,cName,cClass,nDummy)
RETURN nDummy!=0

METHOD EntityExistsAnywhere(eType AS EntityType , cName AS STRING , cClass AS STRING) AS LOGIC
RETURN FALSE

METHOD FindEntity(eType AS EntityType,cName AS STRING,cClass AS STRING,nLine REF Int32) AS LOGIC
LOCAL oLine AS LineObject
LOCAL oEntity AS EntityObject
cName := cName:ToUpper():Trim()
cClass := cClass:ToUpper():Trim()
FOR nLine:=1 UPTO SELF:aLines:Count
	oLine:=SELF:GetLine(nLine)
	IF oLine:lEntity
		oEntity:=oLine:oEntity
		IF oEntity:eType == eType .and. oEntity:cTypedClassName:ToUpper() == cClass
			IF eType == EntityType._Constructor .or. oEntity:cName:ToUpper() == cName
				RETURN FALSE
			ENDIF
		END IF
	END IF
NEXT
nLine:=0
RETURN FALSE

METHOD DeleteEntity(eType AS EntityType,cName AS STRING,cClass AS STRING) AS LOGIC
	LOCAL nLine AS INT
RETURN SELF:DeleteEntity(eType , cName ,cClass , nLine)

METHOD DeleteEntity(eType AS EntityType,cName AS STRING,cClass AS STRING,nLine REF Int32) AS LOGIC
LOCAL oLine AS LineObject
LOCAL lExit AS LOGIC
LOCAL nOldLine AS INT
LOCAL cLine AS STRING
nOldLine := nLine
SELF:FindEntity(eType,cName,cClass,nLine)
IF nLine == 0
	nLine := nOldLine
	RETURN FALSE
ENDIF

DO WHILE nLine!=0
	SELF:RemoveWEDLine(nLine)
	SELF:ModifiedLine(nLine)
	IF nLine<=SELF:aLines:Count
		oLine:=SELF:GetLine(nLine)
		IF oLine:lEntity .or. lExit .or. oLine:IsEndClass
			EXIT
		END IF
		cLine := oLine:LineText:ToUpper()
		IF cLine:Contains("##USER##") .or. cLine:Contains("{{%UC%}}") .or. cLine:Contains("USER CODE STARTS")
			lExit := TRUE
		END IF
	ELSE
		EXIT
	END IF
END DO
SELF:CheckCreatedCode()
RETURN FALSE

METHOD AddInclude(cInclude AS STRING) AS VOID
	LOCAL oLine AS LineObject
	LOCAL nLine AS INT
	LOCAL n AS INT

	nLine := 1

	FOR n := 1 UPTO SELF:aLines:Count
		oLine := SELF:aLines[n - 1]
		DO CASE
		CASE oLine:lEntity
			nLine := n - 1
			EXIT
		CASE oLine:IsInclude .and. oLine:cArgument:ToUpper() == cInclude:ToUpper()
			RETURN
		END CASE
	NEXT
	IF nLine <= 0
		nLine := 1
	ENDIF

	SELF:AddWEDLine("#include " + e"\"" + cInclude + e"\"" , nLine)
	SELF:ModifiedLine(nLine)
RETURN

METHOD RemoveInclude(cInclude AS STRING) AS VOID
	FOR LOCAL nLine := 1 UPTO SELF:aLines:Count
		LOCAL oLine AS LineObject
		oLine := SELF:aLines[nLine - 1]
		DO CASE
		CASE oLine:lEntity
			RETURN
		CASE oLine:IsInclude .and. oLine:cArgument:ToUpper() == cInclude:ToUpper()
			SELF:RemoveWEDLine(nLine)
			SELF:ModifiedLine(nLine)
			RETURN
		END CASE
	NEXT
RETURN

METHOD AddLine(cLine AS STRING) AS VOID
	SELF:oEditor:AddLine(cLine)
	SELF:ModifiedLine(SELF:aLines:Count)
RETURN
METHOD InsertLine(nLine AS INT , cLine AS STRING) AS VOID
	SELF:oEditor:InsertLine(cLine , nLine)
	SELF:ModifiedLine(SELF:aLines:Count)
RETURN

METHOD AddWEDLine(cLine AS STRING,nLine REF Int32) AS LineObject
LOCAL oLine AS LineObject
IF nLine<=SELF:aLines:Count .and. nLine!=0
	SELF:oEditor:InsertLine(cLine , nLine)
	SELF:ModifiedLine(nLine)
ELSE
	SELF:oEditor:AddLine(cLine)
	nLine:=SELF:aLines:Count
	SELF:ModifiedLine(nLine)
END IF
oLine := SELF:GetLine(nLine)
nLine++
RETURN oLine
METHOD ReplaceWEDLine(cLine AS STRING,nLine AS Int32) AS LineObject
	SELF:oEditor:ReplaceLine(cLine , nLine)
	SELF:ModifiedLine(nLine)
RETURN SELF:GetLine(nLine)
METHOD RemoveWEDLine(nLine AS Int32) AS VOID
	SELF:oEditor:RemoveLine(nLine)
RETURN
METHOD Clear() AS VOID
	SELF:oEditor:DeleteAllLines()
RETURN

	STATIC PROTECT cUser := "// {{%UC%}} User code starts here (DO NOT remove this line)  " AS STRING
	STATIC PROTECT cTagU := "" AS STRING

	METHOD GetEntity(eType AS EntityType , cName AS STRING , cClass AS STRING) AS EntityObject
		LOCAL nLine AS INT
		nLine := SELF:FindEntity(eType , cName , cClass)
		IF nLine != 0
			RETURN SELF:GetLine(nLine):oEntity
		END IF
	RETURN NULL

	METHOD FindEntity(eType AS EntityType , cName AS STRING , cClass AS STRING) AS INT
		LOCAL nLine AS INT
		SELF:FindEntity(eType , cName , cClass , nLine)
	RETURN nLine

	METHOD WriteEntity(eType AS EntityType , cName AS STRING , cClass AS STRING , eOptions AS EntityOptions , aEntity AS List<STRING>) AS INT
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		LOCAL nTemp AS INT
		LOCAL nFirst AS INT
		LOCAL lIsUser AS LOGIC
		LOCAL lRemoveFields AS LOGIC
		LOCAL n AS INT

		LOCAL cTab , ceTab AS STRING
		cTab := e"\t"
		ceTab := e"\t"

		IF aEntity:Count == 0
			RETURN 0
		END IF

		cClass := cClass:ToUpper()
		nLine := SELF:FindEntity(eType , cName , cClass)

		IF nLine == 0
			IF eType == EntityType._Class
				nLine := SELF:aLines:Count + 1
			ELSEIF eType == EntityType._Constructor
				nLine := SELF:FindEntity(EntityType._Class , cClass , cClass)
				IF nLine == 0
					RETURN 0
				END IF
				DO WHILE TRUE
					nLine ++
					IF nLine > SELF:aLines:Count
						EXIT
					END IF
					oLine := SELF:GetLine(nLine)
					IF oLine:lEntity .or. oLine:IsEndClass
						EXIT
					END IF
				END DO
			ELSE
				nLine := SELF:FindEntity(EntityType._Class , cClass , cClass)
				IF nLine == 0
					RETURN 0
				END IF
				DO WHILE TRUE
					nLine ++
					IF nLine > SELF:aLines:Count
						EXIT
					END IF
					oLine := SELF:GetLine(nLine)
					IF oLine:IsEndClass
						EXIT
					END IF
					IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() != cClass
						EXIT
					END IF
				END DO
			END IF
			nFirst := nLine
		ELSE
			nFirst := nLine
			IF (eOptions & EntityOptions.NotOverwrite) == EntityOptions.NotOverwrite
				RETURN nFirst
			END IF
			oLine := SELF:GetLine(nLine)
			LOCAL oDeclarationLine AS LineObject
			oDeclarationLine := oLine

			DO WHILE oLine:lOutAmpersand .and. (oLine:LineText:Contains("[") .or. oLine:LineText:Contains("]"))
				nLine ++
				oLine := SELF:GetLine(nLine)
			END DO

			IF (eOptions & EntityOptions.ClearOldFields) == EntityOptions.ClearOldFields
				lRemoveFields := FALSE
				nTemp := nLine
				nTemp ++
				DO WHILE nTemp <= SELF:aLines:Count
					oLine := SELF:GetLine(nTemp)
					IF oLine:lEntity
						EXIT
					END IF
					IF oLine:IsDesignerUserStart
						lRemoveFields := TRUE
						EXIT
					ENDIF
					nTemp ++
				END DO
			ELSE
				lRemoveFields := TRUE
			END IF

			IF lRemoveFields
				nTemp := nLine
				nTemp ++
				DO WHILE nTemp <= SELF:aLines:Count
					oLine := SELF:GetLine(nTemp)
					IF oLine:lEntity .or. oLine:IsEndClass
						EXIT
					END IF
					lIsUser := oLine:IsDesignerUserStart
					SELF:RemoveWEDLine(nTemp)
					IF lIsUser
						EXIT
					ENDIF
				END DO
			END IF

			IF SELF:GetLine(nLine):LineText:ToUpper() == aEntity[0]:ToUpper() .or. (eOptions & EntityOptions.KeepFirstLine) == EntityOptions.KeepFirstLine
				nLine ++
			ELSE
				LOCAL cDeclarationLine AS STRING
				cDeclarationLine := aEntity[0]
				IF oDeclarationLine:oEntity != NULL
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Protected) == EntityModifiers._Protected
						cDeclarationLine := "PROTECTED " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Private) == EntityModifiers._Private
						cDeclarationLine := "PRIVATE " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Partial) == EntityModifiers._Partial
						cDeclarationLine := "PARTIAL " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Internal) == EntityModifiers._Internal
						cDeclarationLine := "INTERNAL " + cDeclarationLine
					ENDIF
					IF .NOT. String.IsNullOrEmpty( oDeclarationLine:oEntity:cImplements:Trim() )
						cDeclarationLine := cDeclarationLine + " IMPLEMENTS " + oDeclarationLine:oEntity:cImplements
					ENDIF
                END IF
                IF eType == EntityType._Constructor
                    LOCAL cOldLine := SELF:GetLine(nLine):LineText:Trim():ToUpper() AS STRING
                    /*LOCAL nAt := cOldLine:LastIndexOf(')') AS INT
                    IF nAt != -1
                        nAt := cOldLine:IndexOf("CLIPPER", nAt)
                        IF nAt != -1
                            cDeclarationLine += " CLIPPER"
                        ENDIF
                    ENDIF*/
                    IF cOldLine:EndsWith("CLIPPER") .and. .not. cDeclarationLine:ToUpper():Contains("CLIPPER")
                        cDeclarationLine += " CLIPPER"
                    ENDIF
                ENDIF
				SELF:ReplaceWEDLine(cDeclarationLine , nLine)
				nLine ++
			END IF
			n := 1
		END IF

		DO WHILE n < aEntity:Count
			oLine := SELF:AddWEDLine(aEntity[n] , nLine)
			n ++
		END DO
		IF (eOptions & EntityOptions.AddUser) == EntityOptions.AddUser
			IF eType == EntityType._Class
				oLine := SELF:AddWEDLine(ceTab + cUser + cTagU , nLine)
			ELSE
				oLine := SELF:AddWEDLine(cTab + cUser + cTagU , nLine)
			END IF
		END IF

		IF eType != EntityType._Class
			IF nLine <= SELF:aLines:Count
				oLine := SELF:GetLine(nLine)
				IF oLine:LineText:Trim() != ""
					oLine := SELF:AddWEDLine("" , nLine)
				END IF
			END IF
		END IF

		SELF:CheckCreatedCode()
	RETURN nFirst

	METHOD WriteEndClass(cClass AS STRING) AS VOID
		LOCAL oLine AS LineObject
		LOCAL lFound AS LOGIC
		LOCAL nLine AS INT
		LOCAL n AS INT

		cClass := cClass:ToUpper()
		FOR n := 1 UPTO SELF:aLines:Count
			oLine := SELF:GetLine(n)
			IF lFound
				IF oLine:IsEndClass
					RETURN
				END IF
				IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() != cClass
					EXIT
				END IF
				nLine := n + 1
			ELSE
				IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() == cClass
					lFound := TRUE
					nLine := n + 1
				END IF
			END IF
		NEXT

		IF nLine != 0
			SELF:AddWEDLine("END CLASS" , nLine)
		END IF

	RETURN

	METHOD DeleteLine(nLine AS INT) AS VOID
		SELF:RemoveWEDLine(nLine)
		SELF:ModifiedLine(nLine)
	RETURN

	METHOD DeleteDefines(aDefines AS List<STRING>) AS VOID
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		nLine := 1
		DO WHILE nLine <= SELF:aLines:Count
			LOCAL lDeleted := FALSE AS LOGIC
			oLine := SELF:aLines[nLine - 1]
			IF oLine:eType == LineType.Define .and. .not. String.IsNullOrEmpty(oLine:cArgument)
				FOREACH cDefine AS STRING IN aDefines
					IF cDefine:ToUpper() == oLine:cArgument:ToUpper()
						SELF:DeleteLine(nLine)
						lDeleted := TRUE
						EXIT
					END IF
				NEXT
			ELSEIF oLine:oEntity != NULL .and. oLine:oEntity:eType == EntityType._Define
				FOREACH cDefine AS STRING IN aDefines
					IF cDefine:ToUpper() == oLine:oEntity:cName:ToUpper()
						SELF:DeleteLine(nLine)
						lDeleted := TRUE
						EXIT
					END IF
				NEXT
			END IF
			IF .not. lDeleted
				nLine ++
			END IF
		END DO

		SELF:CheckCreatedCode()

	RETURN

	METHOD AddDefine(cDefine AS STRING , cValue AS STRING) AS VOID
		SELF:AddDefine(cDefine , cValue , TRUE)
	RETURN

	METHOD AddDefine(cDefine AS STRING , cValue AS STRING , lAdd AS LOGIC) AS VOID
		LOCAL cLine AS STRING
		cLine := String.Format("#define {0} {1}" , cDefine , cValue)
//		cLine := String.Format("DEFINE {0} := {1}" , cDefine , cValue)
		IF lAdd
			SELF:AddLine(cLine)
		ELSE
			SELF:InsertLine(1 , cLine)
		END IF
	RETURN

	METHOD AddDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>) AS VOID
		SELF:AddDefines(aDefines , aDefineValues , TRUE)
	RETURN

	METHOD AddDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING> , lAdd AS LOGIC) AS VOID
		FOR LOCAL n := 0 AS INT UPTO aDefines:Count - 1
			SELF:AddDefine(aDefines[n] , aDefineValues[n] , lAdd)
		NEXT
	RETURN

	METHOD RemoveDefines(cWindowName as STRING) AS VOID
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		nLine := 1
		cWindowName := cWindowName:ToUpper()+"_"
		DO WHILE nLine <= SELF:aLines:Count
			LOCAL lDeleted := FALSE AS LOGIC
			oLine := SELF:aLines[nLine - 1]
			IF oLine:eType == LineType.Define .and. .not. String.IsNullOrEmpty(oLine:cArgument)
				IF oLine:cArgument:ToUpper():StartsWith(cWindowName)
					SELF:DeleteLine(nLine)
					lDeleted := TRUE
				END IF
			ELSEIF oLine:oEntity != NULL .and. oLine:oEntity:eType == EntityType._Define
				IF oLine:oEntity:cName:ToUpper():StartsWith(cWindowName)
					SELF:DeleteLine(nLine)
					lDeleted := TRUE
				END IF
			END IF
			IF .not. lDeleted
				nLine ++
			END IF
		END DO
		SELF:CheckCreatedCode()
		RETURN

	METHOD AddXSharpDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>) AS VOID
		SELF:AddXSharpDefines(aDefines, aDefineValues, FALSE)

	METHOD AddXSharpDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>, lStatic AS LOGIC) AS VOID
		LOCAL cLine AS STRING
		LOCAL nLine AS INT
		FOR LOCAL n := 1 AS INT UPTO SELF:aLines:Count
			LOCAL oLine AS LineObject
			oLine := SELF:aLines[n-1]
			nLine := n
			DO CASE
			CASE oLine:oEntity != NULL
				EXIT
//			CASE oLine:IsRegionIn .and. oLine:cArgument:ToUpper() == "DEFINES"
			// grr, I am not setting cArgument for regions
			CASE oLine:IsRegionIn .and. oLine:LineText:ToUpper():Contains("DEFINES")
				nLine ++
				EXIT
			END CASE
		NEXT
		LOCAL cMask AS STRING
		cMask := "DEFINE {0} := {1}"
		IF lStatic
			cMask := "STATIC "+cMask
        ENDIF
        IF nLine == 0
            nLine := 1
        ENDIF
		FOR LOCAL n := 0 AS INT UPTO aDefines:Count - 1
			cLine := String.Format(cMask , aDefines[n] , aDefineValues[n])
			SELF:InsertLine(nLine , cLine)
			nLine ++
		NEXT
	RETURN

END CLASS

[Flags];
ENUM EntityOptions
	MEMBER None := 0
	MEMBER AddUser := 1
	MEMBER NotOverwrite := 2
	MEMBER ClearOldFields := 4
	MEMBER KeepFirstLine := 8
END ENUM

END NAMESPACE

#using System.Collections.Generic
#using System.Collections.Generic
#using System.Collections

USING Xide

BEGIN NAMESPACE Xide

CLASS AbstractEditor
	EXPORT aLines AS List<LineObject>
	PROTECT nStart,nEnd AS INT
	PROTECT oBuffer AS EditorBuffer
	CONSTRUCTOR(_oBuffer AS EditorBuffer)
		SELF:oBuffer := _oBuffer
		SELF:oBuffer:FullParse()
		SELF:aLines := SELF:oBuffer:aLines
	RETURN

	METHOD BeginCode() AS VOID
		SELF:nStart := 0
		SELF:nEnd := 0
		IF SELF:oBuffer != NULL
			SELF:oBuffer:BeginAction()
		END IF
	RETURN

	METHOD EndCode() AS VOID
		IF SELF:oBuffer != NULL
			SELF:oBuffer:EndAction()
		END IF
	RETURN

	METHOD ModifiedLine(nLine AS INT) AS VOID
		IF SELF:nStart == 0 .or. SELF:nStart > nLine
			SELF:nStart := nLine
		ENDIF
		IF SELF:nEnd == 0 .or. SELF:nEnd < nLine
			SELF:nEnd := nLine
		ENDIF
	RETURN

	METHOD CheckCreatedCode() AS VOID
		IF SELF:nStart != 0
			SELF:oBuffer:LinesModified(0,0,0)
		ENDIF
		SELF:nStart := 0
		SELF:nEnd := 0
	RETURN

	METHOD AddLine(cLine AS STRING) AS VOID
		SELF:oBuffer:AddLine(cLine)
	RETURN

	METHOD InsertLine(cLine AS STRING , nLine AS INT) AS VOID
		SELF:oBuffer:InsertLine(nLine , cLine)
	RETURN

	METHOD ReplaceLine(cLine AS STRING , nLine AS INT) AS VOID
		SELF:oBuffer:ChangeLine(nLine , cLine)
	RETURN

	METHOD RemoveLine(nLine AS INT) AS VOID
		SELF:oBuffer:DeleteLine(nLine)
	RETURN

	METHOD DeleteAllLines() AS VOID
		SELF:oBuffer:DeleteAllLines()
	RETURN

END CLASS

PARTIAL CLASS CodeGenerator
	PROTECT aLines AS List<LineObject>
	PROTECT nStart,nEnd AS INT
	PROTECT oEditor , oBaseEditor , oDesEditor AS AbstractEditor

	CONSTRUCTOR(oBuffer AS EditorBuffer)
		SELF:aLines := oBuffer:aLines
		SELF:oBaseEditor := AbstractEditor{oBuffer}
	RETURN

	METHOD BeginCode() AS LOGIC
		SELF:oDesEditor := SELF:oBaseEditor
		SELF:oEditor := SELF:oBaseEditor
		SELF:oEditor:BeginCode()
	RETURN FALSE

	METHOD EndCode() AS VOID
		SELF:oEditor:EndCode()
	RETURN

METHOD ModifiedLine(nLine AS INT) AS VOID
	SELF:oEditor:ModifiedLine(nLine)
RETURN

METHOD CheckCreatedCode() AS VOID
	SELF:oEditor:CheckCreatedCode()
RETURN
METHOD GetLine(nLine AS INT) AS LineObject
	RETURN SELF:aLines[nLine - 1]

METHOD EntityExists(eType AS EntityType,cName AS STRING,cClass AS STRING) AS LOGIC
LOCAL nDummy AS INT
SELF:FindEntity(eType,cName,cClass,nDummy)
RETURN nDummy!=0

METHOD EntityExistsAnywhere(eType AS EntityType , cName AS STRING , cClass AS STRING) AS LOGIC
RETURN FALSE

METHOD FindEntity(eType AS EntityType,cName AS STRING,cClass AS STRING,nLine REF Int32) AS LOGIC
LOCAL oLine AS LineObject
LOCAL oEntity AS EntityObject
cName := cName:ToUpper():Trim()
cClass := cClass:ToUpper():Trim()
FOR nLine:=1 UPTO SELF:aLines:Count
	oLine:=SELF:GetLine(nLine)
	IF oLine:lEntity
		oEntity:=oLine:oEntity
		IF oEntity:eType == eType .and. oEntity:cTypedClassName:ToUpper() == cClass
			IF eType == EntityType._Constructor .or. oEntity:cName:ToUpper() == cName
				RETURN FALSE
			ENDIF
		END IF
	END IF
NEXT
nLine:=0
RETURN FALSE

METHOD DeleteEntity(eType AS EntityType,cName AS STRING,cClass AS STRING) AS LOGIC
	LOCAL nLine AS INT
RETURN SELF:DeleteEntity(eType , cName ,cClass , nLine)

METHOD DeleteEntity(eType AS EntityType,cName AS STRING,cClass AS STRING,nLine REF Int32) AS LOGIC
LOCAL oLine AS LineObject
LOCAL lExit AS LOGIC
LOCAL nOldLine AS INT
LOCAL cLine AS STRING
nOldLine := nLine
SELF:FindEntity(eType,cName,cClass,nLine)
IF nLine == 0
	nLine := nOldLine
	RETURN FALSE
ENDIF

DO WHILE nLine!=0
	SELF:RemoveWEDLine(nLine)
	SELF:ModifiedLine(nLine)
	IF nLine<=SELF:aLines:Count
		oLine:=SELF:GetLine(nLine)
		IF oLine:lEntity .or. lExit .or. oLine:IsEndClass
			EXIT
		END IF
		cLine := oLine:LineText:ToUpper()
		IF cLine:Contains("##USER##") .or. cLine:Contains("{{%UC%}}") .or. cLine:Contains("USER CODE STARTS")
			lExit := TRUE
		END IF
	ELSE
		EXIT
	END IF
END DO
SELF:CheckCreatedCode()
RETURN FALSE

METHOD AddInclude(cInclude AS STRING) AS VOID
	LOCAL oLine AS LineObject
	LOCAL nLine AS INT
	LOCAL n AS INT

	nLine := 1

	FOR n := 1 UPTO SELF:aLines:Count
		oLine := SELF:aLines[n - 1]
		DO CASE
		CASE oLine:lEntity
			nLine := n - 1
			EXIT
		CASE oLine:IsInclude .and. oLine:cArgument:ToUpper() == cInclude:ToUpper()
			RETURN
		END CASE
	NEXT
	IF nLine <= 0
		nLine := 1
	ENDIF

	SELF:AddWEDLine("#include " + e"\"" + cInclude + e"\"" , nLine)
	SELF:ModifiedLine(nLine)
RETURN

METHOD RemoveInclude(cInclude AS STRING) AS VOID
	FOR LOCAL nLine := 1 UPTO SELF:aLines:Count
		LOCAL oLine AS LineObject
		oLine := SELF:aLines[nLine - 1]
		DO CASE
		CASE oLine:lEntity
			RETURN
		CASE oLine:IsInclude .and. oLine:cArgument:ToUpper() == cInclude:ToUpper()
			SELF:RemoveWEDLine(nLine)
			SELF:ModifiedLine(nLine)
			RETURN
		END CASE
	NEXT
RETURN

METHOD AddLine(cLine AS STRING) AS VOID
	SELF:oEditor:AddLine(cLine)
	SELF:ModifiedLine(SELF:aLines:Count)
RETURN
METHOD InsertLine(nLine AS INT , cLine AS STRING) AS VOID
	SELF:oEditor:InsertLine(cLine , nLine)
	SELF:ModifiedLine(SELF:aLines:Count)
RETURN

METHOD AddWEDLine(cLine AS STRING,nLine REF Int32) AS LineObject
LOCAL oLine AS LineObject
IF nLine<=SELF:aLines:Count .and. nLine!=0
	SELF:oEditor:InsertLine(cLine , nLine)
	SELF:ModifiedLine(nLine)
ELSE
	SELF:oEditor:AddLine(cLine)
	nLine:=SELF:aLines:Count
	SELF:ModifiedLine(nLine)
END IF
oLine := SELF:GetLine(nLine)
nLine++
RETURN oLine
METHOD ReplaceWEDLine(cLine AS STRING,nLine AS Int32) AS LineObject
	SELF:oEditor:ReplaceLine(cLine , nLine)
	SELF:ModifiedLine(nLine)
RETURN SELF:GetLine(nLine)
METHOD RemoveWEDLine(nLine AS Int32) AS VOID
	SELF:oEditor:RemoveLine(nLine)
RETURN
METHOD Clear() AS VOID
	SELF:oEditor:DeleteAllLines()
RETURN

	STATIC PROTECT cUser := "// {{%UC%}} User code starts here (DO NOT remove this line)  " AS STRING
	STATIC PROTECT cTagU := "" AS STRING

	METHOD GetEntity(eType AS EntityType , cName AS STRING , cClass AS STRING) AS EntityObject
		LOCAL nLine AS INT
		nLine := SELF:FindEntity(eType , cName , cClass)
		IF nLine != 0
			RETURN SELF:GetLine(nLine):oEntity
		END IF
	RETURN NULL

	METHOD FindEntity(eType AS EntityType , cName AS STRING , cClass AS STRING) AS INT
		LOCAL nLine AS INT
		SELF:FindEntity(eType , cName , cClass , nLine)
	RETURN nLine

	METHOD WriteEntity(eType AS EntityType , cName AS STRING , cClass AS STRING , eOptions AS EntityOptions , aEntity AS List<STRING>) AS INT
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		LOCAL nTemp AS INT
		LOCAL nFirst AS INT
		LOCAL lIsUser AS LOGIC
		LOCAL lRemoveFields AS LOGIC
		LOCAL n AS INT

		LOCAL cTab , ceTab AS STRING
		cTab := e"\t"
		ceTab := e"\t"

		IF aEntity:Count == 0
			RETURN 0
		END IF

		cClass := cClass:ToUpper()
		nLine := SELF:FindEntity(eType , cName , cClass)

		IF nLine == 0
			IF eType == EntityType._Class
				nLine := SELF:aLines:Count + 1
			ELSEIF eType == EntityType._Constructor
				nLine := SELF:FindEntity(EntityType._Class , cClass , cClass)
				IF nLine == 0
					RETURN 0
				END IF
				DO WHILE TRUE
					nLine ++
					IF nLine > SELF:aLines:Count
						EXIT
					END IF
					oLine := SELF:GetLine(nLine)
					IF oLine:lEntity .or. oLine:IsEndClass
						EXIT
					END IF
				END DO
			ELSE
				nLine := SELF:FindEntity(EntityType._Class , cClass , cClass)
				IF nLine == 0
					RETURN 0
				END IF
				DO WHILE TRUE
					nLine ++
					IF nLine > SELF:aLines:Count
						EXIT
					END IF
					oLine := SELF:GetLine(nLine)
					IF oLine:IsEndClass
						EXIT
					END IF
					IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() != cClass
						EXIT
					END IF
				END DO
			END IF
			nFirst := nLine
		ELSE
			nFirst := nLine
			IF (eOptions & EntityOptions.NotOverwrite) == EntityOptions.NotOverwrite
				RETURN nFirst
			END IF
			oLine := SELF:GetLine(nLine)
			LOCAL oDeclarationLine AS LineObject
			oDeclarationLine := oLine

			DO WHILE oLine:lOutAmpersand .and. (oLine:LineText:Contains("[") .or. oLine:LineText:Contains("]"))
				nLine ++
				oLine := SELF:GetLine(nLine)
			END DO

			IF (eOptions & EntityOptions.ClearOldFields) == EntityOptions.ClearOldFields
				lRemoveFields := FALSE
				nTemp := nLine
				nTemp ++
				DO WHILE nTemp <= SELF:aLines:Count
					oLine := SELF:GetLine(nTemp)
					IF oLine:lEntity
						EXIT
					END IF
					IF oLine:IsDesignerUserStart
						lRemoveFields := TRUE
						EXIT
					ENDIF
					nTemp ++
				END DO
			ELSE
				lRemoveFields := TRUE
			END IF

			IF lRemoveFields
				nTemp := nLine
				nTemp ++
				DO WHILE nTemp <= SELF:aLines:Count
					oLine := SELF:GetLine(nTemp)
					IF oLine:lEntity .or. oLine:IsEndClass
						EXIT
					END IF
					lIsUser := oLine:IsDesignerUserStart
					SELF:RemoveWEDLine(nTemp)
					IF lIsUser
						EXIT
					ENDIF
				END DO
			END IF

			IF SELF:GetLine(nLine):LineText:ToUpper() == aEntity[0]:ToUpper() .or. (eOptions & EntityOptions.KeepFirstLine) == EntityOptions.KeepFirstLine
				nLine ++
			ELSE
				LOCAL cDeclarationLine AS STRING
				cDeclarationLine := aEntity[0]
				IF oDeclarationLine:oEntity != NULL
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Protected) == EntityModifiers._Protected
						cDeclarationLine := "PROTECTED " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Private) == EntityModifiers._Private
						cDeclarationLine := "PRIVATE " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Partial) == EntityModifiers._Partial
						cDeclarationLine := "PARTIAL " + cDeclarationLine
					ENDIF
					IF _AND(oDeclarationLine:oEntity:eModifiers , EntityModifiers._Internal) == EntityModifiers._Internal
						cDeclarationLine := "INTERNAL " + cDeclarationLine
					ENDIF
					IF .NOT. String.IsNullOrEmpty( oDeclarationLine:oEntity:cImplements:Trim() )
						cDeclarationLine := cDeclarationLine + " IMPLEMENTS " + oDeclarationLine:oEntity:cImplements
					ENDIF
                END IF
                IF eType == EntityType._Constructor
                    LOCAL cOldLine := SELF:GetLine(nLine):LineText:Trim():ToUpper() AS STRING
                    LOCAL nAt := cOldLine:LastIndexOf(')') AS INT
                    IF nAt != -1
                        nAt := cOldLine:IndexOf("CLIPPER", nAt)
                        IF nAt != -1
                            cDeclarationLine += " CLIPPER"
                        ENDIF
                    ENDIF
                ENDIF
				SELF:ReplaceWEDLine(cDeclarationLine , nLine)
				nLine ++
			END IF
			n := 1
		END IF

		DO WHILE n < aEntity:Count
			oLine := SELF:AddWEDLine(aEntity[n] , nLine)
			n ++
		END DO
		IF (eOptions & EntityOptions.AddUser) == EntityOptions.AddUser
			IF eType == EntityType._Class
				oLine := SELF:AddWEDLine(ceTab + cUser + cTagU , nLine)
			ELSE
				oLine := SELF:AddWEDLine(cTab + cUser + cTagU , nLine)
			END IF
		END IF

		IF eType != EntityType._Class
			IF nLine <= SELF:aLines:Count
				oLine := SELF:GetLine(nLine)
				IF oLine:LineText:Trim() != ""
					oLine := SELF:AddWEDLine("" , nLine)
				END IF
			END IF
		END IF

		SELF:CheckCreatedCode()
	RETURN nFirst

	METHOD WriteEndClass(cClass AS STRING) AS VOID
		LOCAL oLine AS LineObject
		LOCAL lFound AS LOGIC
		LOCAL nLine AS INT
		LOCAL n AS INT

		cClass := cClass:ToUpper()
		FOR n := 1 UPTO SELF:aLines:Count
			oLine := SELF:GetLine(n)
			IF lFound
				IF oLine:IsEndClass
					RETURN
				END IF
				IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() != cClass
					EXIT
				END IF
				nLine := n + 1
			ELSE
				IF oLine:lEntity .and. oLine:oEntity:cTypedClassName:ToUpper() == cClass
					lFound := TRUE
					nLine := n + 1
				END IF
			END IF
		NEXT

		IF nLine != 0
			SELF:AddWEDLine("END CLASS" , nLine)
		END IF

	RETURN

	METHOD DeleteLine(nLine AS INT) AS VOID
		SELF:RemoveWEDLine(nLine)
		SELF:ModifiedLine(nLine)
	RETURN

	METHOD DeleteDefines(aDefines AS List<STRING>) AS VOID
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		nLine := 1
		DO WHILE nLine <= SELF:aLines:Count
			LOCAL lDeleted := FALSE AS LOGIC
			oLine := SELF:aLines[nLine - 1]
			IF oLine:eType == LineType.Define .and. .not. String.IsNullOrEmpty(oLine:cArgument)
				FOREACH cDefine AS STRING IN aDefines
					IF cDefine:ToUpper() == oLine:cArgument:ToUpper()
						SELF:DeleteLine(nLine)
						lDeleted := TRUE
						EXIT
					END IF
				NEXT
			ELSEIF oLine:oEntity != NULL .and. oLine:oEntity:eType == EntityType._Define
				FOREACH cDefine AS STRING IN aDefines
					IF cDefine:ToUpper() == oLine:oEntity:cName:ToUpper()
						SELF:DeleteLine(nLine)
						lDeleted := TRUE
						EXIT
					END IF
				NEXT
			END IF
			IF .not. lDeleted
				nLine ++
			END IF
		END DO

		SELF:CheckCreatedCode()

	RETURN

	METHOD AddDefine(cDefine AS STRING , cValue AS STRING) AS VOID
		SELF:AddDefine(cDefine , cValue , TRUE)
	RETURN

	METHOD AddDefine(cDefine AS STRING , cValue AS STRING , lAdd AS LOGIC) AS VOID
		LOCAL cLine AS STRING
		cLine := String.Format("#define {0} {1}" , cDefine , cValue)
//		cLine := String.Format("DEFINE {0} := {1}" , cDefine , cValue)
		IF lAdd
			SELF:AddLine(cLine)
		ELSE
			SELF:InsertLine(1 , cLine)
		END IF
	RETURN

	METHOD AddDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>) AS VOID
		SELF:AddDefines(aDefines , aDefineValues , TRUE)
	RETURN

	METHOD AddDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING> , lAdd AS LOGIC) AS VOID
		FOR LOCAL n := 0 AS INT UPTO aDefines:Count - 1
			SELF:AddDefine(aDefines[n] , aDefineValues[n] , lAdd)
		NEXT
	RETURN

	METHOD RemoveDefines(cWindowName as STRING) AS VOID
		LOCAL oLine AS LineObject
		LOCAL nLine AS INT
		nLine := 1
		cWindowName := cWindowName:ToUpper()+"_"
		DO WHILE nLine <= SELF:aLines:Count
			LOCAL lDeleted := FALSE AS LOGIC
			oLine := SELF:aLines[nLine - 1]
			IF oLine:eType == LineType.Define .and. .not. String.IsNullOrEmpty(oLine:cArgument)
				IF oLine:cArgument:ToUpper():StartsWith(cWindowName)
					SELF:DeleteLine(nLine)
					lDeleted := TRUE
				END IF
			ELSEIF oLine:oEntity != NULL .and. oLine:oEntity:eType == EntityType._Define
				IF oLine:oEntity:cName:ToUpper():StartsWith(cWindowName)
					SELF:DeleteLine(nLine)
					lDeleted := TRUE
				END IF
			END IF
			IF .not. lDeleted
				nLine ++
			END IF
		END DO
		SELF:CheckCreatedCode()
		RETURN

	METHOD AddXSharpDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>) AS VOID
		SELF:AddXSharpDefines(aDefines, aDefineValues, FALSE)

	METHOD AddXSharpDefines(aDefines AS List<STRING> , aDefineValues AS List<STRING>, lStatic AS LOGIC) AS VOID
		LOCAL cLine AS STRING
		LOCAL nLine AS INT
		FOR LOCAL n := 1 AS INT UPTO SELF:aLines:Count
			LOCAL oLine AS LineObject
			oLine := SELF:aLines[n-1]
			nLine := n
			DO CASE
			CASE oLine:oEntity != NULL
				EXIT
//			CASE oLine:IsRegionIn .and. oLine:cArgument:ToUpper() == "DEFINES"
			// grr, I am not setting cArgument for regions
			CASE oLine:IsRegionIn .and. oLine:LineText:ToUpper():Contains("DEFINES")
				nLine ++
				EXIT
			END CASE
		NEXT
		LOCAL cMask AS STRING
		cMask := "DEFINE {0} := {1}"
		IF lStatic
			cMask := "STATIC "+cMask
        ENDIF
        IF nLine == 0
            nLine := 1
        ENDIF
		FOR LOCAL n := 0 AS INT UPTO aDefines:Count - 1
			cLine := String.Format(cMask , aDefines[n] , aDefineValues[n])
			SELF:InsertLine(nLine , cLine)
			nLine ++
		NEXT
	RETURN

END CLASS

[Flags];
ENUM EntityOptions
	MEMBER None := 0
	MEMBER AddUser := 1
	MEMBER NotOverwrite := 2
	MEMBER ClearOldFields := 4
	MEMBER KeepFirstLine := 8
END ENUM

END NAMESPACE