TRICKS Tips and Tricks for Microsoft Visual Fox

  • Slides: 28
Download presentation
TRICKS Tips and Tricks for Microsoft Visual Fox. Pro German Fox. Pro User Group

TRICKS Tips and Tricks for Microsoft Visual Fox. Pro German Fox. Pro User Group Rainer Becker Frankfurt/Germany

Rainer Becker • d. FPUG – Online offers – Loose Leaf magazine • •

Rainer Becker • d. FPUG – Online offers – Loose Leaf magazine • • • VFP-Dev. Con Localisation Framework Visual Extend MVP, MCP Wizards & Builders Gmb. H

Session Topics • • Visible COM-Servers Dynamic Constants User Interface Dumb Databases

Session Topics • • Visible COM-Servers Dynamic Constants User Interface Dumb Databases

Visible COM-Servers Business Objects can be turned into COM-Servers to process business logic in

Visible COM-Servers Business Objects can be turned into COM-Servers to process business logic in unattended mode – but you can create visible COM-servers to…

Main object • COM-Server need a OLE-Public main object – It does not have

Main object • COM-Server need a OLE-Public main object – It does not have to be a business object • Very often real business objects are not suited to be called from outside / other applications (especially via Internet) – But it has to be an object • At least a Wrapper-Object is needed • Based on controls or container class – Called via „createobject“ from other applications – Methods/Properties are visible/changeable – Therefore need to be „protected“

Access and Assign Methods • Protected Methods / Properties – Small interface: Hiding Methods

Access and Assign Methods • Protected Methods / Properties – Small interface: Hiding Methods / Properites – Extensive parameterchecking in methods – Access/Assing-methods for properties • Assign- & Access-Methods – – Vartype and valid values (value list, date range, …) formatting (upper case, spaces, …) Write-protect properties Internal properties (hidden property switch)

Additional preparation • Check startmode INLIST( _vfp. startmode, 2, 3, 5 ) • Disable

Additional preparation • Check startmode INLIST( _vfp. startmode, 2, 3, 5 ) • Disable Automation Server Unattended Mode =SYS(2335, 1) • Integrate error handling =COMRETURNERROR • Also from/within Access/Assign-Methods • Set all your settings – Old trick: Strg+OK lists all options…

Project definition • Add main program… – E. g. use test program for that

Project definition • Add main program… – E. g. use test program for that • Include metadata tables • Include Config. fpw – SCREEN = OFF (invisible VFP desktop) – RESOURCE=OFF (prevent foxuser creation) – ALLOWEXTERNAL=ON (additional config) • Turn visible on if/when necessary

Application Execution • Example in Excel: – – – Dim lo. Ref as Object

Application Execution • Example in Excel: – – – Dim lo. Ref as Object On Error Goto Some. Error Set lo. Ref = createobject(„exe. obj“) … other operations Set lo. Ref = Nothing • Excel-developer love VFP-based data access, as it is much easier than ODBC/ADO for them! – No redefinition of all SQLs if field added/removed – Problems with transfer of memofields

Application Rollout • Runtime subdirectory contains – – <Your. Server>. exe VFP 9 R.

Application Rollout • Runtime subdirectory contains – – <Your. Server>. exe VFP 9 R. DLL, VFP 9 RENU. DLL GDIPLUS. DLL REGSVR 32. EXE • MSVCR 70. DLL in system 32 • Regsvr 32. exe vfp 9 r. dll • <Yourserver>. exe /regserver

Summary COM-Server • We use Win. Word, Excel, Outlook, Internet Explorer and other applications

Summary COM-Server • We use Win. Word, Excel, Outlook, Internet Explorer and other applications by calling them • Why dont we offer the same VISIBLE functionality our customers? • Especially Excel-/Worddeveloper/user are an additional market…

Dynamic Constants are constantly used to seldom - and should be more dynamic anyhow.

Dynamic Constants are constantly used to seldom - and should be more dynamic anyhow. Underestimated power…

Base knowledge • #DEFINE CONSTANT Value – Does not work within „“ or ‚‘

Base knowledge • #DEFINE CONSTANT Value – Does not work within „“ or ‚‘ • Different from &, e. g. ? „W&B“ with m. b = value – But does work with brackets! [Beware] • #UNDEFINE CONSTANT • In programs or current method • #INCLUDE or Class/Form Dialog – Recursive calls possible

Conditional constants • #IF Condition (constant or integrated VFP function at compile/design time) –

Conditional constants • #IF Condition (constant or integrated VFP function at compile/design time) – #ELSE, #ELIF condition, #ENDIF • #IFDEF, #IFNDEF constant – #ELSE, #ENDIF • Example – #INCLUDE Foxpro. h / Messagebox – #IF. F. for comments – DEFINE … #IF. F. does not work (optimized) • Except for temporarily disable complete classes

