<< Click to Display Table of Contents >> Templates |
![]() ![]() ![]() |
For its code generation the Connection/Server Editor uses a template file. The current contents of this file is shown below.
The template file consists of a number of sections.
The editor is configurable and allows for a number of different styles of code generation.
// VoAdEdit.TPL
// (c) 2002, Solution Application Software
// EPE, The Netherlands
//
// You may use/alter the template definitions in this file if you want to.
// If you have a suggestion for a template that could be added to a next release
// of Vo2Ado, please send your suggestion to support@heliks.nl
//
// ----------------------------------------------------------------------------------
// This template file contains the source code generation templates
// for most of the Sourcecode generated by the Vo2Ado Server/Connection Editor
// The ConnectionTemplates and ServerTemplates sections contain the names of
// the templates that are shown in the editors.
// Maximum 9 templates per type of template may be used in this file
// Lines without a name are not displayed in the editor
// Each template number should have (a) matching section(s) in this template file
// For connections the editor searches for sections with the name:
// CClass<n>
// CInit<n>
// For Servers the editor searches for sections with the name:
// SClass<n>
// SInit<n>
// SFieldDesc<n>
// The sections for each template are optional:
// Connection Template 2 is an example that has no class definition and where the
// Init method is actually a method of the application.
// This template file also contains the code for the alternative fieldspec code
// generation.
// The following sections apply to fieldspecs
// FsClassNames Template used for generating generic fieldspec class names
// FsClass Template used to generate the class definition
// FsInit Template used to generate the init method of the class
// Finally this template contains code segments for the code generation for callback
// classes and their methods
// This code is located in the sections:
// CbClass Class declaration
// CbStart Start of method
// CbBody Connection specific body
// CbDefault Connection specific body
// CbEnd End of method
// See the Editor's Help file for the list tokens that get replaced by the editor
// ----------------------------------------------------------------------------------
[ConnectionTemplates]
1=Connection Subclass
2=OpenConnection Method (No Class Def)
3=
4=
5=
6=
7=
8=
9=
[ServerTemplates]
1=Default Server Template
2=
3=
4=
5=
6=
7=
8=
9=
// %L gets replaced with the value for Length
// %D gets replaced with the value for Decimals
// For numerics without decimal template N1 is used. Else template N2 is used
[FsClassNames]
C=FsChar%L
M=FsMemo
D=FsDate
N1=FsNum%L
N2=FsNum%L_%D
L=FsLogic
[FsClass]
CLASS %classname% INHERIT %superclass%
[FsInit]
METHOD INIT() CLASS %classname%
LOCAL cPict AS STRING
SUPER:INIT(#%hlname%, "%type%", %LEN%, %dec%)
cPict := "%picture"
IF sLen(cPict) > 0
SELF:Picture := cPict
ENDIF
RETURN SELF
[CBClass]
CLASS %classname%
[CBStart]
METHOD %methodname% (sName, uDefault) CLASS %classname%
LOCAL uRet AS USUAL
DO CASE
[CbBody]
CASE sName == '%name%'
uRet := %uvalue%
[CbDefault]
OTHERWISE
uRet := %uvalue%
[CbEnd]
ENDCASE
RETURN uRet
[SClass1]
CLASS %classname% INHERIT %superclass%
[SInit1]
METHOD INIT(sSource, uConn, nCursorType, nLockType, nOptions ) CLASS %classname%
LOCAL i,nFields AS INT
LOCAL aFieldDesc AS ARRAY
LOCAL nPos AS INT
LOCAL nMaxRecords AS LONG
LOCAL sRecnoColumn AS STRING
LOCAL lLongFldNam AS LOGIC
LOCAL sStatement AS STRING
//
// Elements of SQL statement
// TableName : %tablename%
// ColumnList : %columnlist%
// WhereClause : %whereclause%
// OrderByClause : %orderbyclause%
//
IF IsNil(sSource)
// Build Select statement
sStatement := "%statement%"
sSource := sStatement
ENDIF
lLongFldNam := %longfieldnames%
nMaxRecords := %maxrecords%
sRecnoColumn := "%recnocolumn%"
IF IsNil(nCursorType)
nCursorType := %cursortype%
ENDIF
IF IsNil(nLockType)
nLockType := %locktype%
ENDIF
IF IsNil(uConn)
uConn := AdoGetConnection()
// The connection in the AdoServer Editor was; %connectionname%
ENDIF
SELF:PreInit()
SUPER:INIT(sSource, uConn, nCursorType, nLockType, nOptions, lLongFldNam)
oHyperLabel := HyperLabel{#%tablename%, "%tablename%", "%tablename%", NULL_STRING}
IF oHLStatus = NIL
nFields := ALen(aFieldDesc := SELF:FieldDesc)
FOR i:=1 UPTO nFields
nPos := SELF:FIELDPOS( aFieldDesc[i][DBC_NAME] )
SELF:SetDataField( nPos,;
DataField{aFieldDesc[i][DBC_SYMBOL],aFieldDesc[i][DBC_FIELDSPEC]} )
NEXT
SELF:GoTop()
ENDIF
SELF:PostInit()
RETURN SELF
[SFieldDesc1]
ACCESS FieldDesc CLASS %classname%
//
// This section is modelled after the DbServer Editor Template
//
LOCAL aRet AS ARRAY
LOCAL nFields AS INT
nFields := %fieldcount%
IF nFields > 0
aRet := ArrayCreate(nFields)
%fielddesc%
ELSE
aRet := {}
ENDIF
RETURN aRet
[CClass1]
CLASS %classname% INHERIT AdoConnection
[CInit1]
METHOD INIT() CLASS %classname%
LOCAL cbErr AS CODEBLOCK
LOCAL nTimeOut AS USUAL
cbErr := ErrorBlock({|oErr|_Break(oErr)})
BEGIN SEQUENCE
SUPER:Init()
SELF:ConnectionString := "%connectionstring%"
SELF:CursorLocation := %cursorlocation%
nTimeOut := %timeout%
IF ! IsNil(nTimeOut)
SELF:ConnectiontimeOut := nTimeOut
ENDIF
SELF:Properties:[Item,"prompt"]:Value := AdPromptCompleteRequired
SELF:Open(NIL,%userid%,%password%,NIL)
IF %default%
AdoSetConnection(SELF)
ENDIF
END
ErrorBlock(cbErr)
RETURN SELF
[CInit2]
METHOD Open%classname% CLASS App
LOCAL cbErr AS CODEBLOCK
LOCAL nTimeOut AS USUAL
LOCAL oConn AS AdoConnection
cbErr := ErrorBlock({|oErr|_Break(oErr)})
BEGIN SEQUENCE
oConn := AdoConnection{}
oConn:ConnectionString := "%connectionstring%"
oConn:CursorLocation := %cursorlocation%
nTimeOut := %timeout%
IF ! IsNil(nTimeOut)
oConn:ConnectiontimeOut := nTimeOut
ENDIF
oConn:Properties:[Item,"prompt"]:Value := AdPromptCompleteRequired
oConn:Open(NIL,%userid%,%password%,NIL)
IF %default%
AdoSetConnection(oConn)
ENDIF
END
ErrorBlock(cbErr)
RETURN oConn