The MiniPascal supplement provides a number of predefined subroutines which you can use in your macros to provide added functionality and speed your development time.
Using 'em
To use the supplemental routines, simply copy the subroutine you wish to use from the library files, and paste it in the appropriate location in your macro, after the VAR section, but before the BEGIN statement of your macro's main section. The subroutine is then available for use in your macro.
To use the subroutine, call it like any other standard MiniPascal procedure.
Example - Defining a Subroutine
Procedure DupLayer; VAR OldLNm,LNm:STRING; LSc,bZ,dZ:REAL; V,TOb,TSOb:INTEGER; {-- subroutine section } Procedure LayerInfo(LayerHd:HANDLE;VAR LayerName:STRING;VAR LayerScale,baseZ,deltaZ:REAL; VAR LayerVis,TotalObjs,SelectObjs:INTEGER); BEGIN LayerName:=GetLName(LayerHd); LayerScale:=GetLScale(LayerHd); LayerVis:=GetLVis(LayerHd); GetZVals(baseZ,deltaZ); TotalObjs:=GetNumObjs(LayerHd); SelectObjs:=NumSObjs(LayerHd); END; {-- end subroutines } {-- Macro main } BEGIN LayerInfo(ActLayer,LNm,LSc,bZ,dZ,V,TOb,TSOb); ... ... ...
Using Subroutines As Parts Of Other Subroutines
You can also use the supplement subroutines as part of your own custom subroutines, to provide services where needed. The definition method is basically the same: copy the subroutine you want to use from the library files, and paste into your subroutine between the end of the VAR section and the beginning of your subroutine main. The subroutine will then be available for use in your code.
By defining the scope of the supplement function or procedure within your subroutine, it's services will be available only to your custom subroutine. If you need to use the supplement subroutine's services in places other than your own custom code, define the supplement procedure or function as a subroutine of your main macro(global scope).
Example - Using Other Subroutines Within a Subroutine
{-- the BuildDBColumnRF subroutine from the supplement} Procedure BuildDBColumnRF(WSName,Record,Field:STRING;Row,Column:INTEGER); VAR theCriteria:STRING; {-- other subroutines used to provide services for BuildDBColumnRF } Procedure ActivateWS(theWkshtName:STRING); VAR SSHd:HANDLE; BEGIN SSHd:=GetObject(theWkshtName); SelectSS(SSHd); END; Function BuildRecCrit(Record,Field:STRING;RecordOnly,UseEqual:BOOLEAN):STRING; VAR Q,CriteriaString:STRING; BEGIN Q:=Chr(39); IF RecordOnly THEN BEGIN CriteriaString:=Concat('(R IN[',Q,Record,Q,'])'); IF UseEqual THEN CriteriaString:=Concat('=',CriteriaString); END ELSE BEGIN CriteriaString:=Concat('(',Q,Record,Q,'.',Q,Field,Q,')'); IF UseEqual THEN CriteriaString:=Concat('=',CriteriaString); END; BuildRecCrit:=CriteriaString; END; {-- end subroutines for BuildDBColumnRF } BEGIN ActivateWS(WSName); LoadCell(Row,Column,BuildRecCrit(Record,Field,FALSE,TRUE)); END; {-- end of BuildDBColumnRF }
An Example - Duplicate Layer
Duplicate Layer uses subroutines to provide the services necessary to retrieve layer information and create a duplicate of the specified layer. The macro makes use of the subroutines LayerInfo() and CreateNewLayer(), which are found in this supplement.
Procedure DupLayer; VAR OldLNm,LNm:STRING; LSc,bZ,dZ:REAL; V,TOb,TSOb:INTEGER; {-- Subroutines } Procedure LayerInfo(LayerHd:HANDLE;VAR LayerName:STRING;VAR LayerScale,baseZ,deltaZ:REAL; VAR LayerVis,TotalObjs,SelectObjs:INTEGER); BEGIN LayerName:=GetLName(LayerHd); LayerScale:=GetLScale(LayerHd); LayerVis:=GetLVis(LayerHd); GetZVals(baseZ,deltaZ); TotalObjs:=GetNumObjs(LayerHd); SelectObjs:=NumSObjs(LayerHd); END; Procedure CreateNewLayer(LayerName:STRING;LayerScale,LayerVis:INTEGER;BaseZ,Thk:REAL; LayerFF,LayerFB,LayerPF,LayerPB:LONGINT); VAR LHd:HANDLE; DupLayerAbort : BOOLEAN; BEGIN DupLayerAbort:=FALSE; LHd:=FLayer; WHILE (LHd<>NIL)&(NOT DupLayerAbort) DO BEGIN IF GetLName(LHd)=LayerName THEN DupLayerAbort:=TRUE ELSE LHd:=NextLayer(LHd); END; IF NOT DupLayerAbort THEN BEGIN Layer(LayerName); SetScale(LayerScale); SetZVals(BaseZ,Thk); LFillFore(LayerFF); LFillBack(LayerFB); LPenFore(LayerPF); LPenBack(LayerPB); IF LayerVis=0 THEN ShowLayer ELSE IF LayerVis=1 THEN GrayLayer ELSE IF LayerVis =2 THEN HideLayer; END; END; {-- End subroutines } {-- Macro main } BEGIN LayerInfo(ActLayer,LNm,LSc,bZ,dZ,V,TOb,TSOb); OldLNm:=LNm; LNm:=Concat(LNm,'a'); CreateNewLayer(LNm,LSc,V,bZ,dZ,0,255,0,255); Layer(OldLNm); SelectAll; DoMenuText('Copy'); DSelectAll; Layer(LNm); DoMenuText('Paste In Place'); DSelectAll; END; Run(DupLayer);