tips and tricks for microsoft visual foxpro

28
Tips and Tricks for Microsoft Visual FoxPro German FoxPro User Group Rainer Becker Frankfurt/Germany TRICKS

Upload: desmond-clear

Post on 05-Jan-2016

125 views

Category:

Documents


3 download

DESCRIPTION

TRICKS. Tips and Tricks for Microsoft Visual FoxPro. German FoxPro User Group Rainer Becker Frankfurt/Germany. Rainer Becker. dFPUG Online offers Loose Leaf magazine VFP-DevCon Localisation Framework Visual Extend MVP, MCP Wizards & Builders GmbH. Session Topics. Visible COM-Servers - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Tips and Tricks for Microsoft Visual FoxPro

Tips and Tricks forMicrosoft Visual FoxPro

German FoxPro User GroupRainer Becker

Frankfurt/Germany

TRICKS

Page 2: Tips and Tricks for Microsoft Visual FoxPro

Rainer Becker• dFPUG

– Online offers– Loose Leaf magazine

• VFP-DevCon• Localisation• Framework Visual Extend• MVP, MCP• Wizards & Builders GmbH

Page 3: Tips and Tricks for Microsoft Visual FoxPro

Session Topics

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

Page 4: Tips and Tricks for Microsoft Visual FoxPro

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…

Page 5: Tips and Tricks for Microsoft Visual FoxPro

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“

Page 6: Tips and Tricks for Microsoft Visual FoxPro

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)

Page 7: Tips and Tricks for Microsoft Visual FoxPro

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…

Page 8: Tips and Tricks for Microsoft Visual FoxPro

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

Page 9: Tips and Tricks for Microsoft Visual FoxPro

Application Execution• Example in Excel:

– Dim loRef as Object– On Error Goto SomeError– Set loRef = createobject(„exe.obj“)– … other operations– Set loRef = 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

Page 10: Tips and Tricks for Microsoft Visual FoxPro

Application Rollout• Runtime subdirectory contains

– <YourServer>.exe– VFP9R.DLL, VFP9RENU.DLL– GDIPLUS.DLL– REGSVR32.EXE

• MSVCR70.DLL in system32• Regsvr32.exe vfp9r.dll• <Yourserver>.exe /regserver

Page 11: Tips and Tricks for Microsoft Visual FoxPro

Summary COM-Server• We use WinWord, Excel,

Outlook, Internet Explorer and other applications by calling them

• Why dont we offer the same VISIBLE functionality our customers?

• Especially Excel-/Word- developer/user are an additional market…

Page 12: Tips and Tricks for Microsoft Visual FoxPro

Dynamic Constants

Constants are constantly used to seldom - and should be more

dynamic anyhow. Underestimated power…

Page 13: Tips and Tricks for Microsoft Visual FoxPro

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

Page 14: Tips and Tricks for Microsoft Visual FoxPro

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

Page 15: Tips and Tricks for Microsoft Visual FoxPro

Additional use• Array dimensions and row / column names

– laTemp( lnCounter, CONST_COL_NAME)

• Translation of strings for localization– lcMessage = 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 BeginComment #IF .F. does not work

Page 16: Tips and Tricks for Microsoft Visual FoxPro

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

Page 17: Tips and Tricks for Microsoft Visual FoxPro

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

Page 18: Tips and Tricks for Microsoft Visual FoxPro

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

Page 19: Tips and Tricks for Microsoft Visual FoxPro

User Interface

Majority of programming time is used for user interface design and user interface logic (validations,

refresh)

Page 20: Tips and Tricks for Microsoft Visual FoxPro

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

Page 21: Tips and Tricks for Microsoft Visual FoxPro

Example Addressformater-button• Powerfull Textmerge()-function can be

used in multiple ways:

– Addressformatter– Addressabreviator (not IntelliSense)– Scripting – End user makros– Mail merge

Page 22: Tips and Tricks for Microsoft Visual FoxPro

Example Textmerge• Format-Memofield contains various <<alias.fieldname>> in

correct position plus hardcoded addtional information like country short code

SELECT adressformatLOCATE FOR adressformat.country = lcCountry ;

AND adressformat.active = .T.IF FOUND()

lcFormat = adressformat.formatlcFormat = TEXTMERGE( lcFormat )IF NOT EMPTY( lcFormat )

lcMessage = "adress copied to clipboard"_CLIPTEXT = lcFormat

ENDIF ENDIF

Page 23: Tips and Tricks for Microsoft Visual FoxPro

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

Page 24: Tips and Tricks for Microsoft Visual FoxPro

Dumb Databases

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

complicated…

Page 25: Tips and Tricks for Microsoft Visual FoxPro

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

Page 26: Tips and Tricks for Microsoft Visual FoxPro

Synchronization• Synchronization is only possible in the

correct order of parent/child-relations• Synchronization only possible between

data-bases 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

Page 27: Tips and Tricks for Microsoft Visual FoxPro

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

Page 28: Tips and Tricks for Microsoft Visual FoxPro

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