dynamic constants
Download
Skip this Video
Download Presentation
Dynamic Constants

Loading in 2 Seconds...

play fullscreen
1 / 44

Dynamic Constants - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

Dynamic Constants. Session V16. Rainer Becker. dFPUG, Germany. Who Am I?. German FoxPro User Group http://www.dfpug.de/forum German VFP DevCon FoxX Professional (4x200 pages) Wizards & Builders GmbH http://www.wizards-builders.com MVP, MCSD, speaker/writer But I am not bilingual !.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Dynamic Constants' - elmo-perry


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
dynamic constants

Dynamic Constants

Session V16

Rainer Becker

dFPUG, Germany

FoxTeach 2001

slide2

Who Am I?

  • German FoxPro User Group
    • http://www.dfpug.de/forum
    • German VFP DevCon
    • FoxX Professional (4x200 pages)
  • Wizards & Builders GmbH
    • http://www.wizards-builders.com
  • MVP, MCSD, speaker/writer
    • But I am not bilingual !

FoxTeach 2001

constant basics

Constant Basics

Which commands are available? What do I need to know?

FoxTeach 2001

basic constant basics
Basic Constant Basics
  • All commands with a „#“ in front are pre-processor commands
  • Those commands are NOT compiled into the final program
  • Instead they decide
    • which values are used (#DEFINE) within
    • which lines are compiled (#IF, #IFDEF) into the final program

FoxTeach 2001

define constants
DEFINE Constants
  • #DEFINE CONSTANT Value
    • Instead of hardcoded values or unchanging repeated variables
  • Naming conventions: Uppercase
  • Not working within „ “ or ‚ ‘
    • but working within [ ]-brackets
    • Important for Type-command a.o.

FoxTeach 2001

re define constants
Re-DEFINE Constants
  • You can #DEFINE existing const
    • If syntactically identical
    • Otherwise you get an error, so
  • #UNDEFINE CONSTANT
    • For redefining constants
  • But you can #DEFINE test #DEFINE fun „Joke“ / test
    • ? Fun => „Joke“

FoxTeach 2001

header files
Header Files
  • #DEFINES only valid within program (not only current procedure/function) or within current method (not class)
    • You would have to repeat defines in each
  • #INCLUDE <file>.h in code
    • Current directory or SET PATH
    • Recursive inclusion of header files
  • „Include“ Dialogue in Form or VCX
  • Standard Include in Options

FoxTeach 2001

conditional compilation
Conditional Compilation
  • #IF <condition> = .T./!=0
    • Constants (.T.)
    • VFP functions (version())
    • No variables, functions, API-calls
  • #ELSE = .F. / = 0
    • IF- or ELSE-codeblock compiled
  • #ELIF <condition> = .T./!=0
    • not ELSEIF <g>
  • #ENDIF

FoxTeach 2001

constant dependent compilation
Constant-dependent Compilation
  • #IFDEF
    • Depending on existing #DEFINE
  • #IFNDEF
    • Depending on no #DEFINE
    • E.g. remark out #DEFINE with *
  • #ELSE, #ENDIF
    • No #ELSEIF

FoxTeach 2001

basic preprocessor advantages
Basic Preprocessor Advantages
  • #DEFINE
    • often faster than vars (numeric)
    • Reduces occurence of repetitive code that needs to be changed later
    • Increases readability
  • #IF / #IFDEF
    • reduces actually compiled code

FoxTeach 2001

basic preprocessor disadvantages
Basic Preprocessor Disadvantages
  • #DEFINE
    • Does not allow parameters so you cannot replace function / method calls (with or without parameters)
  • #IF / #IFDEF
    • Does not allow „#FUNCTION“ so you cannot call your own complex decision logic

FoxTeach 2001

classic use of constants

Classic use of Constants

Typical examples in literature and code examples where and how to use constants in Visual FoxPro (additionaly to constant values)

FoxTeach 2001

messagebox parameters
Messagebox Parameters
  • #INCLUDE FOXPRO.H
  • Messagebox( „my title“ , MB_ICONEXCLAMATION + MB_SYSTEMMODAL )
    • Instead of 48 + 4096
  • Should be used generally for function parameters for readability and ease of later changes / ext.

FoxTeach 2001

toolbar names
Toolbar Names
  • See VISUAL CODEBOOK for example of internationalized toolbar names
  • Can be used for other VFP-window names
  • Should be used for internal window / toolbar names

FoxTeach 2001

shorten typed code
Shorten Typed Code
  • #DEFINE CRLF Chr(10)+chr(13)
    • Easier to read, less repeating code
  • #DEFINE PARENT this.parent
    • Don‘t do it, its unsurvivable - Never overwrite reserved words by accident!
  • #DEFINE GRANDPARENT this.parent.parent
    • Shortens reference to grandpa

FoxTeach 2001

overwrite unwanted commands
Overwrite unwanted Commands
  • #DEFINE SUSPEND *
    • Same for DEBUG and other commands not usable in .EXE
  • #DEFINE ASSERT *
    • Use SET ASSERT OFF instead
  • #DEFINE WAIT *
    • Or define a syntax error ...

FoxTeach 2001

array dimensions values
Array Dimensions / Values
  • Especially useful for readability:#DEFINEs for array elements
    • Have you ever converted FP stuff?
  • Example for ADIR
    • #DEFINE adir_name 1
    • #DEFINE adir_size 2
    • #DEFINE adir_date 3
    • #DEFINE adir_time 4
    • #DEFINE adir_attr 5

FoxTeach 2001

version dependent functions
Version-dependent Functions
  • #IF „0x.00“ $ version()
    • Set library to FoxTools additive
    • Handle other differencesbetween product versions

FoxTeach 2001

demo beta version
Demo/Beta Version
  • #DEFINE demoversion .T.
    • Limit number of records
    • Disable special functions
  • #DEFINE betaversion .T.
    • Limit maximum date of usage
    • Disable functions if „not implemented yet“

FoxTeach 2001

additional use of constants

Additional Use of Constants

Where else can you use Constants in traditional coding?

FoxTeach 2001

defines for comment blocks
DEFINEs for Comment Blocks
  • #DEFINE BeginComment #IF .F.
  • #DEFINE EndComment #ENDIF
  • Useful if you heavily comment your code

FoxTeach 2001

translation
Translation
  • Often seen in frameworks
    • Strings in menus and programs defined in a header file, label/form captions set by a function
  • Various practical problems
    • Works only if source-code provided
    • Only one language active (therefore useless for web server/multi-user)

FoxTeach 2001

access methods for arrays
Access Methods for Arrays
  • Variant on parameter passing and array column definition
  • Usable to translate character parameters passed to an access/assign-method of an array to real offset
    • See backcolor-example in VFP

FoxTeach 2001

syntax conversion
Syntax Conversion
  • Fun from Peter Herzog (inventor of Active FoxPro Pages / AFP)
  • Replace commands including clauses with compact words (e.g. „bavarian“)
    • Would be nice in command window
  • Limited to commands, cannot be used for functions
  • Might be fun for programmers, but could be a real help for end-users

FoxTeach 2001

scripting language
Scripting Language
  • Write out memo to file and add lparameters and #include-file
  • Compile and run with object references as parameters

Examples:NEWADDR this.bizobj.datanew()ADDRNAME do setprop with this.bizobj, „adress.name“,

FoxTeach 2001

what else to do with constants

What else to do with Constants?

See another set of possible uses of constants

FoxTeach 2001

configuration
Configuration
  • Use constants instead of properties for general configuration in case of seldomly changed options
  • You can change your mind later on the fly by changing the constant to „this.property“ – but not vice versa
  • Works best with standardized configuration loading mechanism which can be extended

FoxTeach 2001

functional exclusion
Functional Exclusion
  • Exclude unneeded functionality with #IF CONSTANT from .h-file Examples:
    • Call to BackDoor (Steven Black)
    • Call to installation / update apps
    • Call to oneways (one-time-install)
    • Call to config.fpw-creation
    • Login procedure (if no security)

FoxTeach 2001

performance measurement
Performance Measurement
  • Place speed log code within #IFDEF
  • Place alternate code (for speed comparison of alternatives) within #IF..#ELSE.. #ENDIF
  • Place disturbing user interface code within #IFNDEF

FoxTeach 2001

reference redirection
Reference Redirection
  • Reference to global application object with constant
    • In case you change your mind later
  • Reference to sub-objects on global application object
    • Use global and sub-ref in code
  • Reference to global superclass
    • Global (datasession-switching) or on form

FoxTeach 2001

an interlude on superclasses
An Interlude on Superclasses
  • All GUI elements share behaviour
    • Init, Gotfocus / lostfocus
  • Subsets of GUI elements share additional identical behaviour
    • Lineeditfields like textbox / spinner
    • Container like Container, column, page
  • VFP lacks „superclass“ of all GUI elements as well as subclasses
  • Call superclass w. constant-reference globally / placed on form (datasession)

FoxTeach 2001

reference revisited
Reference Revisited
  • Do not use absolute references between objects at the same tier
    • Delayed instantiation generates errors
    • Later integration of additional tier breaks
  • Never use absolute references to objects on different tiers
    • Tier might not be available and you need to reference a wrapper instead

FoxTeach 2001

redirective conversion
Redirective Conversion
  • Moving procedural code to objects is a pain if you can‘t do it at once with lots of time, maybe faster:
    • Map public variables to properties
    • Map function calls to methods
    • Move to VCX later
      • Reformat procedure header
      • Fill „reserved3“ and recompile

FoxTeach 2001

parent class redirection
Parent Class Redirection
  • Use DEFINE CLASS <Name> AS <CONSTANT> in classlibs for others
  • Important for framework integration into larger projects
  • Allows redirection to own base classes instead of hardcoded hierarchy
    • Or use “zig-zag subclassing“...
  • But: Only really useful if working in code, not in visual classlibs...

FoxTeach 2001

addobject redirection
Addobject Redirection
  • Use Addobject( <Name>, <CONSTANT>) for aggregation
  • Important for framework integration into larger projects
  • Allows redirection of aggregation to own service classes instead of hardcoded hierarchy
    • See complex concepts for services...
  • But: Only really useful if working in code, not in classlibs...

FoxTeach 2001

problem complex methods
Problem: Complex Methods
  • Changing behavior of parent class in subclass needs high granularity
    • Even smallest functionality forces a new method for overwriting
    • Complex functions need admin function to call subfunctions
    • Change of admin function flow needs rewriting of the whole function
  • Real problem with framework updates

FoxTeach 2001

solution in between hooks
Solution: In-Between-Hooks
  • Place CONSTANTS before and after each and every functionality
    • BEFORE_CALL_LOGIN
    • Code or call for login functionality
    • AFTER_CALL_LOGIN
  • DEFINE constants with asterisk
  • Include additional empty .h-file
  • Use a variable for status and placeIF llOk ... ENDIF before / after block

FoxTeach 2001

hook examples
Hook Examples
  • Exclude whole functionality
    • BEFORE: #IF .F. / AFTER: #ENDIF
  • Define execution condition
    • BEFORE: if this.cond() / AFTER: endif
  • Use Hooks for changes of running flags or place constant within for flags
    • WITHIN: llOk = this.myfunc()

FoxTeach 2001

general framework configuration
General Framework Configuration
  • #INCLUDE additional custom.h
  • #UNDEFINE constants in custom.h if changes wanted
    • Otherwise you get an error!
  • #DEFINE new value of any kind (function / method-call as you like)
  • Everyone can configure without interfering with code updates

FoxTeach 2001

material and updates

Material and Updates

Where to go from here ? Where to find additional information ?

FoxTeach 2001

what should not be included
What should not be included!
  • As VFP is built in C++ of Visual Studio, it includes - additionally to your header files - the c-header-files if they are on your machine
  • Beware of duplicates !!!

FoxTeach 2001

additional material
Additional Material
  • „Programming the Visual FoxPro Compiler“ by Dennis Hevener in FoxPro Advisor, November 1998
  • Various Code examples in the „dFPUG Baseclasses“ in library „VFP solutions“ at www.dfpug.de/forum
  • See code example of session V17 „Building Server Services“

FoxTeach 2001

foxteach web update page

FoxTeach Web Update Page

www.dbcentral.com

This session will NOT have web updates

(except for an updated slideshow)

FoxTeach 2001

thank you

Thank you!

Please remember to fill out your evaluation.

FoxTeach 2001

ad