Additional use • Array dimensions and row / column names – la. Temp( ln.

Additional use • Array dimensions and row / column names – la. Temp( ln. Counter, CONST_COL_NAME) • Translation of strings for localization – lc. Message = CONT_MSG_TEXT • Replacement of commands, command lines or conditions – LOCATE FOR CONT_LOC_COND • Version dependant functionality – for VFP-version or own program versions • Commenting out of SUSPEND, DEBUG … – #DEFINE SUSPEND *, DEBUG * • Does not work no more: Commentblock – See above, #DEFINE Begin. Comment #IF. F. does not work

Real world examples • Example 1 / Profiler: constants for tablenames, value ranges, captions,

Real world examples • Example 1 / Profiler: constants for tablenames, value ranges, captions, colors, classes, assembled multi-part messages • Example 2 / VFXSync: Contants for steps /messages, meta table names, meta table field names, parameter lists, Locate-commands, logfilenames, table alias

In-Between-Code • • Contants before and after function calls #DEFINE BEFORE/AFTER/WITHIN * #INCLUDE useroverwrite.

In-Between-Code • • Contants before and after function calls #DEFINE BEFORE/AFTER/WITHIN * #INCLUDE useroverwrite. h Variables for application status – For IF/ENDIF-sections – To change statusvar within code • Advantage: No calls to empty methods • More compile-time but faster run-time

Summary Constants • Configurability drastically enhanced by using constants • Only if you really

Summary Constants • Configurability drastically enhanced by using constants • Only if you really want to change application you change the headerfiles • No Performance-Penalty compared to all other ways of configuring application for special needs

User Interface Majority of programming time is used for user interface design and user

User Interface Majority of programming time is used for user interface design and user interface logic (validations, refresh)

Encapsulation of functions • Very often a special business object is to complex and

Encapsulation of functions • Very often a special business object is to complex and by far to much overhead • Save functionality in additional button method and call it via button click • Save button as class and replace button control with class for later reuse in other places • You do not really have to have multi-tiered architecture – but classes do have big advantages, especially to separate complex interactions from form code

Example Addressformater-button • Powerfull Textmerge()-function can be used in multiple ways: – – –

Example Addressformater-button • Powerfull Textmerge()-function can be used in multiple ways: – – – Addressformatter Addressabreviator (not Intelli. Sense) Scripting End user makros Mail merge

Example Textmerge • Format-Memofield contains various <<alias. fieldname>> in correct position plus hardcoded addtional

Example Textmerge • Format-Memofield contains various <<alias. fieldname>> in correct position plus hardcoded addtional information like country short code SELECT adressformat LOCATE FOR adressformat. country = lc. Country ; AND adressformat. active =. T. IF FOUND() lc. Format = adressformat lc. Format = TEXTMERGE( lc. Format ) IF NOT EMPTY( lc. Format ) lc. Message = "adress copied to clipboard" _CLIPTEXT = lc. Format ENDIF

Summary User Interface • Do not scatter your code all over your application •

Summary User Interface • Do not scatter your code all over your application • At least place special functionality in classes • It does not have to be a business object

Dumb Databases Intelligent database are a problem sometimes. Why should be make our programmer

Dumb Databases Intelligent database are a problem sometimes. Why should be make our programmer lives even more complicated…

Reasons for stupid databases • Switching to backend-database is a nightmare if validations are

Reasons for stupid databases • Switching to backend-database is a nightmare if validations are saved within the database • Temporarily saving of records is impossible – Even backups of records have to comply to all rules • Different record types in the same table makes validation rules by far to complex • Rules of user interface and business logic duplicated in database results in much higher maintenance costs – Multiplied by number of backends supported

Synchronization • Synchronization is only possible in the correct order of parent/child-relations • Synchronization

Synchronization • Synchronization is only possible in the correct order of parent/child-relations • Synchronization only possible between databases with same structure • … and same level of validation code • Synchronization example code has been shown throughout the session • Will be available as integrated or separate module for our framework Visual Extend

Summary Databases • Place only base logic within the database and no complex validations

Summary Databases • Place only base logic within the database and no complex validations • Application logic should stay in the application • Many developers found that it eases their daily work if the database is not to intelligent! • Or use tools like XCASE to generate database rules

Thank You! Visit our websites at http: //www. dfpug. de, http: //portal. dfpug. de,

Thank You! Visit our websites at http: //www. dfpug. de, http: //portal. dfpug. de, http: //forum. dfpug. de, http: //newsletter. dfpug. de, http: //devcon. dfpug. de, http: //roadshow. dfpug. de, http: //www. visualextend. com, http: //www. linuxtransfer. de, http: //www. visualfoxpro. de