41
SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker [email protected]

SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker [email protected]

Embed Size (px)

Citation preview

Page 1: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

SEM03Having Fun with VFP(some samples from VFX)

Rainer Becker

[email protected]

Page 2: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Rainer Becker

dFPUG– Incorporated UG

– Portal.dfpug.de

German DevCon– Tenth time & price

Localization Toolkit– German, French, Czech (with Igor Vit)

Visual Extend MVP, MCP Wizards & Builders

Page 3: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Mixed Topics &Basic Directions

What are we talking about in general and in this session

Page 4: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Original Session description There are a lot of concepts in VFP that are different from

the official theory but help us with rapid application development. This session will show a set of examples when, where and why using VFP is a great advantage in software development, at least if you know what you are doing. Many of these subtitles might sound like contradictions in itself but maybe you can still use them in your day to day work, e.g. COM-servers made visible, database without integrity rules, VFP for Excel-users, read-only-access-methods, labels for checkboxes, segmented tables and other topics are presented in a fast paced tips & tricks fashion.

Session title might be misleading…

Page 5: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Topics Concepts of Visual

FoxPro in General Concepts of Visual

Extend in General Contradictive Example:

Visible COM-Servers Thumb databases are

more intelligent Configuration with

Dynamic Constants Main Work is user

interface – misc. Tipps

Page 6: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Concepts of Visual FoxPro and Visual Extend

Just to remind you of some basic stuff

Page 7: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visual FoxPro Capabilities

Free unlimited application distribution Free unlimited database distribution Free unlimited reportwriter distribution

– Just add „MODI REPO ?“ to your menue

All in one tool (everything you need) Partially via integration (Help, Install) Fine-Tuned over a decade of development

• Lifecylce extended to 2014 with VFP 9

Page 8: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visual FoxPro Language

Hybrid programming language– Procedural (great for batch jobs)

• Self-modifying code

– Data-aware commands• Compiled commands for local database engine

– Object-based (like Visual Basic)• But Using Containers instead of SimpleFrame

– Object-oriented (with Business Objects)• Ignoring theory of total encapsulation

Page 9: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visual FoxPro Database

Hybrid database commands– Fast Xbase table commands (records)– SQL (groups, CURrent Set of recORds)– Mixed use (xbase on cursor), but my favorite

• Replace all a.val with b.val for seek( a.key, „b“)

„Compiled“ database access– Critic: no strict type checking in language– Vice versa: always database comand strings…

Page 10: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visual FoxPro Special

OOP Special:– Awareness of parent and all other objects – Container subclassing incl. ActiveX-Controls– Ease of Redirection of subclassing– Not Collection-oriented only

PROG Special:– Evaluate, Macro, Excescript, Compile– Definition files are tables– Command window for direct execution

Page 11: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visual Extend Capabilities

Proven framework with standard functions Rich set to enhance enduser application Builders for Rapid App. Development Standardized Design & Layout

– Standard forms for various tasks– Grid-Page for search, Edit-Pages for detail

Sourcecode included except Builders No Business Objects, just 2-Tier-Apps

Page 12: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Rapid Application Development

2 tiers are most often enough for a good and fast application of small to medium size

Customers often are not willing to pay much higher price for maybe lower maintenance cost in the future

Business functions can still be encapsulated in classes which are to be used by the GUI, but these do not have to be clean BOs

Page 13: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Rapid Application Conversion

If you do not try to re-invent the wheel conversion of FoxPro/Windows applications with the help of a framework is pretty fast-forward as you can take over tables, reports and batch-code

It is „kind of a re-write“ but not really as you can reuse your knowledge and rebuild the application very fast in VFP

Page 14: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Recommendation Software-architecture is

very interesting andthree-tiered appswith business objectsare very powerfull

But only if you can afford them or your client is willing to pay the way

Otherwise stick to RAD VFP / VFX is best suited for and build & sell apps

Page 15: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Visible COM-Servers

You were always told to use Business Objects in the middle tier with the advantage they can be re-used via COM

Page 16: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Main object

COM-Server need one OLE-Public object– this does not have to be a business object

• Most often BO are not best choice to be accessed directly from outside of the application!

– It has to be an object• a wrapper for a BO is needed at least

Based on control or container– Called via createobject from other apps– Methods/properties are accessable so they have

to be protected …

Page 17: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Access/Assign and Parameters

Protect Methods / Properties– Small Interface: Hide Properties / Methods– Extensive parameter checking in Methods– Add Assign-Methods to Properties

Assign- & Access-Methods– Vartype and allowed values (list, valid date)– Formatting (Uppercase, remove spaces)– Read-only properties– Internal access only (hidden property switch)

Page 18: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Additional Preparation

Check startmodeINLIST( _vfp.startmode, 2,3,5 )

disable automation server unattended mode=SYS(2335,1)

Integrate error handling=COMRETURNERROR

• Should also be called from access/assign-methods

Set all your settings – Reminder: Press Strg+OK in Options dialog

Page 19: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Project Definition

Add a main program just to have it– Your test program is a good main program

Include Metadata-tables in project Include Config.fpw in project

– SCREEN = OFF (invisible VFP desktop)– RESOURCE=OFF (prevent foxuser creation)– ALLOWEXTERNAL=ON (additional config)

Make visible when needed

Page 20: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Application Execution

Example in Excel:– Dim loRef as Object– On Error Goto SomeError– Set loRef = createobject(„exe.obj“)– … other operations– Set loRef = Nothing

Excel developers love VFP-data-access as it is much easier for them then ODBC/ADO!

Page 21: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Application Rollout

Runtime Directory contains– <Yourserver>.exe– VFP8R.DLL, VFP8RENU.DLL– GDIPLUS.DLL– REGSVR32.EXE

MSVCR70.DLL to system32 Regsvr32.exe vfp8r.dll <Yourserver>.exe /regserver

Page 22: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Recommendation We use WinWord, Excel,

Outlook, Internet Explorer and other applications by calling them…

Why dont we provide the same VISIBLE function-ality to our customers?

Especially Excel-/Word developers are interested!=> additional market…

Page 23: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Intelligent Databases are a problem for programmers

Why make your live even more complicated ?

Page 24: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Reasons for a dumb datastore

Switching backends is a nightmare if validations are additionaly stored in the database (including key generation/RI)

Temporary saving of invalid records is helpfull for a lot of users (lActive/lValid)

Synchronization is a disaster if records can only be added with correct parent/child-relations set

Page 25: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Recommendation If you want to use

different backends:– No valids, RI, triggers

– No DBCX

– Handle logic in apps

A lot of developers have good experience in practise with dumb datastores for switching and synchronisation …

Page 26: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Dynamic Constants

Repetition how to use constants and additional ways to use Constants for later application configuration

Page 27: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Constants Basics

#DEFINE CONSTANT Value– Not working within „“ or ‚‘

• compared to &, example ?„W&B“ with m.b defined

– But working within [ ]

#UNDEFINE CONSTANT Only in program or current method Use #INCLUDE or Class/Form dialog

– Multiple levels of inclusion possible

Page 28: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Conditional Constants

#IF condition (constant or VFP function)– #ELSE, #ELIF cond, #ENDIF

#IFDEF, #IFNDEF constant– #ELSE, #ENDIF

Some examples– #INCLUDE Foxpro.h / Messagebox-example– #IF .F. for comments– Do not use DEFINE … #IF .F. (optimized)

• Except for temporary exclusion of complete class

Page 29: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

More exciting use for constants Array dimensions and column names

– laTemp( lnCounter, CONST_COL_NAME) Translation of strings

– lcMessage = CONT_MSG_TEXT Replacement of commands

– LOCATE FOR CONT_LOC_COND Version dependent functionality

– Both for VFP as well as own version Comment out SUSPEND, DEBUG …

– #DEFINE SUSPEND *, DEBUG * Not working any more: Commentblock

– See above, #DEFINE BeginComment #IF .F. not working

Page 30: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Real world examples

Example 1 / Profiler:Constants for Tablenames, Boundaries, Captions,

Colors, Classes, Combined Messages

Example 2 / VFXSync: Constants for Steps / Messages, Metatablenames,

Metafieldnames, Parameter lists, locate statements, logfilenames, aliases

Page 31: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

In-Between-Code

Place constants before and after calls #DEFINE BEFORE/AFTER/WITHIN * #INCLUDE useroverwrite.h Use running status-variable

– For IF/ENDIF-blocks – To change running var within code

No need for calls to emtpy methods Longer compilation time but faster runtime

Page 32: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Recommendation You can increase the

configurability of your sourcecode with constants

Only in case you really need to configure you change the header-file.

No performance penalty compared to table-driven or any other way to configure your apps

Page 33: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Main work is stillthe user-interface

Most time is still spend of user interface design and validations

Page 34: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

GUI-functions encapsulation

Very powerfull Textmerge()-function can be used in a variety of ways– Addressformatter

– Addressabreviator (not IntelliSense)

Build in button-click and when done save as class for reuse on other forms

You do not have to go multi-tier, but still it is an advantage to use classes and subclassing – if you separate out user interaction (spagetthi-code!)

Page 35: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Source 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 36: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Recommendation Important is not to

clutter code all over your forms but to place them in a central place, might it be buttons in a classlib or a business object

Important is to allow for GUI-mode and just a function call with return value

Page 37: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Famous last words

Use Visual FoxPro in the right way – for you and your applications

Page 38: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

More and more functionality

Page 39: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Fast development experience

With VFP alone as well as with additional tools and frameworks

Page 40: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Best tool for fast development

.NET is stillnot „ready“

PHP / mySQLno option

VFP will be extended even further

Good option for now as 4 GL

Page 41: SEM03 Having Fun with VFP (some samples from VFX) Rainer Becker Rainer.Becker@dFPUG.de

Thank You! Please do not forget the

evaluation form!

Visit our websiteswww.dfpug.de

portal.dfpug.de

forum.dfpug.de

wiki.dfpug.de

www.visualextend.de

www.visualfoxpro.de

www.wizards-builders.com