applied dws2 programming
TRANSCRIPT
Rel
ease
Can
dida
te2
Applied DelphiWebScript II Programming
DelphiWebScript Community
12th August 2003
Rel
ease
Can
dida
te2
Rel
ease
Can
dida
te2
to all members of the DWS community
Rel
ease
Can
dida
te2
Rel
ease
Can
dida
te2
This isRelease Candidate 2of Applied DelphiWebScript II Programming.
Please understand that this document still lacks serious proof-reading. Be aware that themain author of the original version of this document is no native English speaker. If youfind grammar mistakes, mistakenly used words, bad style or otherbad things, please contacthim atmailto:[email protected] .
If you think that a specific topic you can not find should definitely go into this document,we strongly encourage you to drop us a note. (Use the forum at our sourceforge page!)
This document was created with MiKTEX and LYX on Windows. Several LATEX packageshave been used in order to create this document:framed, eso-pic, color, rotating, array,listingsandhyperref.
Date Version of Document
08/12/2003
• Added HowTos contributed from Yeoh RayMond
• Added HowTo for emulating dynamic arrays
• Bugfixed TWindow class
• Added StringsUnit description
• Added LeftStr, RightStr and MidStr08/11/2003 Changes contributed by Yeoh Ray Mond08/08/2003 Release Candidate 1
Still to do:
• add explanations to COMConnector
• Finish section 2.2 -> Explain IInfo
A special “Thank you” goes out to
Yeoh Ray Mond for providing lots of corrections and helpful suggestions
5
Rel
ease
Can
dida
te2
6
Rel
ease
Can
dida
te2Foreword
Applied DelphiWebScript II Programmingaims to provide you with an in-depth coverage of theDWScomponent, the intentions we had when creating the interpreter, some outlook on futuredevelopments and of course it will provide you with the necessary examples and hints for build-ing professionalDWSdriven applications - regardless if you are developing web applications or“old style” GUI applications.
This document has been brought to you by long standing members of the community andsome of the most activeDWSdevelopers. We hope that it’ll answer all questions you possiblymight have regardingDWSand that it is able to remove any misconceptions that might havearisen over time.Most probably the name DelphiWebScriptitself is already source for such misconceptions, as itimplies thatDWSis for web scripting only. This is, however, not the case at all. In factDWSis a Delphi component that takes some script (written in a subset of Delphi), compiles it intoan abstract syntax tree and then runs the script. The reason for the “WebScript” in the name isthe ability of DWS to run any kind of input through a so called filter before starting the compilecycle. The filter is responsible for ”morphing” the input into a valid DWS script the compilerexpects. Currently one filter ships with the DWS distribution:HTMLFilter.
The HTMLFilter expects a text file as input and does nothing else but wrap a “print” com-mand around the text found in the file. Of course this description is an over simplification, asHTMLFilter allows you to insert DWS scripts within special marked blocks in the text file, butyou get the basic idea.
Back in the year 2000 (you remember the Internet hype?), Delphi 5 was lacking some con-venient way of producing server side scriptable HTML pages. Delphi only featured the wellknown TPageProducer. One main disadvantage of this component was that the CGI or ISAPImodule had to be recompiled every time a change in the application logic (i.e. within the eventsof the page producer component) was made. DI Hannes Hernler by that time came across theTScriptcomponent written by Matthias Ackermann and saw the potential of a modifiedTScriptthat could parse native HTML for his web applications.
To make a long story short: Matthias Ackermann delivered a modifiedTScriptcomponentand it was agreed to make this component widely available, thus making it open source underthe MPL license. By that time it was also decided to rename the component toDWS, as the mainfuture was seen in developing web applications.
Since then many things happened: The Internet hype vanished, DWS was re-written fromscratch (DWS II) several research projects were made for DWS (Session Server, automatic wrap-per generator, Package Connector, Debugger just to name a few) and even DWS3 was started inour CVS repository at sourceforge.
7
Rel
ease
Can
dida
te2
Today DWS II is available for Delphi 5, Delphi 6 and Delphi 7 (it shipped with companionCD of Delphi 6 and Delphi 7), Kylix 3 and Borland C++ Builder.
DWSwould not have been possible without the work of many people from all over the world!So we would like to say a special “Thank You” to all who have contributed toDWS.
Thanks to...
• Andreas Luleich for countless compiler improvements
• Hannes Hernler for paying the web server bill
• Mark Ericksen for IDE Demos, several other tools and improvements in lots of areas.
• Matthias Ackermann for bringing TScript, DWS and DWS II 1.0 to life!
• All other contributors (in alphabetical order):
– Brink, Danie (South Africa)
– Darling, Jeremy
– Egorov, Nikita (Russia)
– Fuchs, Manfred (Germany)
– Grange, Eric (France)
– Hariseno, Jagad (Hungary)
– Krenn, Willibald (Austria)
– Lind, Martin (Denmark)
– Listac, John
– Rheinheimer, Danilo Luiz (Brazil)
– Riepp, Michael (Germany)
– Ronzano, Juan Luis (Portugal)
– Tosik
– van Leijen, Wilbert (Netherlands)
– Waldenburg, Martin (Germany)
– Wilcox, Ken
8
Rel
ease
Can
dida
te2Contents
I. A Quick Introduction to DWS II 13
1. Installation 151.1. Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151.2. Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
1.2.1. Common Runtime Package:dws2Runtime.dpk. . . . . . . . . . . . . 181.2.2. VCL Runtime Package:dws2VCLRuntime.dpk. . . . . . . . . . . . . 191.2.3. CLX Runtime Package:dws2CLXRuntime.dpk. . . . . . . . . . . . . 20
1.3. Installation of the Dws2 Core Components . . . . . . . . . . . . . . . . . . . .20
2. DWS II - the Basics 232.1. SimpleDemo.dpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232.2. Calling Script Functions from Delphi:Call.dpr . . . . . . . . . . . . . . . . . 252.3. DWS II Language - a Subset of Delphi Pascal . . . . . . . . . . . . . . . . . .28
2.3.1. How to Design DWS II Scripts . . . . . . . . . . . . . . . . . . . . . .312.3.2. DWS II Script - Syntax . . . . . . . . . . . . . . . . . . . . . . . . . .31
2.4. Working with Delphi Objects in Scripts:dws2Unit . . . . . . . . . . . . . . . 342.4.1. Constructor and ExternalObject . . . . . . . . . . . . . . . . . . . . .372.4.2. Simple Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .402.4.3. More Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . .41
II. Standard DWS II Library Reference 43
3. DWS II Standard Libraries 453.0.4. How To Manually Install a DWS II Library . . . . . . . . . . . . . . . 45
3.1. COM - Connector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .463.2. Internal Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
3.2.1. Maths Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .473.2.1.1. Math Trigonometric Utilities - DWS II Reference . . . . . .493.2.1.2. Math Float Utilities - DWS II Reference . . . . . . . . . . .513.2.1.3. Math Random Utilities - DWS II Reference . . . . . . . . .533.2.1.4. Math Misc. Utilities - DWS II Reference . . . . . . . . . . .54
3.2.2. String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
9
Rel
ease
Can
dida
te2
Contents
3.2.2.1. String Utilities - DWS II Reference . . . . . . . . . . . . . .573.2.3. Time Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62
3.2.3.1. Time Utilities - DWS II Reference . . . . . . . . . . . . . .633.2.4. Variant Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
3.2.4.1. Variant Utilities - DWS II Reference . . . . . . . . . . . . .693.2.5. FileFunctions (Component) . . . . . . . . . . . . . . . . . . . . . . .71
3.2.5.1. File Utilities - DWS II Reference . . . . . . . . . . . . . . .733.2.6. GUI Functions (Component) . . . . . . . . . . . . . . . . . . . . . . .76
3.2.6.1. GUI Utilities - DWS II Reference . . . . . . . . . . . . . . . 773.2.7. Global Variable Functions (Component) . . . . . . . . . . . . . . . . .79
3.2.7.1. GVar Utilities - DWS II Reference . . . . . . . . . . . . . .813.3. Strings Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .823.4. Classes Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .833.5. Database Libraries (IBX, IBO) . . . . . . . . . . . . . . . . . . . . . . . . . .87
3.5.1. dws2IBXDataBase, dws2IBODataBase . . . . . . . . . . . . . . . . .873.5.2. dws2IBXDataSrc, dws2IBODataSrc . . . . . . . . . . . . . . . . . . .873.5.3. dws2IBXLib, dws2IBOLib . . . . . . . . . . . . . . . . . . . . . . . . 87
3.6. Fiber Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .923.7. Ini Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933.8. MF Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.8.1. dws2MFLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .953.8.2. Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
3.8.2.1. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .953.8.3. Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
3.8.3.1. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .953.8.4. Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
3.8.4.1. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .953.8.5. File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.8.5.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .963.8.5.2. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .96
3.8.6. Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973.8.6.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .973.8.6.2. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .98
3.8.7. Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .993.8.7.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .993.8.7.2. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .99
3.8.8. Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1003.8.8.1. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .100
3.8.9. String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1003.8.9.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .1003.8.9.2. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .100
3.8.10. System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1013.8.10.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .1013.8.10.2. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .104
10
Rel
ease
Can
dida
te2
Contents
3.8.11. Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1053.8.11.1. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .105
3.8.12. dws2MFZipLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1063.8.12.1. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . .1063.8.12.2. Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
3.9. Symbols Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1093.10. Web Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
3.10.1. dws2PageProducer . . . . . . . . . . . . . . . . . . . . . . . . . . . .1113.10.2. dws2PageLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1113.10.3. dws2SessionLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1113.10.4. dws2WebLib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
4. Non DWS II Standard Libraries 1174.1. ADO Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1174.2. DB Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1174.3. SMTP Library (D5, D6 only) . . . . . . . . . . . . . . . . . . . . . . . . . . .117
III. Advanced Topics 119
5. DWS II Tools 121
6. Creating Web Applications Using DWS II 2.0 1236.1. Installation of the ISAPI Demo . . . . . . . . . . . . . . . . . . . . . . . . . .123
6.1.1. Using IIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1236.1.2. Using Apache 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123
6.2. Other demos.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
7. How-To 1257.1. Working with Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
7.1.1. In Delphi, Get the Reference to a Delphi Object that is Wrapped by aScript Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
7.2. Working with DWS2Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1257.2.1. In DWS, Use Functions/Procedures/Objects Defined in other Dws2Units125
7.3. Working with Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1257.3.1. In DWS, Emulate Dynamic Arrays . . . . . . . . . . . . . . . . . . . .1257.3.2. In Delphi, Detect if a Variable is Used During the Running of the Script126
8. Appendices 127
11
Rel
ease
Can
dida
te2
Contents
12
Rel
ease
Can
dida
te2
Part I.
A Quick Introduction to DWS II
13
Rel
ease
Can
dida
te2
Rel
ease
Can
dida
te21. Installation
This chapter shows how to set up your development environment and will discuss the modulesDWS II is broken into. Note that the information presented here is subject to change in futurereleases. It is therefore a good practice, to read the “Readme” file that comes with every DWSdistribution package.
This chapter won’t cover the automatic installer that might have shipped with DWS II. Insteadit’ll explain the modules we have in our CVS repository and how to install these modules byhand.
Some of the modules are not included in the DWS II distribution package because of theirunfinished state.
1.1. Directory Structure
Figure 1.1.:DWS root in CVS
Browsing our CVS repository reveals the module listing from above. Although this documentdeals with DWS II only, we’ll briefly go over all non-dws2 modules too.
The“SampleWebApps”, “connectors”, “dws3” and“tools” modules are deprecated - respec-tively currently not actively maintained.SampleWebAppswas meant to hold a few sample webapplications that were developed using DWS. Unfortunately this goal was never reached. The
15
Rel
ease
Can
dida
te2
1. Installation
connectorsmodule is a reminiscent of some feature we had envisioned for DWS. Today theCOM connector - which is the one and only connector that got implemented - resides in thedws2/Sourcedirectory. In thedws1module you can find the first version of DWS that lackedOOP, but had support for function overloading implemented. This module is not actively main-tained anymore, as is thedws16module, that contains the 1.6 release of DWS. (This release waschecked in to a separate module to ease checkout for developers who are not familiar with CVStags or branches.)
DWS3holds a DWS version that should have become the next release after DWS II 1.0. It’sbased on the DWS II 1.0 source code but was enhanced to allow concurrent execution of the sameTProgram object. To put it differently, DWS3 is thread safe. Please keep in mind that DWS3 isnot production quality and more or less experimental. The DWS3 module also contained somepreliminary version of the “PackageConnector”1. Currently there is no development going on inthe DWS3 module. Finally, thetoolsandwrappermodules contain some deprecated code.
Today, the development takes place in thedws2anddws2toolsmodules. Figure 1.2 on thefacing page shows the directory tree of the checked out dws2 module.
The most important subdirectory in the dws2 module is probably the “Source” directory. Thisdirectory contains the complete Delphi source code for the core DWS II components. If youwant to use DWS II in your applications, you have to include this directory in your Delphi (orKylix) library path! The various Delphi<version> and Kylix<version> subdirectories containthe runtime and design-time packages for DWS II.
Obviously a good starting point to explore the power of DWS II is the “Demos” subdirectory.Please note that you’ll need to have synedit (a recent snapshot!) installed if you want to try themall out. Later on we’ll examine the demos anyway, as they show how to use DWS.
Thereafter we’ll briefly explore the supplied libraries and finally we’ll cover the dws2toolsmodule. You can see the directory structure of the dws2tools module on page 22.
1.2. Packages
DelphiWebScript II is separated into several runtime and design-time packages. This is not onlydemanded by Borland, but also necessary for developers who want to ship their projects splitinto runtime packages2.
Basically DWS II is separated into:
1For the interested reader: Due to some difficulties with the DWS3 type system and the lack of interest in theDWS3 module itself, the PackageConnector was finally canned. The over-all idea behind the package connectorwas to be able to use native Delphi classes in any DWS scriptwithout the need to create wrapper code. Thiswas achieved by letting the Delphi compiler do the wrapping - in other words: Let Delphi compile the code intoruntime packages and call the methods found in the resulting runtime package.
The implementation got never beyond some proof of concept code. If you want to see some examples thatalready worked you might visithttp://www.countsandbarons.com/spass/SpassFrames.htm
2We strongly suggest that readers who are not familiar with the package concept of Delphi should consult theirfavourite Delphi book and read up on that topic.If anyone is interested in the name mangling schema of the Delphi/Kylix compilers (versions 5 & 6 - Delphi7 adds something new if the mangled string is longer than 255 chars):http://www.countsandbarons.com/spass/art/packages_en.htm
16
Rel
ease
Can
dida
te2
1.2. Packages
Figure 1.2.:”dws2” module, directory layout17
Rel
ease
Can
dida
te2
1. Installation
• One design-time package, that is only needed by developers working with DWS II in theDelphi IDE,
• one general runtime package, that contains all non-GUI DWS II classes (all the coreclasses fall in this category),
• one VCL runtime package, that depends on the general runtime package and providesfunctions that rely on the VCL
• and last but not least one CLX runtime package, that depends on the general runtimepackage and provides the same functionality found in the VCL runtime package.
Depending on the Delphi version you have, you can not compile all runtime packages men-tioned above. Delphi 5 (and all versions below) does not know anything about the CLX, so it’ssenseless trying to compile the CLX runtime. Kylix on the other hand does not ship with theVisualComponentLibrary, so you can’t compile the VCL runtime.
NO
TE Note, that the Delphi Personal editions do not ship with CLX and might
not even ship with all VCL classes, so there could be trouble compilingthe VCL runtime.
Most of the libraries that ship with DWS II are not Linux compatible and do not have thedesign-time/runtime separation. That’s because they only register one component in the DelphiIDE and do not depend on any Delphi IDE runtime package for IDE integration.
1.2.1. Common Runtime Package: dws2Runtime.dpk
Starting with thedws2Runtimepackage, we want to cover the contents of the packages andmention some versioning problems that might arise when using runtime packages.
Until Delphi 5 runtime packages had to be named along the pattern: <my-Product>50.dpk forDelphi 5, <my-Product>40.dpk for Delphi 4 and so on. This was necessary so that versions ofthe same runtime package compiled with different versions of Delphi could reside on the samecomputer.
Borland decided to “improve” upon this situation and from Kylix 1 / Delphi 6 on developersshould use the LIBSUFFIX option to indicate the Delphi version a package was compiled with.
18
Rel
ease
Can
dida
te2
1.2. Packages
CO
NV
EN
TIO
NThe DWS community uses following convention for the LIBSUFFIX op-tion:
• Delphi 6: 60
• Delphi X: X0
• Kylix X: X0
Beginning with DWS II 2.0 we’ll also set the LIBVERSION option:
• DWS II 2.0: 20
• DWS II X.Y: XY
The Delphi 5 packages, which have no support for the options mentionedabove, will be named likedws2Runtime50_<DWSIIVersion>.dpk(e.g.dws2Runtime50_20.dpk).
Following components are located in the common runtime package:
1. TDelphiWebScriptII
2. Tdws2HtmlFilter
3. Tdws2SimpleDebugger
4. Tdws2FileFunctions
5. Tdws2GlobalVarsFunctions
6. Tdws2StringResultType
7. Tdws2Unit
8. Tdws2HTMLUnit,
9. Tdws2StringsUnit
1.2.2. VCL Runtime Package: dws2VCLRuntime.dpk
As already mentioned, all VCL dependant classes are located in the VCL runtime package. Thispackage provides following components:
1. dws2ComConnector
2. dws2VclGuiFunctions
19
Rel
ease
Can
dida
te2
1. Installation
HIN
T You can only use these components when developing a VCL based appli-cation! Delphi will automatically hide all dws2 VCL based componentsif the currently active project is CLX based.
1.2.3. CLX Runtime Package: dws2CLXRuntime.dpk
The CLX runtime package is mostly considered for cross-platform development. Therefore noDWS II COM support was included in this package.
Currently, the only component that is contained in dws2CLXRuntime is the “dws2ClxGuiFunctions”component, that can be considered as a 1:1 copy of the VCL GUI functions component. Ofcourse dws2ClxGuiFunctions bind to CLX instead of the VCL.
AT
TE
NT
ION
It is not possible to use the COM connector in CLX based projects.
1.3. Installation of the Dws2 Core Components
Installation of DWS II by hand is pretty straight forward. First, locate the Delphi subdirec-tory matching your Delphi version in the dws2 directory. Load the dws2Runtime package andcompile it. Next load the other runtime packages (VCL,CLX) and compile again.
Now you are ready to install the design-time package: Load the dcldws2.dpk package andinstall.
20
Rel
ease
Can
dida
te2
1.3. Installation of the Dws2 Core Components
HIN
TDo not forget to include the dws2/Source directory in your library path,so that Delphi can find all dws2 source files.If you are using Linux, you might want to modify yourLD_LIBRARY_PATH variable to point to the directory where allbpl*.so.* files were put by the Delphi compiler.If it might happen, that you have to convert Delphi 5 projects that areusing DWS to Delphi 6 (or 7), you should modify the Delphi.upg filefound in your Delphi 6 (Delphi 7) “bin” directory and append followinglines:
dws2Runtime50_<Version>=dws2Runtimedws2VCLRuntime50_<Version>=dws2VCLRuntimedws2CLXRuntime50_<Version>=dws2CLXRuntime
dcldws250=dcldws2
Your component palette should now have a tab labeled “DWS2”. By selecting this tab, youshould see all components from figure 1.4 on the following page.
CO
NV
EN
TIO
N
The component’s background color indicates the type of the component:
• Yellow meansinternal functions(usually fast)
• Blue stands fordebugger
• Orange meansfilter
• Gray indicatesresult typesandTDelphiWebScriptII
• Pink stands fordws2units
Congratulations: By now you should have a working DWS2 installation running. Using thisas a basis, we’ll introduce different DWS II libraries and tools in the next few chapters. Butbefore doing so, we’ll examine the basic DWS II capabilities by looking at a few examples thatrun without additional libraries.
21
Rel
ease
Can
dida
te2
1. Installation
Figure 1.3.:”dws2tools” module - directory tree
Figure 1.4.:dws2 core (above: VCL; below: CLX)
22
Rel
ease
Can
dida
te22. DWS II - the Basics
We’ve decided to cover a few easy examples that ship with DWS right here, so that you get anidea of what can be done with DWS.
2.1. SimpleDemo.dpr
In the “dws2/Demos/Simple” directory you’ll find the SimpleDemo that demonstrates the mini-mum requirements DWS II needs in oder to compile and run scripts.
If you open the Delphi project, you’ll see a main form that has two memos, one buttonand a TDelphiWebScript2 component dropped onto it. If you press F9 and then the “Com-pile&Execute” button, you’ll get the output seen in figure 2.1.
By looking at the event handler source code of the TButton you’ll see the minimum code thatis needed for embedding the DWS II component.
Listing 2.1:SimpleDemo EventHandler code
2 usesdws2Exprs , dws2Compi ler ;
4
procedure TFSimpleDemo . BNCompi leAndExecuteCl ick ( Sender :TObject ) ;
6 varx : I n t e g e r ;
8 Prog : TProgram ;begin
10 / / Compi le t h e s c r i p t programProg : = D e lp h iW e bS c r i p t I I 1 . Compile ( MSource . Text ) ;
12 / / D i sp lay e r r o r messages ( i f any )i f Prog . Msgs . HasComp i le rE r ro rsthen
14 f o r x : = 0 to Prog . Msgs . Count− 1 doShowMessage ( Prog . Msgs [ x ] . As In fo ) ;
16 / / Execu te t h e s c r i p t programProg . Execute ;
18 / / D i sp lay t h e o u t p u tMResult . Text : = Tdws2De fau l tResu l t ( Prog . R e s u l t ) . Text ;
20
/ / D i sp lay e r r o r messages ( i f any )22 f o r x : = 0 to Prog . Msgs . Count− 1 do
ShowMessage ( Prog . Msgs [ x ] . As In fo ) ;
23
Rel
ease
Can
dida
te2
2. DWS II - the Basics
Figure 2.1.:SimpleDemo Output
24
Rel
ease
Can
dida
te2
2.2. Calling Script Functions from Delphi: Call.dpr
24 end ;
Several things in this example are worth to mention: If you look at the implementation’s usesclause, you’ll notice that two units (dws2Exprsanddws2Compiler) were included by hand. Weneed to includedws2Exprsbecause it defines the TProgram class the DWS II compiler returns.Dws2Compileris necessary because of theTdws2DefaultResultcast.
Also note the pattern we used to compile and execute the script! First we compile, then wecheck for errors and only if everything worked out OK we call the execute method of the script.Please keep in mind that a script could cause different runtime errors! So we check for them too.
HIN
T
This example does not use any kind offilter, nor a customresult type.If no custom result type is applied to the DWS II component,TPro-gram.Resultalways gives back aTdws2DefaultResultobject!You can apply a custom DWS II result type by dropping e.g. thedws2StringResultTypecomponent onto the form that already containsa TDelphiWebScriptIIcomponent. Do not forget to set the Configura-tion.ResultType property of the TDelphiWebScriptII component to thenewly added result type component!
If you drop a filter component onto a formdws2Compilerautomaticallygets added to the uses clause, so you only have to add thedws2Exprsunit. To enable the filter, you have to set the Configuration.Filter propertyof the TDelphiWebScriptII component to the newly added filter.
A filter / result type can only be assigned to one TDelphiWebScriptII com-ponent at a time!
2.2. Calling Script Functions from Delphi: Call.dpr
We’ve now seen how to compile and execute a complete DWS script. Often, however, we onlywant to call a function in the script and do not want to execute the whole script. Indeed, it couldbe that the script does not have a ”main” program but only functions and procedures defined!
DWS offers you the flexibility you need: It’s no problem calling a script function from Delphicode. To see how this works, load the “Call” demo that ships with DWS II 2.0. Figure 2.2 onthe next page shows the design-time view of the demo’s main form.
It’s easy to see that the script on the right side of the form lacks a main program. It consistsonly of four functions/procedures and a type declaration.
The reason we need theGUI component here is the call to ShowMessage in procedureTest1.Without dropping the GUI component onto the form, DWS II would not be able to compile the
25
Rel
ease
Can
dida
te2
2. DWS II - the Basics
Figure 2.2.:Call Demo - Design-time
26
Rel
ease
Can
dida
te2
2.2. Calling Script Functions from Delphi: Call.dpr
script! For a complete list of functions defined by the GUI component please refer to to chapter3.
So, what’s necessary to call a script procedure?
Listing 2.2:CallDemo: calling Test1
2 procedure TForm1 . B u t t o n 1 C l i c k ( Sender : TObject ) ;var
4 prog : TProgram ;begin
6 prog : = D e l p h i W e b S c r i p t I I . Compile (Memo1 . Text ) ;prog . BeginProgram ;
8 prog . I n f o . Func [’Test1’ ] . C a l l ( [ E d i t 1 . Text ] ) ;prog . EndProgram ;
10 prog .Free ;end ;
As you can see, it’s pretty easy to invoke a script procedure!First, the script is compiled into a TProgram. As a next step theBeginProgramfunction is
called.It’s utterly important that you call this methodbeforetrying to invoke a script function! You alsohave to callEndProgrambefore destroying the TProgram object.
NO
TE
Please keep in mind that the source found in listing 2.2 is nowhere nearproduction quality! There are several points that “smell”:
• No try-finally around the creation of the TProgram object and thecall to free
• No check for DWS II compile time errors
Before going into details about the invocation call itself, let’s look at the Delphi source codenecessary to call theTest4script function:
Listing 2.3:CallDemo: calling Test4
2 procedure TForm1 . B u t t o n 4 C l i c k ( Sender : TObject ) ;var
4 prog : TProgram ;f u n c I n f , r e s u l t I n f : I I n f o ;
6 begin
27
Rel
ease
Can
dida
te2
2. DWS II - the Basics
prog : = D e l p h i W e b S c r i p t I I . Compile (Memo1 . Text ) ;8 prog . BeginProgram ;
f u n c I n f : = prog . I n f o . Func [’Test4’ ] ;10 f u n c I n f . Pa rame te r [’Struct’ ] . Member [’a’ ] . E lement ( [ 0 ] ) .
Value : = S p i n E d i t 1 . Value ;f u n c I n f . Pa rame te r [’Struct’ ] . Member [’a’ ] . E lement ( [ 1 ] ) .
Value : = S p i n E d i t 2 . Value ;12 f u n c I n f . Pa rame te r [’Struct’ ] . Member [’b’ ] . Value : =
S p i n E d i t 3 . Value ;r e s u l t I n f : = f u n c I n f . C a l l ;
14 S p i n E d i t 4 . Value : = r e s u l t I n f . Member [’a’ ] . E lement ( [ 0 ] ) .Value ;
S p i n E d i t 5 . Value : = r e s u l t I n f . Member [’a’ ] . E lement ( [ 1 ] ) .Value ;
16 S p i n E d i t 6 . Value : = r e s u l t I n f . Member [’b’ ] . Value ;prog . EndProgram ;
18 prog .Free ;end ;
Clearly, CallingTest4demands more work to be done by the programmer.
HIN
T Just in case you wonder where TStruct was defined, have a look at thescript in figure 2.2 on page 26!
ToDo: Explain IInfohere!
2.3. DWS II Language - a Subset of Delphi Pascal
By now we’ve only covered the Delphi - side of DWS II. This section will give you an idea ofhow the Pascal subset of DWS II looks like.
The syntax of DWS II script is similar to Delphi, making the learning curve not very steep.Perhaps we should start with a list of what isnot supported by DWS II.
28
Rel
ease
Can
dida
te2
2.3. DWS II Language - a Subset of Delphi Pascal
AT
TE
NT
ION
Following Delphi language features are NOT supported by DWS II
• sets
• with clause
• pointer
• interfaces
• function overloading
• goto, label, public, protected, private, published
• other low level Delphi instructions (packed, in/out, cdecl/.., etc..)
• call DLL functions from script directly
• save a compiled DWS II script to a filea
aLots of developers have already demanded such a feature. Therefore we’ll briefly dis-cuss why we willnot implement it.
First, DWS II lets you define custom filters that enables you to encrypt your scripts.Second, DWS II has a very fast compiler. It’s no performance problem to compilescripts instead of loading a binary representation that has to be de-serialized. Third,DWS II very strongly depends on libraries providing functions that can be called.When loading a binary representation of a DWS II script we would have to makesure all libraries are compiled into the application that loads and wants to execute thescript. When compiling the script this is automatically done by the DWS II compiler.Fourth, it would be tremendous work without gaining any significant feature:
If you want something compiled into a binary representation for speed reasons,USEDELPHI!
Perhaps it’s more important to say what actually IS supported (Bold printed Items are notsupported by Delphi):
• Flow-Control:
– If-then-else
– For, While, Repeat-until
∗ Break, Continue
– Case
∗ Supports non-ordinal data types
29
Rel
ease
Can
dida
te2
2. DWS II - the Basics
– Try-except, Try-finally
• Functions, Procedures
– Recursion
– Mutual Recursion
– Complex Return Types
– Default Parameters
• Classes
– Fields
– Methods
∗ Virtual
∗ Static
– Properties
∗ Array Properties
∗ Default Properties
• Exceptions
– native Delphi Exceptions (are mapped to ’EDelphi’)
– DWS script Exceptions
• Data types
– Basic Data types:
∗ String
∗ Integer
∗ Boolean
∗ Float (= Double)
∗ Variant
∗ EveryConnectormay define other basic Data types (e.g.: COM Connectorintroduces COMVariant.)
– Structured Data types:
∗ Records
∗ Arrays, Dynamic Arrays
– Enumerations
30
Rel
ease
Can
dida
te2
2.3. DWS II Language - a Subset of Delphi Pascal
• Compiler
– Constant Folding (and/or other custom optimizations)
– All Variables are initialized
– Supports declarations anywhere in script
• ....
2.3.1. How to Design DWS II Scripts
In order to get the maximum DWS performance, you should know how to design your scripts.We find it very important that you stick to the design rules given in this document.
1. Scripts should be:
a) As short as possible
b) Must not contain calculation intense algorithms
c) Do not excessively use loops - especially with lots of iterations
2. “Outsource” as many functions as possible to Delphi and call them. (Use the dws2Unitcomponent!)
3. If possible, cache your compiled TPrograms - do not compile every time again.
HIN
T
DWS II has an option for optimization when compiling the script. Themain work done by the optimizer is constant folding. Note, however, thatonly internal functions can take advantage of this by default. All otherfunctions have to support this explicitly.Internal functions are so to speak built into the TDelphiWebScriptII com-ponent. So most internal functions are always available.You can find a list of all internal functions in section 3.2 on page 46.
2.3.2. DWS II Script - Syntax
The main difference of the syntax used by DWS II and Delphi is that DWS II allows you todefine types/variables almost everywhere in script. This ability is necessary for working withHTML files, as there is no such structure present that we find in Delphi units or programs.
31
Rel
ease
Can
dida
te2
2. DWS II - the Basics
This has one important implication, namely DWS II does not like to have types defined whereyou would define them in Delphi: After the function / procedure header but before the ’begin’keyword of the function’s / procedure’s implementation part. See listing 2.4 for an example.
HIN
T All listings within a shadowbox are considered to be DWS II scripts. Allother listings contain Delphi code.
Listing 2.4:DWSIISyntax: Differences to Delphi
2 procedure t e s t ;/ / f o r c o m p a t i b i l i t y reasons you can d e c l a r e
4 / / v a r i a b l e s herevar x : v a r i a n t ;
6
procedure y ; / / d e c l a r e n e s t e d procedure− ERROR8 begin
/ / DWSII does no t a l l ow you t o d e f i n e10 / / a n e s t e d procedure here ! !
end ;12
begin14 procedure z ; / / ok
var16 a : f l o a t ;
b : i n t e g e r ;18 begin
/ / normal DWSII s y n t a x : d e c l a r e e v e r y t h i n g20 / / you need w i t h i n beg in / end p a i r s
var c : boo lean ;22 end ;
end ;
It is highly recommended that you load theBasicsdemo and experiment with the availableDemos yourself! For convenience we’ll reprint here theNestedDeclarationsexample. It demon-strates the lifetime of a declaration.
32
Rel
ease
Can
dida
te2
2.3. DWS II Language - a Subset of Delphi Pascal
HIN
TYou might have noticed by now that there is no explicit ’main’ programin DWS II scripts. This observation is partly correct. Ideally you shouldthink that the whole script you write is encapsulated between abegin -endpair! As a consequence the whole scriptis the “main” program.
Another important twist comes in here: When defining variables or typeswithin a begin - end pair, you have to begin the declaration every timewith the appropriate keyword! So the following script is not valid andwill produce a compile time error.
//[...]beginvarx: integer;y: bool; // error!end;//[...]
Below you’ll find the source of the “NestedDeclarations” example. Please note howx andsare defined the first time: Every declaration starts with thevar keyword. (Following declarationwould also have been valid: “var x, s: Integer;”.)
Listing 2.5:DWSIISyntax: Nested Declaration
2 {S p e c i a l DWSII Syn tax :
4 I t ’ s p o s s i b l e t o d e c l a r e v a r i a b l e s everywhere i nt h e s c r i p t code . The d e c l a r a t i o n i s v a l i d i n s i d e t h e
6 a c t i v e b l o c k ( a f t e r t h e d e c l a r a t i o n ) and i t s sub−b l o c k s .}
8 var x : I n t e g e r ;var s : I n t e g e r ; / / you need t h e ’ var ’ he re ! !
10 f o r x : = 0 to 1 0 dobegin
12 var s : s t r i n g ; / / o v e r r i d e s p r e v i o u s d e c l a r a t i o n/ / o f " s " ( on l y i n s i d e t h i s loop )
14 / / s now a STRINGs : = In tToStr ( x ) ;
16 P r i n t L n ( s ) ;end ;
18 f o r x : = 0 to 1 0 dobegin
20 var s : F l o a t ; / / o v e r r i d e s p r e v i o u s d e c l a r a t i o n/ / o f " s " ( on l y i n s i d e t h i s loop )
33
Rel
ease
Can
dida
te2
2. DWS II - the Basics
22 / / s now a FLOAT!s : = Sqrt ( x ) ;
24 P r i n t L n ( s ) ;end ;
26 f o r x : = 0 to 1 0 dobegin
28 s : = Round( Sqr ( x ) ) ; / / No r e d e c l a r a t i o n o f " s " so/ / t h e i n i t i a l d e c l a r a t i o n i s used
30 P r i n t L n ( s ) ;end ;
We recommend that you look through all examples theBasicdemo provides.
2.4. Working with Delphi Objects in Scripts: dws2Unit
As a last introducery topic, we’ll briefly cover the mechanisms DWS II uses to work with Delphiobjects. We’ll discuss the examples found in theBasicdemo here.
Thedws2Unitcomponent is a cornerstone in DWS II: It’s the link between native, compiledDelphi code and DWS II scripts. As a consequence it’s therefore important to know how to workwith this component.
NO
TE
Although dws2Unitmade it somewhat easier to create “wrapper code”for DWS II, it’s still a bit cumbersome to work with it. In future,however, there will be some improvement to this situation as there isa dws2UnitEditor in development. (You can find the sources in thedws2tools module).
Figure 2.3 on the facing page shows all types and functions that are defined in the dws2Unitcomponent of the Basic demo.
Modifying the state of a native Delphi object in DWS II script is a very common task. Unlike.NET and Java, Delphi does not offer reflection over all types. As you might know, only pub-lished parts of a class declaration offer meta-data in Delphi. DWS II therefore needs your help tofigure out what methods, fields and properties a Delphi class/object exposes.1 In the followingchapters we’ll refer to this process of providing the information aswriting wrapper code.
If you open theUsing Delphi in DWS -> Dws2AccessInDelphi.dwsscript in the Basic demo,you should see following source:
1Delphi runtime packages offer far more information about the members they contain. Unfortunately it’s not possi-ble to determine the return type of a method/function found in a runtime package. Therefore even if it would bepossible to call functions in runtime packages, one would have to provide the complete interface declaration ofthe functions one wants to call.
34
Rel
ease
Can
dida
te2
2.4. Working with Delphi Objects in Scripts: dws2Unit
Figure 2.3.:Object TreeView of the dws2Unit component found in Basic demo
35
Rel
ease
Can
dida
te2
2. DWS II - the Basics
Listing 2.6:Working with Delphi objects in DWSII: TWindow
2 {Demons t ra tes how t o c a l l methods from n a t i v e
4 Delph i code and how t o a c c e s s t h e d a t a s t r u c t u r e so f DWS.
6 Have a look a t t h e De lph i sou rce code o ft h e DWSII c l a s s " TWindow " !
8 }var w : TWindow ;
10 var i , j , k : i n t e g e r ;
12 w : = TWindow . C r e a t e ( 1 0 , 1 0 ,’Hello World’ ) ;
14 f o r i : = 1 0 to 1 0 0 dobegin
16 Pause ( 1 0 ) ; / / S l e e pw. S e t P o s i t i o n ( i , i ) ;
18 RedrawDwsDemo ;end ;
20
22 var p : TWindowParams ;type t e s t = array [ 1 . . 2 ] of record a , b : i n t e g e r end ;
24 var t : Tes t ;p . L e f t : = 2 0 0 ;
26 p . Top : = 2 0 0 ;p . Width : = 3 0 0 ;
28
p . He igh t : = 5 0 ;30 p . Cap t ion : = ’’ ;
w. SetParams ( p ) ;32 w. UseVarParamTest ;
var v : TWindow ;34 v : = TWindow (w. NewInstance ) ;
36 Pause (3000 ) ;
If you compile and run the demo, you should see three windows created: At first a littlewindow that moves from top left 100 steps to bottom right. This is done by thefor loop startingat line 14. If the loop has completed, the script will create two windows and assign differentcaptions and positions to them.
36
Rel
ease
Can
dida
te2
2.4. Working with Delphi Objects in Scripts: dws2Unit
AT
TE
NT
ION
If you look at the script, you’ll notice that there is no call to a destructorof any of the objects created. If you look at figure 2.4 on the next page,you’ll see that the TWindow classdoeshave a destructor defined.So what’s going on here?The answer is pretty simple: DWS II 2.x featuresGarbage Collection!
You do not need to call any destructor in a DWS II script!
HIN
T
It’s important to realize that a type that can be used in a DWS II script isNOT the native type defined by Delphi - even if the DWS II type has thesame name as the Delphi type and tries to provide the same interface asthe Delphi type.
Everything that you can use in a DWS II script is some wrapper aroundsome native code.
The COM connector might be - partly - an exception to this rule.
To fully understand the script from listing 2.6, we must have a look at the definitions andthe wrapper code provided by the dws2Unit component for TWindow. See figure 2.4 on thefollowing page for the ’interface’ definition of the TWindow class.
2.4.1. Constructor and ExternalObject
Let’s start dissecting the example and begin with line 12, where the TWindow constructor getscalled the first time.
Figure 2.5 on page 39 shows a screen shot of the Object Inspector’s settings for TWindow’sconstructor. Most notably is theOnAssignExternalObjectevent. Listing 2.7 shows the codebehind that event.
Listing 2.7:Working with Delphi objects in DWSII: TWindow Constructor
2 procedure TFDwsDemo .dws2Un i tC lassesTWindowCons t ruc to rsCrea te
A s s i g n E x t e r n a l O b j e c t ( I n f o : TProgramInfo ;var Ex tOb jec t :TObject ) ;
4 beginEx tOb jec t : = TFTest . C r e a t e (n i l ) ;
37
Rel
ease
Can
dida
te2
2. DWS II - the Basics
Figure 2.4.:Object TreeView of the TWindow class defined by dws2Unit
38
Rel
ease
Can
dida
te2
2.4. Working with Delphi Objects in Scripts: dws2Unit
Figure 2.5.:Object Inspector: TWindow Constructor
39
Rel
ease
Can
dida
te2
2. DWS II - the Basics
6 TFTest ( Ex tOb jec t ) . Show ;end ;
As you can see, theExtObjectparameter is declared using thevar directive. This indicatesthatExtObjectcan already have a value assigned when enteringOnAssignExternalObject! (Oth-erwise we would have used theout directive.)
There is only one case where this can happen: If you call a constructor viaInfo.Vars[’TMyClass’].-GetConstructor(’Create’, delphiObject).Call.Value, OnAssignExternalObject gets called withExtObjectassigned todelphiObject.
The most important part of this listing is found in line 5. In this line aDelphi object getscreated and assigned to the ExtObject variable.
AT
TE
NT
ION
It’s important that you understand what function theExtObjectfulfills!Remember: We are writingwrapper codehere. In other words, we haveto create the glue that is necessary for manipulating native Delphi objects.The ExtObject hereby holds a reference to the native Delphi object wewant to control within the DWS II script. You have to create it in thecode that implements theOnAssignExternalObjectevent and you have todestroy it later in a destructor. (The destructor gets automatically calledby DWS II)Any method you define and implement later for your DWS II class willget exactly the same ExtObject you created here passed in as functionparameter!
HIN
T
The dws2Unit component offers a feature calledInstancesthat is usefulfor wrapping variables / properties if they contain / return an object. TheUsing Delphi in DWS -> Tdws2UnitVariablesAutoinstantiate.dwsscriptshows how to use that feature.Basically it allows you to assign the ExtObject on the first read operationof the“instance unit variable”.
2.4.2. Simple Method
The first real method call in listing 2.6 can be found in line 17.
Listing 2.8:Working with Delphi objects in DWSII: TWindow SetPosition
40
Rel
ease
Can
dida
te2
2.4. Working with Delphi Objects in Scripts: dws2Unit
2 procedure TFDwsDemo .dws2Un i tC lassesTWindowMethodsSetPos i t ionEva l ( I n f o :TProgramInfo ; Ex tOb jec t : TObject ) ;
begin4 I n f o . Vars [’Self’ ] . Member [’Left’ ] . Value : = I n f o [’Left’ ] ;
I n f o . Vars [’Self’ ] . Member [’Top’ ] . Value : = I n f o [’Top’ ] ;6 I n f o . Func [’Update’ ] . C a l l ;
end ;
As you can see in figure 2.4 on page 38, this method has two parameters:Left andTop. TheTWindow class itself also has two members (fields) namedLeft andTop.
The code in listing 2.8 does nothing else, than assign the values of the method’s parametersto the internal fields. (Lines 4 and 5.)
Line 6 should look somewhat familiar, if you’ve already read section 2.2 on page 25. To putit in a nutshell: TheUpdatemethod of TWindow gets called. Why not “Info.
Vars[’Self’].Func[’Update’]..”?! -ASK-
Updateis very interesting to us, because it’s there, where the linking between DWS II ScriptClass and native Delphi class happens:
Listing 2.9:Working with Delphi objects in DWSII: TWindow Update
2 procedure TFDwsDemo . dws2Uni tClassesTWindowMethodsUpdateEval( I n f o : TProgramInfo ; Ex tOb jec t : TObjec t ) ;
begin4 TFTest ( Ex tOb jec t ) . L e f t : = I n f o [’Left’ ] ;
TFTest ( Ex tOb jec t ) . Top : = I n f o [’Top’ ] ;6 TFTest ( Ex tOb jec t ) . Width : = I n f o [’Width’ ] ;
TFTest ( Ex tOb jec t ) . He igh t : = I n f o [’Height’ ] ;8 end ;
2.4.3. More Advanced Techniques
Another common situation is that your script functions get a script object (say a TSomeScrip-tObj) as parameter. In theOnEvalevent, however, you need to modify the underlying nativeDelphi object.
So how do you get the native Delphi Object? Listing 2.10 shows you how to do that.
Listing 2.10:Advanced Techniques: Get ScriptObject in OnEval
{ D e c l a r a t i o n o f t h e s c r i p t p rocedure : p rocedure ( SomeObject: TSomeScr ip tOb j )
41
Rel
ease
Can
dida
te2
2. DWS II - the Basics
2 Note : TSomeScr ip tOb j i s a s c r i p t c l a s s t h a t has aTSomeObject De lph i o b j e c t a s s i g n e d . . I t ’ s a wrapperaround TSomeObject i n o t h e r words . }
var4 S c r i p t O b j : I S c r i p t O b j ;
N a t i v e O b j e c t : TSomeObject ;6 begin
/ / g e t t h e s c r i p t o b j e c t8 S c r i p t O b j : = I S c r i p t O b j ( IUnknown ( I n f o [’SomeObject’ ] ) ) ;
i f S c r i p t O b j = n i l then10 N a t i v e O b j e c t : = n i l
e l s e12 / / g e t t h e n a t i v e Ob jec t
N a t i v e O b j e c t : = TSomeObject ( S c r i p t O b j . E x t e r n a l O b j e c t ) ;14 end
Here is the declaration of the IScriptObj interface that represents a DWS II script object:
Listing 2.11:Advanced Techniques: IScriptObj definition
I S c r i p t O b j = i n t e r f a c e2 [ ’{8D534D1E-4C6B-11D5-8DCB-0000216D9E86}’ ]
f un c t i on GetClassSym : TClassSymbol ;4 f un c t i o n GetData : TData ;
procedure SetDa ta ( Dat : TData ) ;6 f un c t i o n G e t E x t e r n a l O b j e c t : TObject ;
procedure S e t E x t e r n a l O b j e c t ( Value : TObject ) ;8 proper ty ClassSym : TClassSymbolread GetClassSym ;
proper ty Data : TData read GetData wr i te SetDa ta ;10 proper ty E x t e r n a l O b j e c t : TObjectread G e t E x t e r n a l O b j e c t
wr i te S e t E x t e r n a l O b j e c t ;end ;
Other advanced topics:
• If you want to know, how you can call a constructor of a script class and what to return,look at theNewInstancemethod of TWindow.
• There are plenty of other examples available in the basic demo - so have a look at them!
42
Rel
ease
Can
dida
te2
Part II.
Standard DWS II Library Reference
43
Rel
ease
Can
dida
te2
Rel
ease
Can
dida
te23. DWS II Standard Libraries
The main part of Applied DWS II Programming is the documentation of the libraries that shipwith DWS II. Consider the information found here as “standard”.
Figure 3.1 shows a screen shot of the DWS2 tab of the Delphi component palette with theDWS II Common Libraries installed.
CO
NV
EN
TIO
N
If you want to implement a library for DWS, please search this chapterfor libraries already providing a similar service and consider the API theyprovide asmust implement.(Note: Before raising some sort of “ENotIm-plemented” exceptions in your library, skip the method alltogether - evenif this method is demanded by the standard.)For example: If you want to implement a new database connectivity li-brary for - say - SAP DB, then look at the DB libraries found here. Theydefine the minimum subset of functions and methods your library has toprovide in oder to beDWS II Standard Library Compliant!Note, that only compliant libraries will be included in the main DWS IIrelease package in future.
3.0.4. How To Manually Install a DWS II Library
Installing a DWS II Library by hand is fairly easy. Just select File->Open Project (*.dpk as filetype) in the Delphi main menu. Delphi now shows an open file dialog box. Browse to yourDWS II installation directory and double click on the “Libraries” subdirectory. The open filedialog now shows you the contents of thedws2\Librariesdirectory. Search for a subdirectoryaccording to your Delphi version:Delphi6when you are using Delphi version 6,Kylix3 if youare running Kylix version 3, etc.
Open that subdirectory and open any Delphi package of your choice. After you’ve opened thepackage, clickInstall in the Delphi package dialog window to install the selected Library.
Figure 3.1.:DWS II tab with Common Libraries installed
45
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
HIN
T
Do not forget to update your Library-Path settings!
3.1. COM - Connector
Listing 3.1:Connectors: COM
{ COM c o n n e c t o r d e f i n e s two d a t a t y p e s : " ComVariant " and "ComVar iantArray " }
2
cons t ComOpt : V a r i a n t = [ v a r E r r o r ] ;4
{ Func t i on t o c r e a t e a new COM−Ob jec t : C rea tes an COMo b j e c t and r e t u r n s a p o i n t e r t o t h e I D i s p a t c h i n t e r f a c e. See De lph i he lp f o r C rea teO leOb jec t . }
6 f un c t i on C r e a t e O l e O b j e c t ( ClassName :St r i ng ) : ComVariant ;
3.2. Internal Functions
Most of the internal functions are always available in DWS II scripts. Only the GUI, GlobalVarand File functions have to be manually included by dropping the appropriate components ontothe form.
NO
TE
The proceduresprint andprintln are built into the TDelphiWebScriptIIcomponent.
• procedurePrint(Output: String);Adds Output without adding CRLF to TProgram.Result
• procedurePrintLn(Output: String);Adds Output + CRLF to TProgram.Result
Note that you can not use PrintLn if you want to add one - in the webbrowser visible - line feed to a HTML page!
46
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.1. Maths Functions
Listing 3.2:Internal Functions: Maths
2 R e g i s t e r I n t e r n a l F u n c t i o n ( TSinFunc ,’Sin’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TSinhFunc ,’Sinh’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TCosFunc ,’Cos’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCoshFunc ,’Cosh’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
6 R e g i s t e r I n t e r n a l F u n c t i o n ( TTanFunc ,’Tan’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TTanhFunc ,’Tanh’ , [ ’a’ , c F l o a t ] ,c F l o a t ) ;
8 R e g i s t e r I n t e r n a l F u n c t i o n ( TArcSinFunc ,’ArcSin’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TArcSinhFunc ,’ArcSinh’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
10 R e g i s t e r I n t e r n a l F u n c t i o n ( TArcCosFunc ,’ArcCos’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TArcCoshFunc ,’ArcCosh’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
12 R e g i s t e r I n t e r n a l F u n c t i o n ( TArcTanFunc ,’ArcTan’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TArcTanhFunc ,’ArcTanh’ , [ ’v’ ,c F l o a t ] , c F l o a t ) ;
14 R e g i s t e r I n t e r n a l F u n c t i o n ( TCotanFunc ,’Cotan’ , [ ’a’ , c F l o a t] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( THypotFunc ,’Hypot’ , [ ’x’ , cF l oa t, ’y’ , c F l o a t ] , c F l o a t ) ;
16 R e g i s t e r I n t e r n a l F u n c t i o n ( TIncFunc ,’Inc’ , [ ’@a’ , c I n t e g e r ,’b’ , c I n t e g e r ] , c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TAbsFunc ,’Abs’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
18 R e g i s t e r I n t e r n a l F u n c t i o n ( TExpFunc ,’Exp’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TLnFunc ,’Ln’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
20 R e g i s t e r I n t e r n a l F u n c t i o n ( TLog2Func ,’Log2’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TLog10Func ,’Log10’ , [ ’v’ , c F l o a t] , c F l o a t ) ;
22 R e g i s t e r I n t e r n a l F u n c t i o n ( TLogNFunc ,’LogN’ , [ ’n’ , cF l oa t , ’x’ , c F l o a t ] , c F l o a t ) ;
47
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
R e g i s t e r I n t e r n a l F u n c t i o n ( TSqrtFunc ,’Sqrt’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
24 R e g i s t e r I n t e r n a l F u n c t i o n ( TSqrFunc ,’Sqr’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TIntFunc ,’Int’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
26 R e g i s t e r I n t e r n a l F u n c t i o n ( TFracFunc ,’Frac’ , [ ’v’ , c F l o a t ] ,c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TTruncFunc ,’Trunc’ , [ ’v’ , c F l o a t] , c I n t e g e r ) ;
28 R e g i s t e r I n t e r n a l F u n c t i o n ( TRoundFunc ,’Round’ , [ ’v’ , c F l o a t] , c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TPowerFunc ,’Power’ , [ ’base’ ,cF loa t , ’exponent’ , c F l o a t ] , c F l o a t ) ;
30 R e g i s t e r I n t e r n a l F u n c t i o n ( TDegToRadFunc ,’DegToRad’ , [ ’a’ ,c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TRadToDegFunc ,’RadToDeg’ , [ ’a’ ,c F l o a t ] , c F l o a t ) ;
32 R e g i s t e r I n t e r n a l F u n c t i o n ( TMaxFunc ,’Max’ , [ ’v1’ , cF l oa t , ’v2’ , c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TMinFunc ,’Min’ , [ ’v1’ , cF l oa t , ’v2’ , c F l o a t ] , c F l o a t ) ;
34 R e g i s t e r I n t e r n a l F u n c t i o n ( TPiFunc ,’Pi’ , [ ] , c F l o a t ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TRandomFunc ,’Random’ , [ ] , c F l o a t )
;36 R e g i s t e r I n t e r n a l F u n c t i o n ( TRandomIntFunc ,’RandomInt’ , [ ’
range’ , c I n t e g e r ] , c I n t e g e r ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TRandomizeFunc ,’Randomize’ , [ ] , ’
’ ) ;38 R e g i s t e r I n t e r n a l F u n c t i o n ( TRandGFunc ,’RandG’ , [ ’mean’ ,
cF loa t , ’stdDev’ , c F l o a t ] , c F l o a t ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TRandSeedFunc ,’RandSeed’ , [ ] ,
c I n t e g e r ) ;40 R e g i s t e r I n t e r n a l F u n c t i o n ( TSetRandSeedFunc ,’SetRandSeed’ , [
’seed’ , c I n t e g e r ] ,’’ ) ;
48
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.1.1. Math Trigonometric Utilities -DWS II Reference
Sin, Sinh
Returns the (hyperbolic) sine of the angle inradians.
Declaration
function Sin(X: Float): Float;function SinH(X: Float): Float;
Description
The Sin function returns the sine of the ar-gument.
X is a real-type expression. Sin returns thesine of the angle X in radians.
Sinh calculates the hyperbolic sine of X.
Cos, Cosh
Returns the (hyperbolic) cosine of the angle inradians.
Declaration
function Cos(X: Float): Float;function CosH(X: Float): Float;
Description
The cosine function returns the cosine of theargument.
X is a real-type expression. Cos returns thesine of the angle X in radians.
Cosh calculates the hyperbolic cosine of X.
Tan, Tanh
Returns the (hyperbolic) tangent of the angle inradians.
Declaration
function Tan(X: Float): Float;function TanH(X: Float): Float;
Description
The Tan function returns the tangent of theargument. (Tan(x) = Sin(x) / Cos(x))
X is a real-type expression. Tan returns thetangent of the angle X in radians.
Tanh calculates the hyperbolic tangent of X.
ArcSin, ArcSinh
Calculates the inverse (hyperbolic) sine of agiven number.
Declaration
function ArcSin(X: Float): Float;function ArcSinH(X: Float): Float;
Description
ArcSin returns the inverse sine of X. X mustbe between -1 and 1. The return value will bein the range [-Pi/2..Pi/2], in radians.
ArcSinh returns the inverse hyperbolic sineof X.
ArcCos, ArcCosh
Calculates the inverse (hyperbolic) cosine of agiven number.
Declaration
function ArcCos(X: Float): Float;function ArcCosH(X: Float): Float;
49
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
Description
ArcCos returns the inverse cosine of X. Xmust be between -1 and 1. The return valuewill be in the range [0..Pi], in radians.
ArcCosh returns the inverse hyperbolic co-sine of X.
ArcTan, ArcTanh
Calculates the inverse (hyperbolic) tangent ofa given number.
Declaration
function ArcTan(X: Float): Float;function ArcTanH(X: Float): Float;
Description
ArcTan returns the arctangent of X.ArcTanh returns the inverse hyperbolic tan-
gent of X. The value of X must be between -1and 1 (inclusive).
Cotan
Calculates the cotangent of an angle.
Declaration
function CoTan(X: Float): Float;
Description
Call Cotan to obtain the cotangent of X. Thecotangent is calculated using the formula
1 / Tan(X)Do not call Cotan with X = 0!
Pi
Returns 3.1415926535897932385.
Declaration
function Pi: Float;
Description
Use Pi in mathematical calculations that re-quire pi
DegToRad
Returns the value of a degree measurement ex-pressed in radians.
Declaration
function DegToRad(x: Float): Float;
RadToDeg
Converts radians to degrees.
Declaration
function RadToDeg(x:Float): Float;
50
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.1.2. Math Float Utilities - DWS IIReference
Abs
Abs returns the absolute value of the argument,X.
X is a float-type expression
Declaration
function Abs(x: Float): Float;
Exp
Returns the value of a degree measurement ex-pressed in radians.
Declaration
function Exp(x: Float): Float;
Ln
Returns the value of a degree measurement ex-pressed in radians.
Declaration
function Ln(x: Float): Float;
Log2
Log2 returns the log base 2 of X.
Declaration
function Log2(x: Float): Float;
Log10
Log10 returns the log base 10 of X.
Declaration
function Log10(x: Float): Float;
LogN
LogN returns the log base Base of X.
Declaration
function LogN(Base, x: Float): Float;
Sqrt
X is a floating-point expression. The result isthe square root of X.
Declaration
function Sqrt(x: Float): Float;
Sqr
The Sqr function returns the square of the ar-gument.
X is a floating-point expression. The result,of the same type as X, is the square of X, orX*X.
Declaration
function Sqr(x: Float): Float;
Int
Int returns the integer part of X; that is, X roundedtoward zero. X is a real-type expression.
Declaration
function Int(x: Float): Float;
Frac
The Frac function returns the fractional part ofthe argument X.
X is a real-type expression. The result isthe fractional part of X; that is, Frac(X) = X- Int(X).
Declaration
function Frac(x: Float): Float;
51
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
Trunc
The Trunc function truncates a real-type valueto an integer-type value. X is a real-type ex-pression. Trunc returns an Integer value that isthe value of X rounded toward zero.
Declaration
function Trunc(x: Float): Integer;
Round
The Round function rounds a real-type value toan integer-type value.
X is a real-type expression. Round returnsan Integer value that is the value of X roundedto the nearest whole number. If X is exactlyhalfway between two whole numbers, the re-sult is always the even number. This method ofrounding is often called Bankers Rounding.
Note: The behavior of Round can be affectedby the Set8087CW procedure or SetRoundModefunction.
Declaration
function Round(x: Float): Integer;
Power
Power raises Base to any power. For fractionalexponents or exponents greater than MaxInt,Base must be greater than 0.
Declaration
function Power(Base, Exponent: Float): Float;
Max
Call Max to compare two numeric values. Maxreturns the greater value of the two.
Declaration
function Max(v1,v2: Float): Float;
Min
Call Min to compare two numeric values. Minreturns the smaller value of the two.
Declaration
function Min(v1,v2: Float): Float;
52
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.1.3. Math Random Utilities - DWS IIReference
Random
Returns a random number within the range 0 <= X < 1
Declaration
function Random: Float;
RandomInt
Returns a random number within the range 0 <= X < Range; x e IN
Declaration
function RandomInt(Range: Integer): Inte-ger;
Randomize
Randomize initializes the built-in random num-ber generator with a random value (obtainedfrom the system clock). The random numbergenerator should be initialized by making a callto Randomize, or by assigning a value to Rand-Seed.
Do not combine the call to Randomize in aloop with calls to the Random function. Typ-ically, Randomize is called only once, beforeall calls to Random.
Declaration
procedureRandomize;
RandG
RandG produces random numbers with Gaus-sian distribution about the Mean. This is usefulfor simulating data with sampling errors andexpected deviations from the Mean.
Declaration
function RandG(Mean, StdDev: Float): Float;
RandSeed
Get the value of the Delphi-RandSeed variable.
Declaration
function RandSeed: Integer;
SetRandSeed
Set the Delphi RandSeed variable.
Declaration
procedureSetRandSeed(val: Integer);
53
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
3.2.1.4. Math Misc. Utilities - DWS IIReference
Inc
Increments a by b.
Declaration
procedure Inc(a,b: Integer);
Hypot
Calculates the length of the hypotenuse.
Declaration
function Hypot(x, y: Float): Float;
54
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.2. String Functions
Listing 3.3:Internal Functions: String Functions
2 R e g i s t e r I n t e r n a l F u n c t i o n ( T In tToSt rFunc ,’IntToStr’ , [ ’i’ ,c I n t e g e r ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TSt rToIn tFunc ,’StrToInt’ , [ ’str’, c S t r i n g ] , c I n t e g e r ) ;
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TSt rToIn tDefFunc ,’StrToIntDef’ , [’str’ , c S t r i n g , ’def’ , c I n t e g e r ] , c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TIntToHexFunc ,’IntToHex’ , [ ’v’ ,c I n t e g e r , ’digits’ , c I n t e g e r ] , c S t r i n g ) ;
6 R e g i s t e r I n t e r n a l F u n c t i o n ( TF loa tToSt rFunc ,’FloatToStr’ , [ ’f’ , c F l o a t ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TSt rToF loa tFunc ,’StrToFloat’ , [ ’str’ , c S t r i n g ] , c F l o a t ) ;
8 R e g i s t e r I n t e r n a l F u n c t i o n ( TSt rToFloatDefFunc ,’StrToFloatDef’ , [ ’str’ , c S t r i n g , ’def’ , c F l o a t ] , c F l o a t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TChrFunc ,’Chr’ , [ ’x’ , c I n t e g e r ] ,c S t r i n g ) ;
10 R e g i s t e r I n t e r n a l F u n c t i o n ( TOrdFunc ,’Ord’ , [ ’s’ , c S t r i n g ] ,c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCharAtFunc ,’CharAt’ , [ ’s’ ,c S t r i n g , ’x’ , c I n t e g e r ] , c S t r i n g ) ;
12 R e g i s t e r I n t e r n a l F u n c t i o n ( TSetCharAtFunc ,’SetCharAt’ , [ ’@s’, c S t r i n g , ’x’ , c I n t e g e r , ’c’ , c S t r i n g ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TDeleteFunc ,’Delete’ , [ ’@S’ ,c S t r i n g , ’Index’ , c I n t e g e r , ’Len’ , c I n t e g e r ] , ’’ ) ;
14 R e g i s t e r I n t e r n a l F u n c t i o n ( T Inse r tFunc ,’Insert’ , [ ’src’ ,c S t r i n g , ’@S’ , c S t r i n g , ’Index’ , c I n t e g e r ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TLowerCaseFunc ,’LowerCase’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
16 R e g i s t e r I n t e r n a l F u n c t i o n ( TAnsiLowerCaseFunc ,’AnsiLowerCase’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TUpperCaseFunc ,’UpperCase’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
18 R e g i s t e r I n t e r n a l F u n c t i o n ( TAnsiUpperCaseFunc ,’AnsiUpperCase’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TPosFunc ,’Pos’ , [ ’subStr’ ,c S t r i n g , ’str’ , c S t r i n g ] , c I n t e g e r ) ;
20 R e g i s t e r I n t e r n a l F u n c t i o n ( TLengthFunc ,’Length’ , [ ’str’ ,c S t r i n g ] , c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TSetLengthFunc ,’SetLength’ , [ ’@S’, c S t r i n g , ’NewLength’ , c I n t e g e r ] , ’’ ) ;
22 R e g i s t e r I n t e r n a l F u n c t i o n ( TTr imLeftFunc ,’TrimLeft’ , [ ’str’, c S t r i n g ] , c S t r i n g ) ;
55
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
R e g i s t e r I n t e r n a l F u n c t i o n ( TTrimRightFunc ,’TrimRight’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
24 R e g i s t e r I n t e r n a l F u n c t i o n ( TTrimFunc ,’Trim’ , [ ’str’ , c S t r i n g] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCompareTextFunc ,’CompareText’ , [’str1’ , c S t r i n g , ’str2’ , c S t r i n g ] , c I n t e g e r ) ;
26 R e g i s t e r I n t e r n a l F u n c t i o n ( TAnsiCompareTextFunc ,’AnsiCompareText’ , [ ’str1’ , c S t r i n g , ’str2’ , c S t r i n g ] ,c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCompareStrFunc ,’CompareStr’ , [ ’str1’ , c S t r i n g , ’str2’ , c S t r i n g ] , c I n t e g e r ) ;
28 R e g i s t e r I n t e r n a l F u n c t i o n ( TAnsiCompareStrFunc ,’AnsiCompareStr’ , [ ’str1’ , c S t r i n g , ’str2’ , c S t r i n g ] ,c I n t e g e r ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( T I sDe l im i t e rFunc ,’IsDelimiter’ , [’delims’ , c S t r i n g , ’s’ , c S t r i n g , ’index’ , c I n t e g e r ] ,cBoolean ) ;
30 R e g i s t e r I n t e r n a l F u n c t i o n ( TLas tDe l im i te rFunc ,’LastDelimiter’ , [ ’delims’ , c S t r i n g , ’s’ , c S t r i n g ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TQuotedStrFunc ,’QuotedStr’ , [ ’str’ , c S t r i n g ] , c S t r i n g ) ;
32 R e g i s t e r I n t e r n a l F u n c t i o n ( TCopyFunc ,’Copy’ , [ ’str’ , c S t r i n g, ’Index’ , c I n t e g e r , ’Len’ , c I n t e g e r ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TLe f tS t rFunc ,’LeftStr’ , [ ’AText’, c S t r i n g , ’ACount’ , c I n t e g e r ] , c S t r i n g ) ;
34 R e g i s t e r I n t e r n a l F u n c t i o n ( TRigh tSt rFunc ,’RightStr’ , [ ’AText’ , c S t r i n g , ’ACount’ , c I n t e g e r ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TMidStrFunc ,’MidStr’ , [ ’AText’ ,c S t r i n g ,’AStart’ , c I n t e g e r , ’ACount’ , c I n t e g e r ] , c S t r i n g) ;
36 R e g i s t e r I n t e r n a l F u n c t i o n ( TStr ingOfCharFunc ,’StringOfChar’, [ ’Ch’ , c S t r i n g , ’Count’ , c I n t e g e r ] , c S t r i n g ) ;
Please note that most of the Delphi function descriptions below are taken from the Delphi help.For your convenience we chose to replicate them here.
56
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.2.1. String Utilities - DWS IIReference
IntToStr
IntToStr converts an integer into a string con-taining the decimal representation of that num-ber.
Declaration
function IntToStr(i: Integer): String;
StrToInt
StrToInt converts the string S, which representsan integer-type number in either decimal or hex-adecimal notation, into a number. If S doesnot represent a valid number, StrToInt raises anEDelphi exception.
Declaration
function StrToInt(S: String): Integer;
StrToIntDef
StrToIntDef converts the string S, which repre-sents an integer-type number in either decimalor hexadecimal notation, into a number. If Sdoes not represent a valid number, StrToIntDefreturns the number passed in Default.
Declaration
function StrToIntDef(const S: string; Default:Integer): Integer;
IntToHex
IntToHex converts a number into a string con-taining the number’s hexadecimal (base 16) rep-resentation. Value is the number to convert.Digits indicates the minimum number of hex-adecimal digits to return.
Declaration
function IntToHex(Value: Integer; Digits:Integer): string;
FloatToStr
FloatToStr converts the floating-point value givenby Value to its string representation. The con-version uses general number format with 15significant digits.
For greater control over the formatting of thestring, use the FloatToStrF function.
Declaration
function FloatToStr(Value: Float): string;
StrToFloat
Use StrToFloat to convert a string, S, to a floating-point value. S must consist of an optional sign(+ or -), a string of digits with an optional deci-mal point, and an optional mantissa. The man-tissa consists of ’E’ or ’e’ followed by an op-tional sign (+ or -) and a whole number. Lead-ing and trailing blanks are ignored.
The DecimalSeparator global variable definesthe character that must be used as a decimalpoint. Thousand separators and currency sym-bols are not allowed in the string. If S doesn’tcontain a valid value, StrToFloat raises an ECon-vertError (=EDelphi) exception.
Declaration
function StrToFloat(const S: string): float;
StrToFloatDef
Same as StrToFloat but if the conversion failsthe result value is parameter def .
Declaration
function StrToFloatDef(const S: string; def:float): float;
57
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
Chr
Chr returns the character with the ordinal value(ASCII value) of the byte-type expression, X.
Declaration
function Chr( x: Integer): String;
Ord
Ord returns the ASCII value of char s.
Declaration
function Ord(s: String): Integer;
CharAt
Returns the char at position i from string x.Replacement for Delphi styleresult := x[i]
Declaration
function CharAt(x: String; i: Integer): String;
SetCharAt
Sets the char at position i in string x to value.Replacement for Delphi stylex[i] := value
Declaration
procedure SetCharAt(var x:string; i: inte-ger; value: string);
Delete
Delete removes a substring of Count charac-ters from string S starting with S[Index]. Sis a string-type variable. Index and Count areinteger-type expressions.
If index is larger than the length of the S orless than 1, no characters are deleted.
If count specifies more characters than re-main starting at the index, Delete removes therest of the string. If count is less than 0, nocharacters are deleted.
Declaration
procedureDelete(var S: string; Index, Count:Integer);
Insert
Insert merges Source into S at the position S[index].Source is a string-type expression. S is a
string-type variable of any length. Index is aninteger-type expression. It is a character indexand not a byte index.
If Index is less than 1, it is mapped to a 1.If it is past the end of the string, it is set to thelength of the string, turning the operation intoan append.
If the Source parameter is an empty string,Insert does nothing.
Insert throws an EOutOfMemory (=EDelphi)exception if it is unable to allocate enough mem-ory to accommodate the new returned string.
Declaration
procedureInsert(Source: string;var S: string;Index: Integer);
LowerCase
LowerCase returns a string with the same textas the string passed in S, but with all lettersconverted to lowercase. The conversion affectsonly 7-bit ASCII characters between ’A’ and’Z’. To convert 8-bit international characters,use AnsiLowerCase.
Declaration
function LowerCase(S: string): string;
AnsiLowerCase
AnsiLowerCase returns a string that is a copyof the given string converted to lower case. Theconversion uses the current locale. This func-tion supports multi-byte character sets (MBCS).
58
Rel
ease
Can
dida
te2
3.2. Internal Functions
Declaration
function AnsiLowerCase(S: string): string;
UpperCase
UpperCase returns a copy of the string S, withthe same text but with all 7-bit ASCII char-acters between ’a’ and ’z’ converted to upper-case. To convert 8-bit international characters,use AnsiUpperCase instead.
Declaration
function UpperCase(S: string): string;
AnsiUpperCase
AnsiUpperCase returns a string that is a copyof S, converted to upper case. The conversionuses the current locale.
Note: This function supports multi-byte char-acter sets (MBCS).
Declaration
function AnsiUpperCase(S: string): string;
Pos
Pos searches for a substring, Substr, in a string,S. Substr and S are string-type expressions.
Pos searches for Substr within S and returnsan integer value that is the index of the firstcharacter of Substr within S. Pos is case-sensitive.If Substr is not found, Pos returns zero
Declaration
function Pos(Substr: string; S: string): Inte-ger;
Length
Length returns the number of characters actu-ally used in the string.
Declaration
function Length(S): Integer;
SetLength
Sets the length of string S to NewLength.
Declaration
procedureSetLength(var S : String; NewLength: Integer);
TrimLeft
TrimLeft returns a copy of the string S withleading spaces and control characters removed.
Declaration
function TrimLeft(S: string): string;
TrimRight
TrimRight returns a copy of the string S withtrailing spaces and control characters removed.
Declaration
function TrimRight(S: string): string;
Trim
Trim removes leading and trailing spaces andcontrol characters from the given string S.
Declaration
function Trim(S: string): string;
CompareText
CompareText compares S1 and S2 and returns0 if they are equal. If S1 is greater than S2,CompareText returns an integer greater than 0.If S1 is less than S2, CompareText returns aninteger less than 0. CompareText is not casesensitive and is not affected by the current lo-cale.
Declaration
function CompareText(S1, S2: string): In-teger;
59
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
AnsiCompareText
AnsiCompareText compares S1 to S2, withoutcase sensitivity. The compare operation is con-trolled by the current locale. AnsiCompare-Text returns a value less than 0 if S1 < S2, avalue greater than 0 if S1 > S2, and returns 0 ifS1 = S2.
Declaration
function AnsiCompareText(S1, S2: string):Integer;
CompareStr
CompareStr compares S1 to S2, with case sen-sitivity. The return value is less than 0 if S1 isless than S2, 0 if S1 equals S2, or greater than0 if S1 is greater than S2. The compare opera-tion is based on the 8-bit ordinal value of eachcharacter and is not affected by the current lo-cale.
Declaration
function CompareStr(S1, S2: string): Inte-ger;
AnsiCompareStr
AnsiCompareStr compares S1 to S2, with casesensitivity. The compare operation is controlledby the current locale. The return value is:
Condition Return ValueS1 > S2 > 0S1 < S2 < 0S1 = S2 = 0Note: Most locales consider lowercase char-
acters to be less than the corresponding upper-case characters. This is in contrast to ASCII or-der, in which lowercase characters are greaterthan uppercase characters. Thus, AnsiCom-pareStr(’a’,’A’) returns a value less than zero,while CompareStr(’a’,’A’) returns a value greaterthan zero.
Declaration
function AnsiCompareStr( S1, S2: string):Integer;
IsDelimiter
Call IsDelimiter to determine whether the char-acter at byte offset Index in the string S is oneof the delimiters in the string Delimiters. In-dex is the 0-based index of the byte in question,where 0 is the first byte of the string, 1 is thesecond byte, and so on.
When working with a multi-byte charactersystem (MBCS), IsDelimiter checks to makesure the indicated byte is not part of a doublebyte character. The delimiters in the Delime-ters parameter must all be single byte charac-ters.
Declaration
function IsDelimiter(Delimiters, S: string;Index: Integer): Boolean;
LastDelimiter
Call LastDelimiter to locate the last delimiterin S. For example, the line
MyIndex := LastDelimiter(’\.:’,’c:\filename.ext’);sets MyIndex to 12.When working with multi-byte character sets
(MBCS), S may contain double byte charac-ters, but the delimiters listed in the Delime-ters parameter must all be single byte non-nullcharacters.
Declaration
function LastDelimiter(Delimiters, S: string):Integer;
60
Rel
ease
Can
dida
te2
3.2. Internal Functions
QuotedStr
Use QuotedStr to convert the string S to a quotedstring. A single quote character (’) is insertedat the beginning and end of S, and each singlequote character in the string is repeated.
Declaration
function QuotedStr( S: string): string;
Copy
S is an expression of a string. Index and Countare integer-type expressions. Copy returns asubstring containing Count characters or ele-ments starting at S[Index].
If Index is larger than the length of S, Copyreturns an empty string or array.
If Count specifies more characters than areavailable, only the characters from S[Index] tothe end of S are returned.
Declaration
function Copy(S: String; Index, Count: In-teger): String;
LeftStr
Does a Copy(Info[’AText’], 1, integer(info[’ACount’]));
Declaration
function LeftStr(AText: String; ACount: In-teger): String;
RightStr
Does a Copy(Info[’AText’], Length(Info[’AText’])+ 1 - integer(info[’ACount’]), integer(info[’ACount’]));
Declaration
function RightStr(AText: String; ACount:Integer): String;
MidStr
Does a Copy(Info[’AText’], integer(info[’AStart’]),integer(info[’ACount’]));
Declaration
function MidStr(AText: String; AStart, ACount:Integer): string;
StringOfChar
StringOfChar returns a string containing Countcharacters with the character value given byCh. For example,
S := StringOfChar(’A’, 10);sets S to the string ’AAAAAAAAAA’.
Declaration
function StringOfChar(Ch : String; Count :Integer) : String;
61
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
3.2.3. Time Functions
Listing 3.4:Internal Functions: DateTime Functions
2 R e g i s t e r I n t e r n a l F u n c t i o n ( TNowFunc ,’Now’ , [ ] , cDateTime ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TDateFunc ,’Date’ , [ ] , cDateTime ) ;
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TTimeFunc ,’Time’ , [ ] , cDateTime ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TDateTimeToStrFunc ,’DateTimeToStr
’ , [ ’dt’ , cDateTime ] , c S t r i n g ) ;6 R e g i s t e r I n t e r n a l F u n c t i o n ( TStrToDateTimeFunc ,’StrToDateTime
’ , [ ’str’ , c S t r i n g ] , cDateTime ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TDateToStrFunc ,’DateToStr’ , [ ’dt’
, cDateTime ] , c S t r i n g ) ;8 R e g i s t e r I n t e r n a l F u n c t i o n ( TStrToDateFunc ,’StrToDate’ , [ ’str
’ , c S t r i n g ] , cDateTime ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TTimeToStrFunc ,’TimeToStr’ , [ ’dt’
, cDateTime ] , c S t r i n g ) ;10 R e g i s t e r I n t e r n a l F u n c t i o n ( TStrToTimeFunc ,’StrToTime’ , [ ’str
’ , c S t r i n g ] , cDateTime ) ;R e g i s t e r I n t e r n a l F u n c t i o n ( TDayOfWeekFunc ,’DayOfWeek’ , [ ’dt’
, cDateTime ] , c I n t e g e r ) ;12 R e g i s t e r I n t e r n a l F u n c t i o n ( TFormatDateTimeFunc ,’
FormatDateTime’ , [ ’frm’ , c S t r i n g , ’dt’ , cDateTime ] ,c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TIsLeapYearFunc ,’IsLeapYear’ , [ ’year’ , c I n t e g e r ] , cBoolean ) ;
14 R e g i s t e r I n t e r n a l F u n c t i o n ( TIncMonthFunc ,’IncMonth’ , [ ’dt’ ,cDateTime , ’nb’ , c I n t e g e r ] , cDateTime ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TDecodeDateFunc ,’DecodeDate’ , [ ’dt’ , cDateTime , ’@y’ , c I n t e g e r , ’@m’ , c I n t e g e r , ’@d’ ,c I n t e g e r ] , ’’ ) ;
16 R e g i s t e r I n t e r n a l F u n c t i o n ( TEncodeDateFunc ,’EncodeDate’ , [ ’y’ , c I n t e g e r , ’m’ , c I n t e g e r , ’d’ , c I n t e g e r ] , cDateTime ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TDecodeTimeFunc ,’DecodeTime’ , [ ’dt’ , cDateTime , ’@h’ , c I n t e g e r , ’@m’ , c I n t e g e r , ’@s’ ,c I n t e g e r , ’@ms’ , c I n t e g e r ] , ’’ ) ;
18 R e g i s t e r I n t e r n a l F u n c t i o n ( TEncodeTimeFunc ,’EncodeTime’ , [ ’h’ , c I n t e g e r , ’m’ , c I n t e g e r , ’s’ , c I n t e g e r , ’ms’ ,c I n t e g e r ] , cDateTime ) ;
62
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.3.1. Time Utilities - DWS IIReference
Now
Returns the current date and time, correspond-ing to Date + Time.
Note: Although TDateTime values can rep-resent milliseconds, Now only returns the timeto the closest second.
Declaration
function Now: TDateTime;
Date
Use Date to obtain the current local date asa TDateTime value. The time portion of thevalue is 0 (midnight).
Declaration
function Date: TDateTime;
Time
Time returns the current time as a TDateTimevalue.
Declaration
function Time: TDateTime;
DateTimeToStr
The function DateTimeToString converts theTDateTime value given by DateTime using theformat given by the ShortDateFormat globalDelphi variable, followed by the time using theformat given by the LongTimeFormat globalDelphi variable. The time is not displayed ifthe fractional part of the DateTime value is zero.
To change how the string is formatted, changeShortDateFormat and LongTimeFormat globaldate time formatting variables in Delphi.
Declaration
function DateTimeToStr(DateTime: TDate-Time): string;
StrToDateTime
Call StrToDate to parse a string that specifiesa date and time value. If S does not contain avalid date, StrToDate raises an EConvertError(=EDelphi) exception.
The S parameter must use the current localesdate/time format. In the US, this is commonlyMM/DD/YY HH:MM:SS format. SpecifyingAM or PM as part of the time is optional, asare the seconds. Use 24-hour time (7:45 PM isentered as 19:45, for example) if AM or PM isnot specified.
Y2K issue: The conversion of two-digit yearvalues is determined by the TwoDigitYearCentu-ryWindow variable. For more information, seeStrToDate.
Note: The format of the date and time stringvaries when the values of date/time formattingvariables are changed.
Declaration
function StrToDateTime(const S: string): TDate-Time;
DateToStr
Use DateToStr to obtain a string representationof a date value that can be used for display pur-poses. The conversion uses the format speci-fied by the ShortDateFormat global variable.
Declaration
function DateToStr(Date: TDateTime): string;
63
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
StrToDate
Call StrToDate to parse a string that specifies adate. If S does not contain a valid date, StrTo-Date raises an EConvertError (=EDelphi) ex-ception.
S must consist of two or three numbers, sep-arated by the character defined by the Date-Separator global Delphi variable. The orderfor month, day, and year is determined by theShortDateFormat global Delphi variable - pos-sible combinations are m/d/y, d/m/y, and y/m/d.
If S contains only two numbers, it is inter-preted as a date (m/d or d/m) in the currentyear.
Year values between 0 and 99 are convertedusing the TwoDigitYearCenturyWindow globalDelphi variable. If TwoDigitYearCenturyWin-dow is 0, year values between 0 and 99 are as-sumed to be in the current century. If TwoDigi-tYearCenturyWindow is greater than 0, its valueis subtracted from the current year to determinethe pivot; years on or after the pivot are keptin the current century, while years prior to thepivot are moved to the next century. For exam-ple:
Cur
rent
year
TwoD
igit-
Yea
r-C
entu
ry-
Win
dow
Piv
otda
te=
mm
/dd/
03da
te=
mm
/dd/
50da
te=
mm
/dd/
68
1998
019
0019
0319
5019
68
2002
020
0020
0320
5020
68
1998
5019
4820
0319
5019
68
2000
5019
5020
0319
5019
68
2002
5019
5220
0320
5019
68
2020
5019
7020
0320
5020
68
2020
1020
1021
0320
5020
68
Note: The format of the date string varieswhen the values of date/time formatting vari-ables are changed.
Declaration
function StrToDate(const S: string): TDate-Time;
TimeToStr
TimeToStr converts the Time parameter, a TDate-Time value, to a string. The conversion usesthe format specified by the LongTimeFormatglobal Delphi variable. Change the format ofthe string by changing the values of some ofthe date and time Delphi variables.
Declaration
function TimeToStr(Time: TDateTime): string;
64
Rel
ease
Can
dida
te2
3.2. Internal Functions
StrToTime
Call StrToTime to parse a string that specifiesa time value. If S does not contain a valid time,StrToTime raises an EConvertError (=EDelphi)exception.
The S parameter must consist of two or threenumbers, separated by the character defined bythe TimeSeparator global variable, optionallyfollowed by an AM or PM indicator. The num-bers represent hour, minute, and (optionally)second, in that order. If the time is followedby AM or PM, it is assumed to be in 12-hourclock format. If no AM or PM indicator is in-cluded, the time is assumed to be in 24-hourclock format.
Note: The format of the date and time stringvaries when the values of date/time formattingDelphi variables are changed.
Declaration
function StrToTime(const S: string): TDate-Time;
DayOfWeek
DayOfWeek returns the day of the week of thespecified date as an integer between 1 and 7,where Sunday is the first day of the week andSaturday is the seventh.
Note: DayOfWeek is not compliant with theISO 8601 standard, which defines Monday asthe first day of the week.
Declaration
function DayOfWeek(Date: TDateTime): In-teger;
FormatDateTime
FormatDateTime formats the TDateTime valuegiven by DateTime using the format given byFormat. See Date-Time format strings in theDelphi help for more information.
If the string specified by the Format parame-ter is empty, the TDateTime value is formattedas if a ’c’ format specifier had been given.
Declaration
function FormatDateTime(Format: string;DateTime: TDateTime): string;
IsLeapYear
Call IsLeapYear to determine whether the yearspecified by the Year parameter is a leap year.Year specifies the calendar year.
Declaration
function IsLeapYear(Year: Integer): Boolean;
IncMonth
IncMonth returns the value of the Date parame-ter, incremented by NumberOfMonths months.NumberOfMonths can be negative, to return adate N months previous.
If the input day of month is greater than thelast day of the resulting month, the day is set tothe last day of the resulting month. The time ofday specified by the Date parameter is copiedto the result.
Declaration
function IncMonth(Date: TDateTime; Num-berOfMonths: Integer): TDateTime;
DecodeDate
The DecodeDate procedure breaks the valuespecified as the Date parameter into Year, Month,and Day values. If the given TDateTime valuehas a negative (BC) year, the year, month, andday return parameters are all set to zero.
Declaration
procedure DecodeDate(Date: TDateTime;var Year, Month, Day: Integer);
65
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
EncodeDate
EncodeDate returns a TDateTime value fromthe values specified as the Year, Month, andDay parameters.
The year must be between 1 and 9999.Valid Month values are 1 through 12.Valid Day values are 1 through 28, 29, 30,
or 31, depending on the Month value. For ex-ample, the possible Day values for month 2(February) are 1 through 28 or 1 through 29,depending on whether or not the Year valuespecifies a leap year.
If the specified values are not within range,EncodeDate raises an EConvertError (= EDel-phi) exception.
Declaration
function EncodeDate(Year, Month, Day: In-teger): TDateTime;
DecodeTime
DecodeTime breaks the object specified as theTime parameter into hours, minutes, seconds,and milliseconds.
Declaration
procedure DecodeTime(Time: TDateTime;var Hour, Min, Sec, MSec: Integer);
EncodeTime
EncodeTime encodes the given hour, minute,second, and millisecond into a TDateTime value.
Valid Hour values are 0 through 24. If Houris 24, Min, Sec, and MSec must all be 0, andthe resulting TDateTime value represents mid-night (12:00:00:000 AM) of the following day.
Valid Min and Sec values are 0 through 59.Valid MSec values are 0 through 999.If the specified values are not within range,
EncodeTime raises an EConvertError exception.
The resulting value is a number between 0and 1 (inclusive) that indicates the fractionalpart of a day given by the specified time or (if1.0) midnight on the following day. The value0 corresponds to midnight, 0.5 corresponds tonoon, 0.75 corresponds to 6:00 pm, and so on.
Declaration
function EncodeTime(Hour, Min, Sec, MSec:Integer): TDateTime;
66
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.4. Variant Functions
Listing 3.5:Internal Functions: Variant Functions
2 procedure I n i t V a r i a n t s ( SystemTable , UnitSyms , Un i tTab le :TSymbolTable ) ;
var4 T , E : TTypeSymbol ;
begin6 T : = SystemTable . FindSymbol (’Integer’ ) as TTypeSymbol ;
E : = TEnumerat ionSymbol . C r e a t e (’TVarType’ ,T ) ;8 Un i tTab le . AddSymbol (E ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varEmpty’ , E ,varEmpty , True ) ) ;
10 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varNull’ , E ,va rNu l l , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varSmallint’ ,E , v a r S m a l l i n t , True ) ) ;
12 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varInteger’ , E, v a r I n t e g e r , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varSingle’ , E, v a r S i n g l e , True ) ) ;
14 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varDouble’ , E, varDouble , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varCurrency’ ,E , varCur rency , True ) ) ;
16 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varDate’ , E ,varDate , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varOleStr’ , E, va rO leS t r , True ) ) ;
18 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varDispatch’ ,E , va rD i spa t ch , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varError’ , E ,v a r E r r o r , True ) ) ;
20 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varBoolean’ , E, varBoolean , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varVariant’ , E, v a r V a r i a n t , True ) ) ;
22 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varUnknown’ , E, varUnknown , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varShortInt’ ,E , v a r S h o r t I n t , True ) ) ;
24 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varByte’ , E ,varByte , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varWord’ , E ,varWord , True ) ) ;
67
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
26 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varLongWord’ ,E , varLongWord , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varInt64’ , E ,v a r I n t 6 4 , True ) ) ;
28 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varStrArg’ , E, va rS t rArg , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varString’ , E, v a r S t r i n g , True ) ) ;
30 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varAny’ , E ,varAny , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varTypeMask’ ,E , varTypeMask , True ) ) ;
32 Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varArray’ , E ,varAr ray , True ) ) ;
Un i tTab le . AddSymbol ( TElementSymbol . C r e a t e (’varByRef’ , E ,varByRef , True ) ) ;
34
T : = SystemTable . FindSymbol (’Variant’ ) as TTypeSymbol ;36 Un i tTab le . AddSymbol ( TConstSymbol . C r e a t e (’Null’ , T , Nu l l ) )
;Un i tTab le . AddSymbol ( TConstSymbol . C r e a t e (’Unassigned’ , T ,
Unass igned ) ) ;38 end ;
i n i t i a l i z a t i o n40 R e g i s t e r I n t e r n a l I n i t P r o c ( @ I n i t V a r i a n t s ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TVarClearFunc ,’VarClear’ , [ ’@v’, c V a r i a n t ] , ’’ ) ;
42 R e g i s t e r I n t e r n a l F u n c t i o n ( TVar IsNul lFunc ,’VarIsNull’ , [ ’v’ , c V a r i a n t ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TVarIsEmptyFunc ,’VarIsEmpty’ , [’v’ , c V a r i a n t ] , cBoolean ) ;
44 R e g i s t e r I n t e r n a l F u n c t i o n ( TVarAsTypeFunc ,’VarAsType’ , [ ’v’ , cVa r i an t , ’VarType’ , c I n t e g e r ] , c V a r i a n t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TVarToStrFunc ,’VarToStr’ , [ ’v’, c V a r i a n t ] , c S t r i n g ) ;
46
end .
68
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.4.1. Variant Utilities - DWS IIReference
Null
Use Null to obtain a Null Variant that can in-dicate unknown or missing data. Null Variantscan be assigned to variables in an applicationthat must contain a null value. Assigning Nullto a variant variable does not cause an error,and Null can be returned from any functionwith a variant return value.
Expressions involving Null Variants alwaysresult in a Null Variant. Thus, Null is said topropagate through intrinsic functions that re-turn variant data types. If any part of the ex-pression evaluates to Null, the entire expres-sion evaluates to Null.
Declaration
constNull: Variant;
Unassigned
The Unassigned constant is used to indicate thata variant has not yet been assigned a value.The initial value of any variant is Unassigned.The Unassigned value disappears as soon as avariant is assigned any other value, includingthe value 0, a zero-length string, and the Nullvalue.
Use the VarIsEmpty internal function to testwhether a variant is Unassigned. When usedon an Unassigned variant, the VarType inter-nal function returns varEmpty. An EVariantEr-ror (=EDelphi) exception is raised if an Unas-signed variant appears in any other expressionor an attempt is made to convert an Unassignedvariant to another type (using VarAsType).
You can make a variant unassigned by as-signing the Unassigned return value to it..
Declaration
constUnassigend: Variant;
VarClear
Calling VarClear is equivalent to assigning theUnassigned value to the Variant. V can be ei-ther a Variant or an OleVariant, but it must bepossible to assign a value to it (it must be anlvalue).
After calling VarClear, the VarIsEmpty func-tion returns True. Using an unassigned vari-ant in an expression causes an EVariantError(=EDelphi) exception to be thrown. Likewise,if you attempt to convert an unassigned Variantto another type (using VarAsType ), an EVari-antError (=EDelphi) exception is thrown.
Note: Do not confuse clearing a Variant, whichleaves it unassigned, with assigning a Null value.A Null Variant is still assigned, but has the valueNull. Unlike unassigned Variants, Null Vari-ants can be used in expressions and can be con-verted to other types of Variants.
Declaration
procedureVarClear(V: Variant);
VarIsNull
VarIsNull returns True if the given variant con-tains the value Null. If the variant contains anyother value, the function result is False.
Note: Do not confuse a Null variant with anunassigned variant. A Null variant is still as-signed, but has the value Null. Unlike unas-signed variants, Null variants can be used inexpressions and can be converted to other typesof variants.
Declaration
function VarIsNull(const V: Variant): Boolean;
VarIsEmpty
VarIsEmpty returns True if the given variantcontains the value Unassigned. If the variant
69
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
contains any other value, the function result isFalse.
Note: Do not confuse an unassigned vari-ant with a Null variant. A Null variant is stillassigned, but has the value Null. Unlike unas-signed variants, Null variants can be used inexpressions and can be converted to other typesof variants.
Declaration
function VarIsEmpty(const V: Variant): Boolean;
VarAsType
VarAsType converts a variant to a specified typeand returns a new Variant that has the specifiedtype.
V is the Variant to convert.VarType is a variant type code that indicates
the type to which V should be converted. Thiscan be one of the constants defined by the dws2VariantFunctionsDelphi unit, or it can be the integer type codefor a custom variant type. It cannot include thevarArray or varByRef bits.
VarAsType throws an EVariantError (= EDel-phi) exception if the variant cannot be convertedto the given type.
Following VarTypes are available:varEmpty,varNull, varSmallint, varInteger, varSingle, var-Double, varCurrency, varDate, varOleStr, varDis-patch, varError, varBoolean, varVariant, varUn-known, varShortInt, varByte, varWord, varLong-Word, varInt64, varStrArg, varString, varAny,varTypeMask, varArray, varByRef.
Declaration
function VarAsType(V: Variant; VarType: In-teger): Variant;
VarToStr
VarToStr converts the data in the variant V to astring and returns the result. If the variant hasa null value, VarToStr returns an empty string.
Declaration
function VarToStr(const V: Variant): String;
70
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.5. FileFunctions (Component)
Due to security reasons the file functions are NOT included by default! If you want to allowyour scripts access to the local file system, you have to drop the FileFunctions component ontothe form that contains the TDelphiWebScriptII component.
AT
TE
NT
ION Including the file functions may lead to security problems!
For web development we strongly discourage the use of this component,but suggest that you write your own access functions that provide onlyaccess to the files you absolutely need.
Listing 3.6:Internal Functions: File Functions
2 R e g i s t e r I n t e r n a l F u n c t i o n ( TSaveSt r ingToF i leFunc ,’SaveStringToFile’ , [ ’fileName’ , c S t r i n g , ’data’ , c S t r i n g] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TLoadSt r ingFromFi leFunc ,’LoadStringFromFile’ , [ ’fileName’ , c S t r i n g ] , c S t r i n g ) ;
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TAppendSt r ingToFi leFunc ,’AppendStringToFile’ , [ ’fileName’ , c S t r i n g , ’data’ ,c S t r i n g ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( T F i l e E x i s t s F u n c ,’FileExists’ , [ ’fileName’ , c S t r i n g ] , cBoolean ) ;
6 R e g i s t e r I n t e r n a l F u n c t i o n ( TDe le teF i l eFunc ,’DeleteFile’ , [ ’fileName’ , c S t r i n g ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TRenameFileFunc ,’RenameFile’ , [ ’oldName’ , c S t r i n g , ’newName’ , c S t r i n g ] , cBoolean ) ;
8 R e g i s t e r I n t e r n a l F u n c t i o n ( TChDirFunc ,’ChDir’ , [ ’s’ , c S t r i n g] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCreateDi rFunc ,’CreateDir’ , [ ’dir’ , c S t r i n g ] , cBoolean ) ;
10 R e g i s t e r I n t e r n a l F u n c t i o n ( TRemoveDirFunc ,’RemoveDir’ , [ ’dir’ , c S t r i n g ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TGetCur rentDi rFunc ,’GetCurrentDir’ , [ ] , c S t r i n g ) ;
12 R e g i s t e r I n t e r n a l F u n c t i o n ( TSetCur ren tD i rFunc ,’SetCurrentDir’ , [ ’dir’ , c S t r i n g ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TF i leSearchFunc ,’FileSearch’ , [ ’name’ , c S t r i n g , ’dirList’ , c S t r i n g ] , c S t r i n g ) ;
14 R e g i s t e r I n t e r n a l F u n c t i o n ( T E x t r a c t F i l e D r i v e F u n c ,’ExtractFileDrive’ , [ ’fName’ , c S t r i n g ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( T E x t r a c t F i l e D i r F u n c ,’ExtractFileDir’ , [ ’fName’ , c S t r i n g ] , c S t r i n g ) ;
71
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
16 R e g i s t e r I n t e r n a l F u n c t i o n ( TExt rac tF i leNameFunc ,’ExtractFileName’ , [ ’fName’ , c S t r i n g ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( T E x t r a c t F i l e P a t h F u n c ,’ExtractFilePath’ , [ ’fName’ , c S t r i n g ] , c S t r i n g ) ;
18 R e g i s t e r I n t e r n a l F u n c t i o n ( T E x t r a c t F i l e E x t F u n c ,’ExtractFileExt’ , [ ’fName’ , c S t r i n g ] , c S t r i n g ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TChangeFi leExtFunc ,’ChangeFileExt’ , [ ’fName’ , c S t r i n g , ’ext’ , c S t r i n g ] , c S t r i n g ) ;
72
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.5.1. File Utilities - DWS II Reference
SaveStringToFile
Saves string "data" to file "filename".Note: SaveStringToFile creates the file if it
does not exist. Otherwise the file is opened inwrite mode.
The function might throw an EDelphi excep-tion if the file can not be opened / created.
Declaration
procedureSaveStringToFile(FileName,Data: String);
LoadStringFromFile
Returns contents of file "filename" as string.File “FileName” is opened using thefmShare-
DenyNoneflag.Note that this function might throw an EDel-
phi exception, if the file can not be opened.
Declaration
function LoadStringFromFile(FileName:string): String;
AppendStringToFile
Adds string "Data" to file "FileName"
Declaration
procedureAppendStringToFile(FileName,Data: String);
FileExists
FileExists returns True if the file specified byFileName exists. If the file does not exist, File-Exists returns False.
Declaration
function FileExists(FileName: string):Boolean;
DeleteFile
DeleteFile deletes the file named by FileNamefrom the disk. If the file cannot be deleted ordoes not exist, the function returns False.
Declaration
function DeleteFile(FileName: string): Boolean;
RenameFile
RenameFile attempts to change the name of thefile specified by OldFile to NewFile. If theoperation succeeds, RenameFile returns True.If it cannot rename the file (for example, if afile called NewName already exists), it returnsFalse.
Declaration
function RenameFile(OldName, NewName:string): Boolean;
ChDir
ChDir changes the current directory to the pathspecified by S.
You may get an EDelphi exception when call-ing this function and an IOError occurred.
Declaration
procedureChDir(S: string);
CreateDir
CreateDir creates a new directory. The returnvalue is True if a new directory was success-fully created, or False if an error occurred.
Declaration
function CreateDir(Dir: string): Boolean;
73
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
RemoveDir
Call RemoveDir to remove the directory spec-ified by the Dir parameter. The return value isTrue if a new directory was successfully deleted,False if an error occurred. The directory mustbe empty before it can be successfully deleted.
Declaration
function RemoveDir(Dir: string): Boolean;
GetCurrentDir
GetCurrentDir returns the fully qualified nameof the current directory.
Declaration
function GetCurrentDir: string;
SetCurrentDir
The SetCurrentDir function sets the current di-rectory. The return value is True if the currentdirectory was successfully changed, or False ifan error occurred.
Declaration
function SetCurrentDir(Dir: string):Boolean;
FileSearch
FileSearch searches through the directoriespassed in DirList for a file named Name. DirListis a list of path names delimited by semicolonson Windows (colons on Linux). If FileSearchlocates a file matching Name, it returns a stringspecifying a path name for that file. If no match-ing file exists, FileSearch returns an empty string.
Declaration
function FileSearch(Name, DirList: string):string;
ExtractFileDrive
ExtractFileDrive returns a string containing thedrive portion of a fully qualified path name forthe file passed in the FileName. For file nameswith drive letters, the result is in the form ’<drive>’.For file names with a UNC path the result isin the form ’. If the given path contains nei-ther style of path prefix, the result is an emptystring.
Declaration
function ExtractFileDrive(FileName: string):string;
ExtractFileDir
The resulting string is a directory name suit-able for passing to the CreateDir, RemoveDir,and SetCurrentDir functions. This string is emptyif FileName contains no drive and directory parts.
Declaration
function ExtractFileDir(const FileName: string):string;
ExtractFileName
The resulting string is the rightmost charactersof FileName, starting with the first characterafter the colon or backslash that separates thepath information from the name and extension.The resulting string is equal to FileName if File-Name contains no drive and directory parts.
Declaration
function ExtractFileName(FileName: string):string;
74
Rel
ease
Can
dida
te2
3.2. Internal Functions
ExtractFilePath
The resulting string is the leftmost charactersof FileName, up to and including the colon orbackslash that separates the path informationfrom the name and extension. The resultingstring is empty if FileName contains no driveand directory parts.
Declaration
function ExtractFilePath(FileName: string):string;
ExtractFileExt
Use ExtractFileExt to obtain the extension froma file name. For example, the following codereturns the extension of the file name specifiedby a variable named MyFileName:
MyFilesExtension := ExtractFileExt(MyFileName);The resulting string includes the period char-
acter that separates the name and extension parts.This string is empty if the given file name hasno extension.
Declaration
function ExtractFileExt(FileName: string):string;
ChangeFileExt
ChangeFileExt takes the file name passed inFileName and changes the extension of the filename to the extension passed in Extension. Ex-tension specifies the new extension, includingthe initial dot character.
ChangeFileExt does not rename the actualfile, it just creates a new file name string.
Declaration
function ChangeFileExt(FileName, Exten-sion: string): string;
75
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
3.2.6. GUI Functions (Component)
Often the GUI functions are not needed in script. Due to this fact and the separation of theruntime packages into a version that depends on VCL and one that depends on CLX, the GUIfunctions are provided in a separate component and not included by default. If you want to usethem, simply drop the GUI Functions component onto the form containing the TDelphiWeb-ScriptII component.
HIN
T
If you use this component:
• You have to redistribute thedws2VCLRuntimepackage - if youwant to ship your VCL program using runtime packages.
• Redistribute thedws2CLXRuntimepackage, if you are using theCLX and ship your program with runtime packages.
Of course you also need to ship thedws2Runtimepackage in addition tothe package mentioned above.
Listing 3.7:Internal Functions: GUI Functions
2 R e g i s t e r I n t e r n a l F u n c t i o n ( TShowMessageFunc ,’ShowMessage’ , [’msg’ , c S t r i n g ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TInputBoxFunc ,’InputBox’ , [ ’aCaption’ , c S t r i n g , ’aPrompt’ , c S t r i n g , ’aDefault’ ,c S t r i n g ] , c S t r i n g ) ;
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TErrorDlgFunc ,’ErrorDlg’ , [ ’msg’, c S t r i n g ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( T In format ionDlgFunc ,’InformationDlg’ , [ ’msg’ , c S t r i n g ] ,’’ ) ;
6 R e g i s t e r I n t e r n a l F u n c t i o n ( TQuest ionDlgFunc ,’QuestionDlg’ , [’msg’ , c S t r i n g ] , cBoolean ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TOkCancelDlgFunc ,’OkCancelDlg’ , [’msg’ , c S t r i n g ] , cBoolean ) ;
76
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.6.1. GUI Utilities - DWS II Reference
ShowMessage
Call ShowMessage to display a simple mes-sage box with an OK button. The name of theapplication’s executable file appears as the cap-tion of the message box.
Msg parameter is the message string that ap-pears in the message box.
Note: If the user types Ctrl+C in the mes-sage box, the text of the message is copied tothe clipboard.
Declaration
procedureShowMessage(Msg: string);
InputBox
Call InputBox to bring up an input dialog boxready for the user to enter a string in its editbox.
ACaptionis the caption of the dialog box.APromptis the text that prompts the user to
enter input in the edit box.ADefaultis the string that appears in the edit
box when the dialog box first appears.If the user chooses the Cancel button, In-
putBox returns the default string. If the userchooses the OK button, InputBox returns thestring in the edit box.
Use the InputBox function when there is adefault value that should be used when the userchooses the Cancel button (or presses Esc) toexit the dialog.
Declaration
function InputBox(ACaption, APrompt, ADe-fault: string): string;
ErrorDlg
Call ErrorDlg to display a simple message boxwith an OK button. The name of the applica-tion’s executable file appears as the caption of
the message box. The message box contains anerror icon.
Msg parameter is the message string that ap-pears in the message box.
Note: If the user types Ctrl+C in the mes-sage box, the text of the message is copied tothe clipboard.
Declaration
procedureErrorDlg(Msg: string);
InformationDlg
Call InformationDlg to display a simple mes-sage box with an OK button. The name of theapplication’s executable file appears as the cap-tion of the message box. The message box con-tains an icon showing an exclamation sign.
Msg parameter is the message string that ap-pears in the message box.
Note: If the user types Ctrl+C in the mes-sage box, the text of the message is copied tothe clipboard.
Declaration
procedure InformationDlg(Msg: string);
QuestionDlg
The message box contains an icon showing aquestion mark and two buttons "Yes" and "No".
Msg parameter is the message string that ap-pears in the message box.
The return value is true if the "Yes" buttonwas pressed and false otherwise.
Declaration
function QuestionDlg(Msg: string): Boolean;
77
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
OkCancelDlg
The message box contains an icon showing aquestion mark and two buttons "Yes" and "Can-cel".
Msg parameter is the message string that ap-pears in the message box.
The return value is true if the "Yes" buttonwas pressed and false otherwise.
Declaration
function OkCancelDlg(Msg: string): Boolean;
78
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.7. Global Variable Functions (Component)
This component implements global variables functions, that allow scripts to read and write tovariables across a script’s context. Details:
• Variables can be declared and read from any script, or from Delphi code
• Read/Write access is thread-safe
• Variables names arecase sensitive
• Fast, (reads/writes per second on a 800MHz Duron and a handful of variables: 100k/sec,1000k with optimization using D5)
The global variables can be saved/restored as a whole only from Delphi code (Delphi code onlyas of now, mainly for security reasons) to a file, string or stream. Be aware DWS II will requirespecial care to run in a multi-threaded environment.
Listing 3.8:Internal Functions: Global Variable Functions
2 { => Fo l low ing f u n c t i o n s are d e f i n e d i n DWSII s c r i p t : }
4 R e g i s t e r I n t e r n a l F u n c t i o n ( TReadGlobalVarFunc ,’ReadGlobalVar’ , [ ’n’ , c S t r i n g ] , c V a r i a n t ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TReadGlobalVarDefFunc ,’ReadGlobalVarDef’ , [ ’n’ , c S t r i n g , ’d’ , c V a r i a n t ] ,c V a r i a n t ) ;
6 R e g i s t e r I n t e r n a l F u n c t i o n ( TWri teGlobalVarFunc ,’WriteGlobalVar’ , [ ’n’ , c S t r i n g , ’v’ , c V a r i a n t ] , ’’ ) ;
R e g i s t e r I n t e r n a l F u n c t i o n ( TCleanupGlobalVarsFunc ,’CleanupGlobalVars’ , [ ] , ’’ ) ;
8
10
12
{ => Fo l low ing DELPHI f u n c t i o n s are a v a i l a b l e t o a c c e s s t h es t o r e d v a r i a b l e s : }
14
{ D i r e c t l y w r i t e a g l o b a l var . }16 procedure Wri teG loba lVar (cons t aName : s t r i n g ; cons t aValue
: V a r i a n t ) ;
18 { D i r e c t l y read a g l o b a l var . }f un c t i on ReadGlobalVar (cons t aName : s t r i n g ) : V a r i a n t ;
20
{ D i r e c t l y read a g l o b a l var , u s i n g a d e f a u l t v a l u e i fv a r i a b l e does no t e x i s t s . }
79
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
22 f un c t i on ReadGlobalVarDef (cons t aName : s t r i n g ; cons ta D e f a u l t : V a r i a n t ) : V a r i a n t ;
24 { R e s e t s a l l g l o b a l va rs . }procedure CleanupGloba lVars ;
26
{ Save c u r r e n t g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }28 f un c t i on SaveG loba lVa rsToS t r i ng :s t r i n g ;
30 { Load g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }procedure LoadGloba lVarsFromSt r ing (cons t s r c S t r i n g : s t r i n g )
;32
{ Save c u r r e n t g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }34 f un c t i on SaveGloba lVa rsToF i l e (cons t des tF i leName : s t r i n g ) :
Boolean ;
36 { Load g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }f un c t i on LoadGloba lVarsFromFi le (cons t srcF i leName : s t r i n g )
: Boolean ;38
{ Save c u r r e n t g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }40 procedure SaveGloba lVarsToSt ream ( d e s t S t r e a m : TStream ) ;
42 { Load g l o b a l va rs and t h e i r v a l u e s t o a f i l e . }procedure LoadGlobalVarsFromStream ( s r c S t r e a m : TStream ) ;
80
Rel
ease
Can
dida
te2
3.2. Internal Functions
3.2.7.1. GVar Utilities - DWS IIReference
ReadGlobalVar
Returns the value of the global variablen.This function returns an empty variant, if the
variable can not be found.
Declaration
function ReadGlobalVar(n: String): Vari-ant;
ReadGlobalVarDef
Similar to ReadGlobalVar, except thatd is givenback in case the variable specified by n couldnot be found.
Declaration
function ReadGlobalVarDef(n: String; d: Vari-ant): Variant;
WriteGlobalVar
Assigns value of v to the global variable namedn.
WriteGlobalVar creates a new global vari-able (with namen), if it can not find an existingglobal variable with the name specified by n.
Declaration
procedureWriteGlobalVar(n: String; v: Vari-ant);
CleanupGlobalVars
Deletes and frees all global variables.
Declaration
procedureCleanupGlobalVars;
81
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
3.3. Strings Unit
AT
TE
NT
ION
Dws2StringsUnit demands that TDelphiWebScriptII’s resulttype is set todws2StringResultType!In other words: To use this component, you also have to drop the “RESstr” labeleddws2StringResultTypecomponent onto the form that containsthe TDelphiWebScriptII componentand you have to set theTDelphiWeb-ScriptII.Config.ResultTypeproperty to thedws2StringResultTypecompo-nent.
Listing 3.9:Strings Unit: Functions
procedure Tdws2St r i ngsUn i t . AddUnitSymbols ( SymbolTable :TSymbolTable ) ;
2 varemptyArg : array o f s t r i n g ;
4 beginTWr i teFunc t i on . C r e a t e ( SymbolTable ,’WriteStr’ , [ ’Str’ ,
SYS_VARIANT ] , ’’ ) ;6 TWr i teLnFunct ion . C r e a t e ( SymbolTable ,’WriteLn’ , [ ’Str’ ,
SYS_VARIANT ] , ’’ ) ;TWr i t eA l l Func t i on . C r e a t e ( SymbolTable ,’WriteAll’ , [ ’Str’
, SYS_VARIANT ] , ’’ ) ;8 SetLeng th ( emptyArg , 0 ) ;
TReadCharFunct ion . C r e a t e ( SymbolTable ,’ReadChar’ ,emptyArg , SYS_STRING ) ;
10 TReadLnFunct ion . C r e a t e ( SymbolTable ,’ReadLn’ , emptyArg ,SYS_STRING) ;
TReadAl lFunc t ion . C r e a t e ( SymbolTable ,’ReadAll’ , emptyArg, SYS_STRING) ;
12 end ;
The string unit introduces following procedures:
• WriteStr( Str: Variant);
• WriteLn( Str: Variant);
82
Rel
ease
Can
dida
te2
3.4. Classes Library
• WriteAll( Str: Variant);
Additionally following functions are available:
• ReadChar: String;
• ReadLn: String;
• ReadAll: String;
3.4. Classes Library
The classes library defines wrappers for commonly used Delphi classes. Listing 3.10 showsall types that are defined by this library.
NO
TE The listing below was created with the help of thedws2UnitEditor. You
can find this utility in thedws2tools/UnitCompEditormodule.Note: This component is still in development, thus not 100% stable.
Listing 3.10:Standard Library: Classes Library
{ Forward D e c l a r a t i o n s }2 type T S t r i n g L i s t = c l a s s;
4 { C o n s t a n t s }cons t dupAccept : I n t e g e r = 2 ;
6 cons t dupEr ro r : I n t e g e r = 1 ;cons t dup Ignore : I n t e g e r = 0 ;
8
{ C l a s s e s }10 type
T L i s t = c l a s s( TObject )12 cons t ruc to r C r e a t e ;
f un c t i on Add ( Obj : TObjec t ) : I n t e g e r ;14 procedure C l e a r ;
f un c t i on Count : I n t e g e r ;16 procedure De le te( Index : I n t e g e r ) ;
d e s t r u c t o r Des t roy ; ove r r i de ;18 f un c t i on Get I tems (Index : I n t e g e r ) : TObject ;
f un c t i on IndexOf ( Obj : TObject ) : I n t e g e r ;
83
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
20 procedure I n s e r t ( Index : I n t e g e r ; Obj : TObject ) ;f un c t i on Remove ( Obj : TObject ) : I n t e g e r ;
22 procedure S e t I t e m s (Index : I n t e g e r ; Value : TObject ) ;proper ty I t ems [ x : I n t e g e r ] : TObjec t read Get I tems
wr i te S e t I t e m s ; d e f a u l t ;24 end ;
26 typeT S t r i n g s = c l a s s( TObject )
28 cons t ruc to r C r e a t e ;f un c t i on Add ( Str : St r i ng ) : I n t e g e r ;
30 f un c t i on AddObject ( S : St r i ng ; AObject : TObject ) :I n t e g e r ;
procedure AddSt r i ngs ( S t r i n g s : T S t r i n g L i s t ) ;32 procedure C l e a r ;
procedure De le te( Index : I n t e g e r ) ;34 d e s t r u c t o r Des t roy ; ove r r i de ;
procedure Exchange ( Index1 : I n t e g e r ; Index2 : I n t e g e r ) ;36 f un c t i on Get (Index : I n t e g e r ) : St r i ng ;
f un c t i on GetCommaText : St r i ng ;38 f un c t i on GetCount : I n t e g e r ;
f un c t i on GetNames ( s : St r i ng ) : St r i ng ;40 f un c t i on GetOb jec t s (Index : I n t e g e r ) : TObject ;
f un c t i on G e t S t r i n g s (Index : I n t e g e r ) : St r i ng ;42 f un c t i on GetText : St r i ng ;
f un c t i on GetValues (Str : St r i ng ) : St r i ng ;44 f un c t i on IndexOf (Str : St r i ng ) : I n t e g e r ;
f un c t i on IndexOfName (Str : St r i ng ) : I n t e g e r ;46 f un c t i on I ndexOfOb jec t ( AObject : TObjec t ) : I n t e g e r ;
procedure I n s e r t ( Index : I n t e g e r ; Str : St r i ng ) ;48 procedure I n s e r t O b j e c t (Index : I n t e g e r ; S : St r i ng ;
AObject : TObject ) ;procedure LoadFromFi le ( Fi leName : St r i ng ) ;
50 procedure Move( Cur Index : I n t e g e r ; NewIndex : I n t e g e r ) ;procedure SaveToF i le ( Fi leName :St r i ng ) ;
52 procedure SetCommaText ( Value :St r i ng ) ;procedure S e t O b j e c t s (Index : I n t e g e r ; Value : TObject ) ;
54 procedure S e t S t r i n g s (Index : I n t e g e r ; Value : St r i ng ) ;procedure Se tTex t ( Value : St r i ng ) ;
56 procedure Se tVa lues (Str : St r i ng ; Value : St r i ng ) ;proper ty CommaText : St r i ng read GetCommaText wr i te
SetCommaText ;58 proper ty Count : I n t e g e r read GetCount ;
proper ty Names [ s : St r i ng ] : St r i ng read GetNames ;60 proper ty O b j e c t s [ x : I n t e g e r ] : TObjectread GetOb jec t s
wr i te S e t O b j e c t s ;proper ty S t r i n g s [ x : I n t e g e r ] : St r i ng read G e t S t r i n g s
wr i te S e t S t r i n g s ; d e f a u l t ;62 proper ty Text : St r i ng read GetText wr i te Se tTex t ;
84
Rel
ease
Can
dida
te2
3.4. Classes Library
proper ty Values [ s : St r i ng ] : St r i ng read GetVa lueswr i te Se tVa lues ;
64 end ;
66 typeT S t r i n g L i s t = c l a s s( T S t r i n g s )
68 f un c t i on Find ( S : St r i ng ; var Index : I n t e g e r ) :Boolean ;
f un c t i on G e t D u p l i c a t e s : I n t e g e r ;70 f un c t i on GetSor ted : Boolean ;
procedure S e t D u p l i c a t e s ( Value : I n t e g e r ) ;72 procedure S e t S o r t e d ( Value : Boolean ) ;
procedure S o r t ;74 proper ty D u p l i c a t e s : I n t e g e r read G e t D u p l i c a t e s wr i te
S e t D u p l i c a t e s ;proper ty S o r t e d : Boolean read GetSor ted wr i te S e t S o r t e d
;76 end ;
78 typeTHash tab le = c l a s s( TObject )
80 f un c t i on Ca pac i t y : I n t e g e r ;procedure C l e a r ;
82 f un c t i on S ize : I n t e g e r ;end ;
84
type86 T I n t e g e r H a s h t a b l e =c l a s s( THash tab le )
cons t ruc to r C r e a t e ;88 d e s t r u c t o r Des t roy ; ove r r i de ;
f un c t i on Get ( Key : I n t e g e r ) : TObject ;90 f un c t i on HasKey ( Key : I n t e g e r ) : Boolean ;
procedure Put ( Key : I n t e g e r ; Value : TObjec t ) ;92 f un c t i on RemoveKey ( Key : I n t e g e r ) : TObject ;
end ;94
type96 T S t r i n g H a s h t a b l e =c l a s s( THash tab le )
cons t ruc to r C r e a t e ;98 d e s t r u c t o r Des t roy ; ove r r i de ;
f un c t i on Get ( Key : St r i ng ) : TObject ;100 f un c t i on HasKey ( Key : St r i ng ) : Boolean ;
procedure Put ( Key : St r i ng ; Value : TObject ) ;102 f un c t i on RemoveKey ( Key : St r i ng ) : TObject ;
end ;104
type106 TStack = c l a s s( TObject )
cons t ruc to r C r e a t e ;
85
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
108 f un c t i on Count : I n t e g e r ;d e s t r u c t o r Des t roy ; ove r r i de ;
110 f un c t i on Peek : TObject ;f un c t i on Pop : TObject ;
112 procedure Push ( Obj : TObject ) ;end ;
114
type116 TQueue = c l a s s( TObject )
cons t ruc to r C r e a t e ;118 f un c t i on Count : I n t e g e r ;
d e s t r u c t o r Des t roy ; ove r r i de ;120 f un c t i on Peek : TObject ;
f un c t i on Pop : TObject ;122 procedure Push ( Obj : TObject ) ;
end ;
We won’t cover most of the types and methods here, because they are commonly used inDelphi and rely on the behavior of the equivalent native Delphi classes. Please consult yourDelphi help, if you have questions regarding these types.
THashTable, TIntegerHashTableandTStringHashTableprovide script access to the types de-fined in thedws2HashtablesDWS II Delphi unit. You can find this file in the “Source” directoryof your DWS II installation.
THashTable
THashTable is the base class for all DWS II HashTable classes.Following methods are defined:
function Size: Integer;Returns the number of stored items.
function Capacity: Integer;Returns the number of items that may be stored without having to re-allocate memory.
procedureClear;Clears the HashTable.
TIntegerHashTable
Derived from THashTable, TIntegerHashTable can store any kind of objects that use an integervalue as hash key.
All methods should be self explanatory, so we do not cover them here.
TStringHashTable
Use TStringHashTable to store objects that have strings as hash keys.
86
Rel
ease
Can
dida
te2
3.5. Database Libraries (IBX, IBO)
3.5. Database Libraries (IBX, IBO)
Especially for web applications it is crucial to have fast, reliable and flexible access to databases.The IBX and IBO Libraries shipping with DWS II implement several features that enable DWSII to fulfill this demand.
NO
TE
Consider the functionality IBXLib offers as DWS II database connectivitystandard.The IBO Library sticks to that standard, so whenever you are reading“IBX” here, you can think of “IBX and IBO”.
3.5.1. dws2IBXDataBase, dws2IBODataBase
Component to add more TIB_Connections if you use more than one database. DWS Queriesand Statements can be created with database as parameter.
3.5.2. dws2IBXDataSrc, dws2IBODataSrc
Component to add a predefined TIB_Query, TIB_Cursor or TIB_Statement as script object thatcan be used in the script without creation or prepare.
3.5.3. dws2IBXLib, dws2IBOLib
Listing 3.11:Standard Library: IBX / IBO Library
{ Forward D e c l a r a t i o n s }2 type TDatase t = c l a s s;
4 { C l a s s e s }type
6 TDatabase = c l a s s( TObject )cons t ruc to r c r e a t e ( d a t a b a s e :St r i ng ; u s e r : St r i ng ;
pwd : St r i ng ) ;
87
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
8 procedure connec t ;procedure d i s c o n n e c t ;
10 f un c t i on g e t c h a r s e t : St r i ng ;f un c t i on g e t d i a l e c t : I n t e g e r ;
12 procedure s e t c h a r s e t ( s C h a r s e t :St r i ng ) ;procedure s e t d i a l e c t ( i D i a l e c t : I n t e g e r ) ;
14 proper ty c h a r s e t : St r i ng read g e t c h a r s e t wr i tes e t c h a r s e t ;
proper ty d i a l e c t : I n t e g e r read g e t d i a l e c t wr i tes e t d i a l e c t ;
16 end ;
18 typeTCustomDBField = c l a s s( TObject )
20 f un c t i on GetValue : V a r i a n t ; v i r t u a l ;f un c t i on GetVa lueS t r : St r i ng ; v i r t u a l ;
22 procedure SetVa lue ( Value : V a r i a n t ) ;v i r t u a l ;procedure S e t V a l u e S t r ( Value : St r i ng ) ; v i r t u a l ;
24 proper ty AsS t r i ng : St r i ng read GetVa lueS t r wr i teS e t V a l u e S t r ;
end ;26
type28 TDBField = c l a s s( TCustomDBField )
f un c t i on GetDateTime : DateTime ;30 f un c t i on G e t F l o a t : F l o a t ;
f un c t i on G e t I n t e g e r : I n t e g e r ;32 procedure SetDateTime ( Value : DateTime ) ;
procedure S e t F l o a t ( Value : F l o a t ) ;34 procedure S e t I n t e g e r ( Value : I n t e g e r ) ;
proper ty AsDateTime : DateTimeread GetDateTime wr i teSetDateTime ;
36 proper ty AsF loa t : F l o a t read G e t F l o a t wr i te S e t F l o a t ;proper ty A s I n t e g e r : I n t e g e r read G e t I n t e g e r wr i te
S e t I n t e g e r ;38 proper ty AsS t r i ng : St r i ng read GetVa lueS t r wr i te
S e t V a l u e S t r ;proper ty Value : V a r i a n t read GetValue wr i te SetVa lue ;
40 end ;
42 typeTLUField = c l a s s( TCustomDBField )
44 f un c t i on GetDateTime : DateTime ;f un c t i on G e t F l o a t : F l o a t ;
46 f un c t i on G e t I n t e g e r : I n t e g e r ;f un c t i on GetValue : V a r i a n t ; ove r r i de ;
48 f un c t i on GetVa lueS t r : St r i ng ; ove r r i de ;procedure SetDateTime ( Value : DateTime ) ;
50 procedure S e t F l o a t ( Value : F l o a t ) ;
88
Rel
ease
Can
dida
te2
3.5. Database Libraries (IBX, IBO)
procedure S e t I n t e g e r ( Value : I n t e g e r ) ;52 procedure SetVa lue ( Value : V a r i a n t ) ;ove r r i de ;
procedure S e t V a l u e S t r ( Value : St r i ng ) ; ove r r i de ;54 proper ty AsDateTime : DateTimeread GetDateTime wr i te
SetDateTime ;proper ty AsF loa t : F l o a t read G e t F l o a t wr i te S e t F l o a t ;
56 proper ty A s I n t e g e r : I n t e g e r read G e t I n t e g e r wr i teS e t I n t e g e r ;
proper ty AsS t r i ng : St r i ng read GetVa lueS t r wr i teS e t V a l u e S t r ;
58 proper ty Value : V a r i a n t read GetValue wr i te SetVa lue ;end ;
60
type62 TMLUField = c l a s s
cons t ruc to r c r e a t e ( Da taSe t : TDa tase t ; MLUFieldName :St r i ng ) ;
64 d e s t r u c t o r f r e e ;f un c t i on GetValue (Name : St r i ng ) : St r i ng ;
66 procedure SetNameValue (Name : St r i ng ; Value : St r i ng ) ;end ;
68
type70 TSta tement = c l a s s
cons t ruc to r C r e a t e ;72 cons t ruc to r CreateFromDB ( d a t a b a s e : TDatabase ) ;v i r t u a l
;procedure Execute ;
74 f un c t i on F i e l d ( FieldName : St r i ng ) : V a r i a n t ;f un c t i on FieldByName ( FieldName :St r i ng ) : TDBField ;
76 f un c t i on F i e l d I s N u l l ( FieldName : St r i ng ) : Boolean ;d e s t r u c t o r Free ;
78 f un c t i on GetSQL : St r i ng ;procedure Open ; v i r t u a l ;
80 f un c t i on ParamByName ( ParamName :St r i ng ) : TDBField ;procedure SetParam ( ParamName :St r i ng ; Value : V a r i a n t )
;82 procedure SetSQL ( sSQL : St r i ng ) ;
proper ty SQL : St r i ng read GetSQL wr i te SetSQL ;84 end ;
86 typeTDatase t = c l a s s( TSta tement )
88 cons t ruc to r C r e a t e ;cons t ruc to r CreateFromDB ( Database : TDatabase ) ;
ove r r i de ;90 procedure Cance l ;
procedure Close ;92 procedure De le te;
89
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
procedure E d i t ;94 f un c t i on Eof : Boolean ;
f un c t i on F i r s t : Boolean ;96 procedure I n s e r t ;
f un c t i on Next : Boolean ;98 procedure Open ; ove r r i de ;
procedure Pos t ;100 end ;
102 typeTQuery = c l a s s( TDa tase t )
104 cons t ruc to r C r e a t e ;cons t ruc to r CreateFromDB ( DataBase : TDatabase ) ;
ove r r i de ;106 f un c t i on G e t F i l t e r : St r i ng ;
f un c t i on G e t F i l t e r e d : Boolean ;108 f un c t i on GetSo r tOrde r : I n t e g e r ;
f un c t i on LookUp ( KeyF ie ldVa lue : St r i ng ) :TCustomDBField ;
110 f un c t i on P r i o r : Boolean ;procedure S e t F i l t e r ( F i l t e r S t r : St r i ng ) ;
112 procedure S e t F i l t e r e d ( F i l t e r e d : Boolean ) ;procedure SetLookUpFie lds ( KeyFieldName :St r i ng ;
LUfieldName : St r i ng ) ;114 procedure S e t S o r t O r d e r ( S o r t O r d e r : I n t e g e r ) ;
proper ty F i l t e r : St r i ng read G e t F i l t e r wr i te S e t F i l t e r ;116 proper ty F i l t e r e d : Boolean read G e t F i l t e r e d wr i te
S e t F i l t e r e d ;proper ty S o r t O r d e r : I n t e g e r read GetSo r tOrde r wr i te
S e t S o r t O r d e r ;118 end ;
120 typeTDataSetGrp = c l a s s
122 cons t ruc to r C r e a t e ( d a t a S e t : TDa tase t ; groupFie ldName: St r i ng ) ;
procedure AddRow ;124 procedure AddSumField ( FieldName :St r i ng ) ;
f un c t i on Changed : Boolean ;126 f un c t i on Count : I n t e g e r ;
d e s t r u c t o r Free ;128 procedure Reset;
procedure R e s t a r t ;130 f un c t i on SumOfField ( FieldName : St r i ng ) : F l o a t ;
end ;
90
Rel
ease
Can
dida
te2
3.5. Database Libraries (IBX, IBO)
• LookUpField : special for web apps - define a master-detail table relation, you can lookupdetails belonging to one master dataline (like with name=value in stringlists) when "name"field is string.
• MLUField : MemoLookUpField .. special for web apps - define a MemoField, you canlookup values with name=value from stringlist
• DataSetGrp : DataSetGroup, special for reports - if you iterate through a dataset you canuse DataSetGrp to watch changing of single field values, calculate group sums and totalsums (like all incomes listed per person and totals per person....).
TDataSetGrp
• .create(DataSet: TDataset; GroupFieldName: String);// DataSet should be prepared;!!
• .Free;
• .Changed: boolean;will be false while the content of the GroupField stays the same while iterating throughthis dataset
• .AddSumField(FieldName: String);after create, before start iterating, add all fieldnames of fields which should be added inthe group or total
• .SumOfField(FieldName: String): float;returns actual value of added field values. is set to 0 with "reset"
• .Count: integer;returns the number of datarecords in this group.
• .AddRow;adds values of all fields
• .Restart;reset values for a new group, DOES NOT RESET FIELD SUMS
• .Reset;reset values AND FIELD SUMS for a new group
Example:
Listing 3.12:Standard Library: IBX / IBO Library - DataSetGrp Example
{2 dws2IBO : TDataSetGrp Demo
}
91
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
4
var qAmounts : TDa tase t ;6 var grpEmployee : TDataSetGrp ;
qAmounts : = TDa tase t . C r e a t e ;8 qAmounts . SQL : = ’select * from empl_amounts’ ; / / wages o f
employeesqAmounts . open ;
10 grpEmployee : = TDataSetGrp . c r e a t e ( qAmounts ,’name’ ) ;grpEmployee . AddSumField (’amount’ ) ;
12 whi le not qAmounts .Eof dobegin
14 P r i n t (’name: ’ ) ;P r i n t L n ( qAmounts . F i e l d (’name’ ) ) ;
16 whi le not grpEmployee . changeddobegin
18 P r i n t ( qAmounts . F ie ldbyname (’bill_date’ ) . v a l u e ) ;P r i n t (’, ’ ) ;
20 P r i n t L n ( qAmounts . F i e l d (’amount’ ) ) ;grpEmployee . addrow ;
22 qAmounts . Next ;i : = i +1;
24 end ;P r i n t ( grpEmployee . coun t ) ;
26 P r i n t (’-----------, sum: ’ ) ;P r i n t L n ( grpEmployee . SumOfField (’amount’ ) ) ;
28 P r i n t l n (’’ ) ;grpEmployee .r e s e t ;
30 end ;
3.6. Fiber Library
The Fiber Library enables the use of control scripts that "pause". It was intended for OpenGL(GLScene) scripting, with arunall being called(between rendering) each 100 ms or so...
For further details, see the included demo. You can find it in the FiberLibrary directory.
Listing 3.13:Standard Library: Fiber
92
Rel
ease
Can
dida
te2
3.7. Ini Library
procedure FiberMessage ( MessageText :St r i ng ) ;2 f un c t i on GetF ibe rDa ta (Name: St r i ng ) : St r i ng ;
procedure Nex tF ibe r ( ) ;4 procedure S e t F i b e r D a t a (Name: St r i ng ; Value : St r i ng ) ;
3.7. Ini Library
Listing 3.14:Standard Library: Ini
{ C l a s s e s }2 type
T I n i F i l e = c l a s s4 cons t ruc to r C r e a t e ( Fi leName : St r i ng ) ;
procedure DeleteKey ( S e c t i o n : St r i ng ; I d e n t : St r i ng ) ;6 d e s t r u c t o r Des t roy ; ove r r i de ;
procedure E r a s e S e c t i o n ( S e c t i o n :St r i ng ) ;8 f un c t i on GetF i lename : St r i ng ;
f un c t i on ReadBool ( S e c t i o n : St r i ng ; I d e n t : St r i ng ;Defau l t : Boolean ) : Boolean ;
10 f un c t i on ReadDate ( S e c t i o n :St r i ng ; Name : St r i ng ;Defau l t : DateTime ) : DateTime ;
f un c t i on ReadDateTime ( S e c t i o n :St r i ng ; Name : St r i ng ;Defau l t : DateTime ) : DateTime ;
12 f un c t i on ReadF loa t ( S e c t i o n :St r i ng ; Name : St r i ng ;Defau l t : F l o a t ) : F l o a t ;
f un c t i on R e a d I n t e g e r ( S e c t i o n :St r i ng ; I d e n t : St r i ng ;Defau l t : I n t e g e r ) : I n t e g e r ;
14 procedure ReadSec t ion ( S e c t i o n :St r i ng ; S t r i n g s :T S t r i n g L i s t ) ;
procedure ReadSec t i ons ( S t r i n g s : T S t r i n g L i s t ) ;16 procedure ReadSec t i onVa lues ( S e c t i o n :St r i ng ; S t r i n g s
: T S t r i n g L i s t ) ;f un c t i on ReadS t r i ng ( S e c t i o n :St r i ng ; I d e n t : St r i ng ;
Defau l t : St r i ng ) : St r i ng ;18 f un c t i on ReadTime ( S e c t i o n :St r i ng ; Name : St r i ng ;
Defau l t : DateTime ) : DateTime ;f un c t i on S e c t i o n E x i s t s ( S e c t i o n :St r i ng ) : Boolean ;
93
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
20 procedure U p d a t e F i l e ;f un c t i on V a l u e E x i s t s ( S e c t i o n : St r i ng ; I d e n t : St r i ng )
: Boolean ;22 procedure Wri teBoo l ( S e c t i o n : St r i ng ; I d e n t : St r i ng ;
Value : Boolean ) ;procedure Wri teDate ( S e c t i o n : St r i ng ; Name : St r i ng ;
Value : DateTime ) ;24 procedure Wri teDateTime ( S e c t i o n : St r i ng ; Name : St r i ng
; Value : DateTime ) ;procedure W r i t e F l o a t ( S e c t i o n : St r i ng ; Name : St r i ng ;
Value : F l o a t ) ;26 procedure W r i t e I n t e g e r ( S e c t i o n : St r i ng ; I d e n t : St r i ng
; Value : I n t e g e r ) ;procedure W r i t e S t r i n g ( S e c t i o n : St r i ng ; I d e n t : St r i ng
; Value : St r i ng ) ;28 procedure WriteTime ( S e c t i o n : St r i ng ; Name : St r i ng ;
Value : DateTime ) ;proper ty Fi lename : St r i ng read GetF i lename ;
30 end ;
3.8. MF Library
There arelots of functions and constants defined in MF Library. Most of them, however, areonly meaningful on Windows.
We provide here a listing of all functions and constants defined by this Library! Don’t expectthem to be documented here - this would simply blow the 200 pages border...
MFLib also comes with some demos!
HIN
T Please use the documentation shipping with Delphi if you have questionsregarding one of the constants/functions/classes below!
94
Rel
ease
Can
dida
te2
3.8. MF Library
3.8.1. dws2MFLoader
This component enables you to load encrypted DWS II scripts.
3.8.2. Basic
3.8.2.1. Functions
Listing 3.15:Standard Library: MFLib - Basic
procedure Beep ; forward ;2 procedure Dec( var I : I n t e g e r ) ; forward ;
procedure Dec2 (var I : I n t e g e r ; N : I n t e g e r ) ; forward ;4 procedure Inc ( var I : I n t e g e r ) ; forward ;
procedure Inc2 (var I : I n t e g e r ; N : I n t e g e r ) ; forward ;6 f un c t i on GetTickCount : I n t e g e r ; forward ;
procedure Sleep ( mSecs : I n t e g e r ) ;forward ;8 procedure WriteLn ( Text : St r i ng ) ; forward ;
3.8.3. Connection
3.8.3.1. Functions
Listing 3.16:Standard Library: MFLib - Connection
{ F u n c t i o n s }2 f un c t i on Connected : Boolean ;forward ;
f un c t i on IPAddress : St r i ng ; forward ;
3.8.4. Dialog
3.8.4.1. Functions
Listing 3.17:Standard Library: MFLib - Dialog
f un c t i on S e l e c t S t r i n g D i a l o g ( T i t l e : St r i ng ; S t r i n g s :T S t r i n g L i s t ; S e l e c t e d : I n t e g e r ) : I n t e g e r ;
95
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
3.8.5. File
3.8.5.1. Constants
• DRIVE_UNKNOWN
• DRIVE_NO_ROOT_DIR
• DRIVE_REMOVABLE
• DRIVE_FIXED
• DRIVE_REMOTE
• DRIVE_CDROM
• DRIVE_RAMDISK
• FILEDATE_CREATION
• FILEDATE_LASTACCESS
• FILEDATE_LASTWRITE
• MOVEFILE_REPLACE_EXISTING
• MOVEFILE_COPY_ALLOWED
• MOVEFILE_DELAY_UNTIL_REBOOT
• MOVEFILE_WRITE_THROUGH
• MOVEFILE_CREATE_HARDLINK
• MOVEFILE_FAIL_IF_NOT_TRACKABLE
3.8.5.2. Functions
Listing 3.18:Standard Library: MFLib - File
f un c t i o n DescCopy ( Source , T a r g e t :St r i ng ) : Boolean ;2 f un c t i o n D e s c L i s t C r e a t e ( Di r : St r i ng ) : T S t r i n g L i s t ;
f un c t i o n DescL is tRead ( L i s t : T S t r i n g L i s t ; Fi leName :St r i ng ): St r i ng ;
96
Rel
ease
Can
dida
te2
3.8. MF Library
4 f un c t i on DescMove ( Source , T a r g e t :St r i ng ) : Boolean ;f un c t i on DescRead ( F i lename :St r i ng ) : St r i ng ;
6 f un c t i on DescWri te ( FileName , Desc :St r i ng ) : Boolean ;f un c t i on OpenDialog ( FileName , I n i t i a l D i r , T i t l e , De fau l tEx t
, F i l t e r : St r i ng ; F i l t e r I n d e x : I n t e g e r ) : St r i ng ;8 f un c t i on OpenDia logMul t i ( Fi leName , I n i t i a l D i r , T i t l e ,
De fau l tEx t , F i l t e r : St r i ng ; F i l t e r I n d e x : I n t e g e r ) :T S t r i n g L i s t ;
f un c t i on SaveDia log ( FileName , I n i t i a l D i r , T i t l e , De fau l tEx t, F i l t e r : St r i ng ; F i l t e r I n d e x : I n t e g e r ) : St r i ng ;
10 f un c t i on CDClose ( Dr ive : I n t e g e r ) : Boolean ;f un c t i on CDOpen ( Dr ive : I n t e g e r ) : Boolean ;
12 f un c t i on GetCRC32FromFile ( Fi leName :St r i ng ) : I n t e g e r ;f un c t i on GetDriveName ( Dr ive : I n t e g e r ) :St r i ng ;
14 f un c t i on GetDriveNum ( Dr ive : St r i ng ) : I n t e g e r ;f un c t i on GetDr iveReady ( Dr ive : I n t e g e r ) : Boolean ;
16 f un c t i on G e t D r i v e S e r i a l ( Dr ive : I n t e g e r ) :St r i ng ;f un c t i on GetDr iveType ( Dr ive : I n t e g e r ) : I n t e g e r ;
18 f un c t i on D i r e c t o r y E x i s t s ( DirName : St r i ng ) : Boolean ;f un c t i on D i r e c t o r y L i s t ( DirName : St r i ng ; Recurse , Hidden ) :
T S t r i n g L i s t ;20 f un c t i on CopyFi le ( Source , T a r g e t :St r i ng ; F a i l : Boolean ) :
Boolean ;f un c t i on F i l e D a t e ( Fi leName : St r i ng ; F lag : I n t e g e r ) :
DateTime ;22 f un c t i on F i l e L i s t ( Fi leName : St r i ng ; Recurse , Hidden , D i r s :
Boolean ) : T S t r i n g L i s t ;f un c t i on F i l e S i z e ( Fi leName : St r i ng ) : I n t e g e r ;
24 f un c t i on MakePath ( Dr ive , Dir , Name, Ext : St r i ng ) : St r i ng ;f un c t i on MoveFi le ( Source , T a r g e t :St r i ng ) : Boolean ;
26 f un c t i on MoveFileEx ( Source , T a r g e t :St r i ng ; F l a g s : I n t e g e r ): Boolean ;
f un c t i on ReadOnlyPath ( Pa th :St r i ng ) : Boolean ;28 procedure S p l i t P a t h ( Pa th : St r i ng ; var Drive , Dir , Name, Ext
: St r i ng ) ;f un c t i on S u b d i r e c t o r y E x i s t s ( Di r : St r i ng ) : Boolean ;
3.8.6. Info
3.8.6.1. Constants
• VER_UNKNOWN
• VER_WIN32S
• VER_WIN95
97
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
• VER_WIN98
• VER_WIN98SE
• VER_WINME
• VER_WINNT
• VER_WINNT4
• VER_WIN2000
3.8.6.2. Functions
Listing 3.19:Standard Library: MFLib - Info
f un c t i on G e t A l l U s e r s D e s k t o p D i r e c t o r y :St r i ng ;2 f un c t i on G e t A l l U s e r s P r o g r a m s D i r e c t o r y :St r i ng ;
f un c t i on G e t A l l U s e r s S t a r t m e n u D i r e c t o r y :St r i ng ;4 f un c t i on G e t A l l U s e r s S t a r t u p D i r e c t o r y :St r i ng ;
f un c t i on GetAppda taD i rec to r y : St r i ng ;6 f un c t i on GetCacheD i rec to ry :St r i ng ;
f un c t i on GetChannelFolderName :St r i ng ;8 f un c t i on GetCommonFi lesDi rec tory :St r i ng ;
f un c t i on GetComputerName :St r i ng ;10 f un c t i on G e t C o n s o l e T i t l e : St r i ng ;
f un c t i on G e t C o o k i e s D i r e c t o r y : St r i ng ;12 f un c t i on GetCPUSpeed :St r i ng ;
f un c t i on G e t D e s k t o p D i r e c t o r y : St r i ng ;14 f un c t i on GetDev icePath : St r i ng ;
f un c t i on GetEnv i ronmen tVa r i ab le :St r i ng ;16 f un c t i on G e t F a v o r i t e s D i r e c t o r y :St r i ng ;
f un c t i on G e t F o n t s D i r e c t o r y : St r i ng ;18 f un c t i on G e t H i s t o r y D i r e c t o r y : St r i ng ;
f un c t i on GetL ink fo lderName : St r i ng ;20 f un c t i on GetMediaPath : St r i ng ;
f un c t i on GetNe thoodD i rec to ry : St r i ng ;22 f un c t i on G e t P e r s o n a l D i r e c t o r y :St r i ng ;
f un c t i on GetPFAccessor iesName :St r i ng ;24 f un c t i on G e t P r i n t h o o d D i r e c t o r y : St r i ng ;
f un c t i on G e t P r o g r a m f i l e s D i r e c t o r y :St r i ng ;26 f un c t i on GetP rog ramsD i rec to r y :St r i ng ;
f un c t i on G e t R e c e n t D i r e c t o r y :St r i ng ;28 f un c t i on G e t S e n d t o D i r e c t o r y :St r i ng ;
f un c t i on GetSMAccessoriesName :St r i ng ;30 f un c t i on G e t S t a r t m e n u D i r e c t o r y :St r i ng ;
f un c t i on G e t S t a r t u p D i r e c t o r y : St r i ng ;32 f un c t i on GetSys temDi rec to r y :St r i ng ;
98
Rel
ease
Can
dida
te2
3.8. MF Library
f un c t i on GetTempDirec tory : St r i ng ;34 f un c t i on G e t T e m p l a t e s D i r e c t o r y :St r i ng ;
f un c t i on GetUserName : St r i ng ;36 f un c t i on GetVers ion : St r i ng ;
f un c t i on G e t W a l l p a p e r D i r e c t o r y : St r i ng ;38 f un c t i on GetWindowsDirec tory : St r i ng ;
f un c t i on GetWindowsVersion : St r i ng ;40 f un c t i on IsWin2000 : Boolean ;
f un c t i on IsWin9x : Boolean ;42 f un c t i on IsWinNT : Boolean ;
f un c t i on IsWinNT4 : Boolean ;44 f un c t i on SetComputerName :St r i ng ;
f un c t i on S e t C o n s o l e T i t l e : St r i ng ;
3.8.7. Registry
3.8.7.1. Constants
• HKEY_CLASSES_ROOT
• HKEY_CURRENT_USER
• HKEY_LOCAL_MACHINE
• HKEY_USERS
• HKEY_PERFORMANCE_DATA
• HKEY_CURRENT_CONFIG
• HKEY_DYN_DATA
3.8.7.2. Functions
Listing 3.20:Standard Library: MFLib - Registry
procedure RegCreateKey ( MainKey : I n t e g e r ; SubKey :St r i ng ) ;2 procedure RegDeleteKey ( MainKey : I n t e g e r ; SubKey :St r i ng ) ;
procedure RegDele teVa lue ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ) ;
4 f un c t i on RegReadIn teger ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ; ValDef : I n t e g e r ) : I n t e g e r ;
f un c t i on RegReadSt r ing ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ; ValDef : St r i ng ) : St r i ng ;
99
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
6 f un c t i on RegGetType ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ; var S ize : I n t e g e r ) : I n t e g e r ;
f un c t i on RegKeyExis ts ( MainKey : I n t e g e r ; SubKey :St r i ng ) :Boolean ;
8 f un c t i on RegVa lueEx is t s ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ) : Boolean ;
procedure R e g W r i t e I n t e g e r ( MainKey : I n t e g e r ; SubKey :St r i ng; ValName : St r i ng ; Value : I n t e g e r ) ;
10 procedure RegWr i t eS t r i ng ( MainKey : I n t e g e r ; SubKey :St r i ng ;ValName : St r i ng ; Value : St r i ng ) ;
3.8.8. Shell
3.8.8.1. Functions
Listing 3.21:Standard Library: MFLib - Shell
Desk topRe f resh ;
3.8.9. String
3.8.9.1. Constants
• cdrLeft
• cdrRight
3.8.9.2. Functions
Listing 3.22:Standard Library: MFLib - String
f un c t i on ANSI2OEM( S : St r i ng ) : St r i ng ;2 f un c t i on ChangeTokenValue ( S :St r i ng ; Name: St r i ng ; Value :
St r i ng ; D e l i m i t e r : St r i ng ) : St r i ng ;f un c t i on Chr ( Byte : I n t e g e r ) : St r i ng ;
4 f un c t i on CmpRE( S : St r i ng ; RE : St r i ng ) : Boolean ;f un c t i on CmpWC( S : St r i ng ; WC: St r i ng ; Case: Boolean ) :
Boolean ;
100
Rel
ease
Can
dida
te2
3.8. MF Library
6 f un c t i on Crop ( S : St r i ng ; Len : I n t e g e r ; D i r : I n t e g e r ;D e l i m i t e r : St r i ng )
f un c t i on ForEach ( L i s t : T S t r i n g L i s t ; Func :St r i ng ; F lag :I n t e g e r ) : Boolean ;
8 procedure FormatColumns ( L i s t : T S t r i n g L i s t ; D e l i m i t e r :St r i ng ; Space : St r i ng ; Ad jus tment : I n t e g e r ) ;
f un c t i on GetCRC32FromString ( S :St r i ng ) : I n t e g e r ;10 f un c t i on G e t S t r i n g F r o m L i s t ( L i s t : T S t r i n g L i s t ; D e l i m i t e r :
St r i ng ) : St r i ng ;f un c t i on GetTokenL is t ( S : St r i ng ; D e l i m i t e r : St r i ng ;
Re pe a t e r : Boolean ; I g n o r e F i r s t : Boolean ; I g n o r e L a s t :Boolean ) : T S t r i n g L i s t ;
12 f un c t i on IncWC ( S : St r i ng ; WC: St r i ng ; Case: Boolean ) :St r i ng ;
f un c t i on Num2Text (Num : I n t e g e r ) : St r i ng ;14 f un c t i on OEM2ANSI( S : St r i ng ) : St r i ng ;
f un c t i on Ord ( Char : St r i ng ) : I n t e g e r ;16 f un c t i on PosX ( SubSt r : St r i ng ; S : St r i ng ) : I n t e g e r ;
f un c t i on St r i ngOfCha r ( Ch : St r i ng ; Count : I n t e g e r ) : St r i ng ;18 f un c t i on TestWC ( S : St r i ng ) : I n t e g e r ;
f un c t i on T r a n s l a t e ( S : St r i ng ; Out : St r i ng ; In : St r i ng ;P l a c e : St r i ng ; Case: Boolean ) : St r i ng ;
3.8.10. System
3.8.10.1. Constants
• SW_HIDE
• SW_SHOWNORMAL
• SW_NORMAL
• SW_SHOWMINIMIZED
• SW_SHOWMAXIMIZED
• SW_MAXIMIZE
• SW_SHOWNOACTIVE
• SW_SHOW
• SW_MINIMIZE
• SW_SHOWMINNOACTIVE
101
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
• SW_SHOWNA
• SW_RESTORE
• SW_SHOWDEFAULT
• EWX_LOGOFF
• EWX_SHUTDOWN
• EWX_REBOOT
• EWX_FORCE
• EWX_POWEROFF
• EWX_FORCEIFHUNG
• Message-Constants for PostMessage() and SendMessage():
– WM_MOVE
– WM_SIZE
– WM_ACTIVATE
– WM_SETFOCUS
– WM_KILLFOCUS
– WM_ENABLE
– WM_CLOSE
– WM_QUIT
– WM_SHOWWINDOW
– WM_ACTIVATEAPP
– WM_SETCURSOR
– WM_MOUSEACTIVATE
– WM_CHILDACTIVATE
– WM_HELP
– WM_COMMAND
– WM_SYSCOMMAND
– WM_HSCROLL
– WM_VSCROLL
– WM_MOUSEMOVE
– WM_LBUTTONDOWN
– WM_LBUTTONUP
102
Rel
ease
Can
dida
te2
3.8. MF Library
– WM_LBUTTONDBLCLK
– WM_RBUTTONDOWN
– WM_RBUTTONUP
– WM_RBUTTONDBLCLK
– WM_MBUTTONDOWN
– WM_MBUTTONUP
– WM_MBUTTONDBLCLK
– WM_MOUSEWHEEL
– WM_MDITILE
– WM_MDICASCADE
– WM_CUT
– WM_COPY
– WM_PASTE
– WM_CLEAR
– WM_UNDO
– WM_USER
– BM_CLICK
– BM_GETCHECK
– BM_SETCHECK
– BST_CHECKED
– BST_INDETERMINATE
– BST_UNCHECKED
– CB_GETCOUNT
– CB_GETCURSEL
– CB_GETDROPPEDSTATE
– CB_GETEDITSEL
– CB_GETTOPINDEX
– CB_RESETCONTENT
– CB_SETCURSEL
– CB_SETEDITSEL
– CB_SETTOPINDEX
– CB_SHOWDROPDOWN
– EM_GETSEL
– EM_SETSEL
103
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
– EM_UNDO
– LB_GETCOUNT
– LB_GETCURSEL
– LB_GETSEL
– LB_GETSELCOUNT
– LB_GETTEXT
– LB_GETTEXTLEN
– LB_GETTOPINDEX
– LB_ITEMFROMPOINT
– LB_RESETCONTENT
– LB_SELITEMRANGE
– LB_SETCURSEL
– LB_SETSEL
– LB_SETTOPINDEX
– SB_BOTTOM
– SB_ENDSCROLL
– SB_LINEDOWN
– SB_LINEUP
– SB_PAGEDOWN
– SB_PAGEUP
– SB_THUMBPOSITION
– SB_THUMBTRACK
– SB_TOP
3.8.10.2. Functions
Listing 3.23:Standard Library: MFLib - System
f un c t i on S h e l l E x e c u t e ( O p e r a t i o n :St r i ng ; F i lename : St r i ng ;P a r a m e t e r s :St r i ng ; D i r e c t o r y : St r i ng ; ShowCmd : I n t e g e r ): I n t e g e r ;
2 f un c t i on S h e l l E x e c u t e W a i t ( F i lename :St r i ng ; P a r a m e t e r s :St r i ng ; D i r e c t o r y : St r i ng ; ShowCmd : I n t e g e r ) : Boolean ;
f un c t i on ExitWindowsEx ( F l a g s : I n t e g e r ) : I n t e g e r ;4 f un c t i on W r i t e M a i l s l o t ( Machine : St r i ng ; M a i l s l o t : St r i ng ;
Text : St r i ng ) : Boolean ;f un c t i on G e t P r o c e s s L i s t : T S t r i n g L i s t ;
6 f un c t i on HiWord ( Value : I n t e g e r ) : I n t e g e r ;
104
Rel
ease
Can
dida
te2
3.8. MF Library
f un c t i on I s F i l e A c t i v e ( Fi leName : St r i ng ) : Boolean ;8 f un c t i on K i l l P r o c e s s ( Window : I n t e g e r ; Fi leName :St r i ng ;
K i l l A l l : Boolean ) : Boolean ;f un c t i on LoWord ( Value : I n t e g e r ) : I n t e g e r ;
10 f un c t i on MakeLong (Low , High : I n t e g e r ) : I n t e g e r ;f un c t i on PostMessage ( Window , Msg , WParam , LParam : I n t e g e r )
: Boolean ;12 procedure SendKeys ( Keys : St r i ng ) ;
procedure SendKeysEx ( Keys :St r i ng ; Wait : I n t e g e r ) ;14 f un c t i on SendKeysNamedWin ( Window :St r i ng ; Keys : St r i ng ) :
I n t e g e r ;f un c t i on SendKeysNamedWinEx ( Window :St r i ng ; Keys : St r i ng ;
Wait : I n t e g e r ; Back : Boolean ) : I n t e g e r ;16 f un c t i on SendKeysWin ( Window : I n t e g e r ; Keys :St r i ng ) :
I n t e g e r ;f un c t i on SendKeysWinEx ( Window : I n t e g e r ; Keys :St r i ng ; Wait
: I n t e g e r ; Back : Boolean ) : I n t e g e r ;18 f un c t i on SendMessage ( Window , Msg , WParam , LParam : I n t e g e r )
: I n t e g e r ;
3.8.11. Window
3.8.11.1. Functions
Listing 3.24:Standard Library: MFLib - Window
f un c t i on FindWindow (Class : St r i ng ; Window : St r i ng ) : I n t e g e r;
2 f un c t i on FindWindowEx ( P a r e n t : I n t e g e r ; C h i l d A f t e r : I n t e g e r; Class : St r i ng ; Window : St r i ng ) : I n t e g e r ;
f un c t i on GetClassName ( Window : I n t e g e r ) :St r i ng ;4 f un c t i on GetWindowText ( Window : I n t e g e r ) :St r i ng ;
procedure HideTaskbar ;6 f un c t i on I s I c o n i c ( Window : I n t e g e r ) : Boolean ;
f un c t i on IsWindow ( Window : I n t e g e r ) : Boolean ;8 f un c t i on IsWindowEnabled ( Window : I n t e g e r ) : Boolean ;
f un c t i on I sWindowVis ib le ( Window : I n t e g e r ) : Boolean ;10 f un c t i on IsZoomed ( Window : I n t e g e r ) : Boolean ;
f un c t i on SearchWindow (var C lass ; var Window : St r i ng ; ProcID: I n t e g e r ) : I n t e g e r ;
12 f un c t i on SearchWindowEx ( P a r e n t : I n t e g e r ; C h i l d A f t e r :I n t e g e r ; var C lass ; var Window : St r i ng ; Num : I n t e g e r ) :I n t e g e r ;
procedure ShowTaskbar ;
105
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
14 f un c t i on WaitForWindow (var C lass ; var Window : St r i ng ;T imeout : I n t e g e r ; ProcID : I n t e g e r ) : I n t e g e r ;
f un c t i on WaitForWindowClose ( Window : I n t e g e r ; Timeout :I n t e g e r ) : Boolean ;
16 f un c t i on WaitForWindowClose (Class : St r i ng ; Window : St r i ng ;T imeout : I n t e g e r ; ProcID : I n t e g e r ) : Boolean ;
f un c t i on WaitForWindowEnabled ( Window : I n t e g e r ; Timeout :I n t e g e r ) : Boolean ;
18 f un c t i on WaitForWindowEnabled (Class : St r i ng ; Window : St r i ng; T imeout : I n t e g e r ; ProcID : I n t e g e r ) : Boolean ;
f un c t i on WaitForWindowEx ( P a r e n t : I n t e g e r ;var C lass ; varWindow : St r i ng ; T imeout : I n t e g e r ; Num : I n t e g e r ) : I n t e g e r;
20 procedure WindowMove ( Window : I n t e g e r ; X : I n t e g e r ; Y :I n t e g e r ; Abs : Boolean ) ;
procedure WindowResize ( Window : I n t e g e r ; X : I n t e g e r ; Y :I n t e g e r ; Abs : Boolean ) ;
3.8.12. dws2MFZipLib
3.8.12.1. Constants
• Zip_Add
• Zip_Move
• Zip_Update
• Zip_Freshen
• Zip_Extract
• Zip_Test
• Zip_OverwriteConfirm
• Zip_OverwriteAlways
• Zip_OverwriteNever
• Zip_EraseFinal
• Zip_EraseAllowUndo
106
Rel
ease
Can
dida
te2
3.8. MF Library
3.8.12.2. Classes
Listing 3.25:Standard Library: MFLib - Zip
{ C l a s s e s }2 type
TZip = c l a s s4 f un c t i on Add ( Ac t ion : I n t e g e r ; Z i p F i l e : St r i ng ;
Fi leName : St r i ng ) : I n t e g e r ;f un c t i on AddLis t ( Ac t ion : I n t e g e r ; Z i p F i l e : St r i ng ;
F i leNames : T S t r i n g L i s t ) : I n t e g e r ;6 cons t ruc to r C r e a t e ;
f un c t i on De le te( Z i p F i l e : St r i ng ; Fi leName : St r i ng ) :I n t e g e r ;
8 f un c t i on D e l e t e L i s t ( Z i p F i l e : St r i ng ; F i leNames :T S t r i n g L i s t ) : I n t e g e r ;
d e s t r u c t o r Des t roy ;10 f un c t i on E x t r a c t ( Ac t ion : I n t e g e r ; Z i p F i l e : St r i ng ;
Fi leName : St r i ng ; BaseDi r : St r i ng ) : I n t e g e r ;f un c t i on E x t r a c t L i s t ( Ac t ion : I n t e g e r ; Z i p F i l e : St r i ng
; F i leNames : T S t r i n g L i s t ; BaseDi r :St r i ng ) :I n t e g e r ;
12 f un c t i on L i s t ( Z i p F i l e : St r i ng ) : T S t r i n g L i s t ;f un c t i on Message ( Z i p F i l e : St r i ng ) : St r i ng ;
14 f un c t i on ReadAddCompLevel : I n t e g e r ;f un c t i on ReadAddDirNames : Boolean ;
16 f un c t i on ReadAddDiskSpan : Boolean ;f un c t i on ReadAddDiskSpanErase : Boolean ;
18 f un c t i on ReadAddEncrypt : Boolean ;f un c t i on ReadAddHiddenFi les : Boolean ;
20 f un c t i on ReadAddRecurseDirs : Boolean ;f un c t i on ReadAddSepara teD i rs : Boolean ;
22 f un c t i on ReadAddZipTime : Boolean ;f un c t i on ReadConf i rmErase : Boolean ;
24 f un c t i on ReadExtrDirNames : Boolean ;f un c t i on ReadEx t rOverwr i t e : Boolean ;
26 f un c t i on ReadHowToDelete : I n t e g e r ;f un c t i on ReadKeepFreeOnDisk1 : I n t e g e r ;
28 f un c t i on ReadMaxVolumeSize : I n t e g e r ;f un c t i on ReadMinFreeVolumeSize : I n t e g e r ;
30 f un c t i on ReadPassword :St r i ng ;f un c t i on ReadSFXAskCmdLine : Boolean ;
32 f un c t i on ReadSFXAskFi les : Boolean ;f un c t i on ReadSFXCaption : St r i ng ;
34 f un c t i on ReadSFXCommandLine :St r i ng ;f un c t i on ReadSFXDefaul tDi r : St r i ng ;
36 f un c t i on ReadSFXHideOverwri teBox : Boolean ;f un c t i on ReadSFXOverwriteMode : I n t e g e r ;
107
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
38 f un c t i on ReadSpan ( Sp anF i l e :St r i ng ; var Z i p F i l e :St r i ng ) : I n t e g e r ;
f un c t i on ReadTemp : St r i ng ;40 f un c t i on SFX2ZIP ( Z i p F i l e : St r i ng ) : I n t e g e r ;
procedure WriteAddCompLevel ( Value : I n t e g e r ) ;42 procedure WriteAddDirNames ( Value : Boolean ) ;
procedure WriteAddDiskSpan ( Value : Boolean ) ;44 procedure Wri teAddDiskSpanErase ( Value : Boolean ) ;
procedure Wri teAddEncrypt ( Value : Boolean ) ;46 procedure Wri teAddHiddenF i les ( Value : Boolean ) ;
procedure Wri teAddRecurseDi rs ( Value : Boolean ) ;48 procedure Wr i teAddSepa ra teD i r s ( Value : Boolean ) ;
procedure WriteAddZipTime ( Value : Boolean ) ;50 procedure Wri teCon f i rmErase ( Value : Boolean ) ;
procedure Wri teExt rD i rNames ( Value : Boolean ) ;52 procedure W r i t e E x t r O v e r w r i t e ( Value : Boolean ) ;
procedure WriteHowToDelete ( Value : I n t e g e r ) ;54 procedure WriteKeepFreeOnDisk1 ( Value : I n t e g e r ) ;
procedure WriteMaxVolumeSize ( Value : I n t e g e r ) ;56 procedure Wri teMinFreeVolumeSize ( Value : I n t e g e r ) ;
procedure Wri tePassword ( Value :St r i ng ) ;58 procedure WriteSFXAskCmdLine ( Value : Boolean ) ;
procedure Wri teSFXAskFi les ( Value : Boolean ) ;60 procedure Wri teSFXCapt ion ( Value : St r i ng ) ;
procedure WriteSFXCommandLine ( Value :St r i ng ) ;62 procedure Wri teSFXDefau l tD i r ( Value : St r i ng ) ;
procedure WriteSFXHideOverwr i teBox ( Value : Boolean ) ;64 procedure WriteSFXOverwri teMode ( Value : I n t e g e r ) ;
f un c t i on Wri teSpan ( Z i p F i l e : St r i ng ; Sp anF i l e : St r i ng ): I n t e g e r ;
66 procedure WriteTemp ( Value : St r i ng ) ;f un c t i on ZIP2SFX ( Z i p F i l e : St r i ng ) : I n t e g e r ;
68 proper ty AddCompLevel : I n t e g e r read ReadAddCompLevelwr i te WriteAddCompLevel ;
proper ty AddDirNames : Booleanread ReadAddDirNameswr i te WriteAddDirNames ;
70 proper ty AddDiskSpan : Booleanread ReadAddDiskSpanwr i te WriteAddDiskSpan ;
proper ty AddDiskSpanErase : BooleanreadReadAddDiskSpanErasewr i te Wri teAddDiskSpanErase ;
72 proper ty AddEncrypt : Boolean read ReadAddEncrypt wr i teWri teAddEncrypt ;
proper ty AddHiddenFi les : BooleanreadReadAddHiddenFi leswr i te Wri teAddHiddenF i les ;
74 proper ty AddRecurseDi rs : BooleanreadReadAddRecurseDirswr i te Wri teAddRecurseDi rs ;
proper ty AddSepara teD i r s : BooleanreadReadAddSepara teD i rswr i te Wr i teAddSepa ra teD i r s ;
108
Rel
ease
Can
dida
te2
3.9. Symbols Library
76 proper ty AddZipTime : Boolean read ReadAddZipTime wr i teWriteAddZipTime ;
proper ty Conf i rmErase : Booleanread ReadConf i rmErasewr i te Wri teCon f i rmErase ;
78 proper ty ExtrDirNames : Booleanread ReadExtrDirNameswr i te Wri teExt rD i rNames ;
proper ty E x t r O v e r w r i t e : Boolean read ReadEx t rOverwr i t ewr i te W r i t e E x t r O v e r w r i t e ;
80 proper ty HowToDelete : I n t e g e r read ReadHowToDeletewr i te WriteHowToDelete ;
proper ty KeepFreeOnDisk1 : I n t e g e rreadReadKeepFreeOnDisk1wr i te WriteKeepFreeOnDisk1 ;
82 proper ty MaxVolumeSize : I n t e g e r read ReadMaxVolumeSizewr i te WriteMaxVolumeSize ;
proper ty MinFreeVolumeSize : I n t e g e rreadReadMinFreeVolumeSizewr i te Wri teMinFreeVolumeSize ;
84 proper ty Password : St r i ng read ReadPasswordwr i teWri tePassword ;
proper ty SFXAskCmdLine : Booleanread ReadSFXAskCmdLinewr i te WriteSFXAskCmdLine ;
86 proper ty SFXAskFi les : Boolean read ReadSFXAskFi leswr i te Wri teSFXAskFi les ;
proper ty SFXCaption : St r i ng read ReadSFXCaptionwr i teWri teSFXCapt ion ;
88 proper ty SFXCommandLine : St r i ng read ReadSFXCommandLinewr i te WriteSFXCommandLine ;
proper ty SFXDefau l tD i r : St r i ng read ReadSFXDefaul tDi rwr i te Wri teSFXDefau l tD i r ;
90 proper ty SFXHideOverwri teBox : BooleanreadReadSFXHideOverwri teBoxwr i teWriteSFXHideOverwr i teBox ;
proper ty SFXOverwriteMode : I n t e g e rreadReadSFXOverwriteModewr i te WriteSFXOverwri teMode ;
92 proper ty Temp : St r i ng read ReadTemp wr i te WriteTemp ;end ;
3.9. Symbols Library
Listing 3.26:Standard Library: Symbols
109
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
{ Forward D e c l a r a t i o n s }2 type TSymbols = c l a s s;
4 { Enumera t ions }type TSymbolType = ( stUnknown , s tA r ray , s t A l i a s , s t C l a s s ,
s t C o n s t a n t , s t F i e l d , s t F u n c t i o n , stMember , s tParam ,s t P r o p e r t y , s tRecord , s t U n i t , s t V a r i a b l e ) ;
6
{ C l a s s e s }8 type
TSymbols = c l a s s10 cons t ruc to r CreateMain ;
cons t ruc to r Crea teU id ( Uid : St r i ng ) ;12 cons t ruc to r C r e a t e U n i t (Name : St r i ng ) ;
f un c t i on Capt ion : St r i ng ;14 f un c t i on D e s c r i p t i o n : St r i ng ;
d e s t r u c t o r Des t roy ; ove r r i de ;16 f un c t i on Eof : Boolean ;
procedure F i r s t ;18 f un c t i on GetMembers : TSymbols ;
f un c t i on GetPa rame te rs : TSymbols ;20 f un c t i on GetSuperC lass : TSymbols ;
procedure Las t ;22 f un c t i on Loca te (Name : St r i ng ) : Boolean ;
f un c t i on Name : St r i ng ;24 procedure Next ;
procedure P r e v i o u s ;26 f un c t i on SymbolType : TSymbolType ;
end ;
3.10. Web Library
The DWS2-Web-Library brings you 3 components for building web applications with DWS2and 1 for desktop script handling (e.g. in reports...), namelydws2Pageloader.
110
Rel
ease
Can
dida
te2
3.10. Web Library
NO
TE
The Web Library has the ability to automatically check access to a webscript. This is accomplished by special naming of the script files:
_S<name>.dws means that a user must have a valid user session to beable to access the script
_L<name>.dws means that a user must have a valid Login state to ac-cess the script
_M<name>.dws same as _L<name>.dws, but disallows access withGUEST login state.
3.10.1. dws2PageProducer
Thedws2PageProduceris based on CustomContentProducer, with standard interface to be calledby webactions and return content from scriptfiles.
3.10.2. dws2PageLoader
This component is similar to thedws2PageProducerbut without interface to webbroker.
3.10.3. dws2SessionLib
Dws2SessionLibprovides HTTP - usertracking and the ability to store sessiondata.
HIN
T
You can find avery simple Session Tracking Serverin the dws2\-Libraries\WebLib\SimpleSessionServerdirectory. It’s a CLX based demothat shows how you can add external session tracking to DWS II enabledCGI executables.In normal operational mode,dws2SessionLibdoes aninternal user ses-sion tracking. This technique only works in ISAPI modules, because themodule is loaded once and if a request hits the module, just a new threadis created that has access to a global internal session list.If you plan to use DWS II enabled CGI executables and you need sessiontracking, then you need to install an external Session Tracking Server, asthe CGI executable terminates after each web-request, thereby clearingthe global session list.
Listing 3.27:Standard Library: WebLib - SessionLib
111
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
{ C o n s t a n t s }2 cons t dwsta teGLI : I n t e g e r = 1 ;
cons t dwstateLOFF : I n t e g e r =−1;4 cons t dwstateNAT : I n t e g e r = 1 2 ;
cons t dwsta teNLI : I n t e g e r = 0 ;6 cons t dwstatePRF : I n t e g e r = 9 ;
cons t dwstateSU : I n t e g e r = 1 0 0 ;8 cons t dwstateTOUT : i n t e g e r =−2;
cons t dwsta teULI : I n t e g e r = 1 0 ;10 cons t dwsta teVIP : I n t e g e r = 2 0 ;
cons t Vers ion : St r i ng = ’2.1.2001.6.20’ ;12
{ C l a s s e s }14 type
S e s s i o n = c l a s s( TObject )16 c l a s s f unc t i on GetAc t i veUse rs : I n t e g e r ;
c l a s s f unc t i on GetCSta te : I n t e g e r ;18 c l a s s f unc t i on GetIpAddr : St r i ng ;
c l a s s f unc t i on GetSBrand : St r i ng ;20 c l a s s f unc t i on GetTLas tAc t ion : DateTime ;
c l a s s f unc t i on GetTLogin : DateTime ;22 c l a s s f unc t i on Param (Name : s t r i n g ) : v a r i a n t ;
c l a s s procedure S e t C S t a t e ( Value : I n t e g e r ) ;24 c l a s s procedure Set IpAddr ( Value : St r i ng ) ;
c l a s s procedure SetSBrand ( Value : St r i ng ) ;26 c l a s s procedure Se tTLas tAc t i on ( Value : DateTime ) ;
c l a s s procedure SetTLogin ( Value : DateTime ) ;28 c l a s s procedure S t o r e (name : s t r i n g ; v a l u e : v a r i a n t ) ;
proper ty Ac t i veUs e rs : I n t e g e r read GetAc t i veUse rs ;30 proper ty C l i e n t S t a t e : I n t e g e r read GetCSta te wr i te
S e t C S t a t e ;proper ty IpAddr : St r i ng read GetIpAddr wr i te Set IpAddr ;
32 proper ty SBrand : St r i ng read GetSbrand wr i te SetSbrand ;proper ty TLas tAc t ion : DateTime read GetTLas tAc t ion
wr i te Se tTLas tAc t i on ;34 proper ty TLogin : DateTime read GetT log in wr i te
S e t T l o g i n ;end ;
36
{ F u n c t i o n s }38 f un c t i on TIDfunc : St r i ng ; forward ;
f un c t i on A c t i v e S e s s i o n : boo lean ;forward ;40 f un c t i on URL(AnURL : St r i ng ) : St r i ng ; forward ;
112
Rel
ease
Can
dida
te2
3.10. Web Library
3.10.4. dws2WebLib
Dws2WebLibintroduces some classes to handle the ISAPI calls of Borland’s webbroker (request,response, cookie), the scriptdoc class to store information about the scriptfile, and TFormVar-Group to handle multiple input fields of database tables in html forms. There are also some"functions" useful for webapps.
Listing 3.28:Standard Library: WebLib
{ Forward D e c l a r a t i o n s }2 type TCookie = c l a s s;
4 { C l a s s e s }type
6 Reques t = c l a s s( TObject )c l a s s f unc t i on Accept : St r i ng ;
8 c l a s s f unc t i on A u t h o r i z a t i o n : s t r i n g ;c l a s s f unc t i on Conten t : St r i ng ;
10 c l a s s f unc t i on Conten tLeng th : I n t e g e r ;c l a s s f unc t i on ContentType : St r i ng ;
12 c l a s s f unc t i on Cookie (Name : St r i ng ) : St r i ng ;c l a s s f unc t i on CookieCount : I n t e g e r ;
14 c l a s s f unc t i on CookieName (Index : I n t e g e r ) : St r i ng ;c l a s s f unc t i on CookieValue (Index : I n t e g e r ) : St r i ng ;
16 c l a s s f unc t i on Date : DateTime ;c l a s s f unc t i on From : St r i ng ;
18 c l a s s f unc t i on Host : St r i ng ;c l a s s f unc t i on LogContent : St r i ng ;
20 c l a s s f unc t i on Method : St r i ng ;c l a s s f unc t i on Param (Name : St r i ng ) : St r i ng ;
22 c l a s s f unc t i on ParamCount : I n t e g e r ;c l a s s f unc t i on ParamName (Index : I n t e g e r ) : St r i ng ;
24 c l a s s f unc t i on Params (Name : St r i ng ) : St r i ng ;c l a s s f unc t i on ParamValue (Index : I n t e g e r ) : s t r i n g ;
26 c l a s s f unc t i on P a t h I n f o : St r i ng ;c l a s s f unc t i on R e f e r e r : St r i ng ;
28 c l a s s f unc t i on RemoteAddr : St r i ng ;c l a s s f unc t i on RemoteHost : St r i ng ;
30 c l a s s f unc t i on Scr ip tName : St r i ng ;c l a s s f unc t i on T i t l e : St r i ng ;
32 c l a s s f unc t i on Ur l : St r i ng ;c l a s s f unc t i on UserAgent : St r i ng ;
34 end ;
36 typeResponse =c l a s s( TObject )
38 c l a s s f unc t i on Cookie (Index : I n t e g e r ) : TCookie ;c l a s s f unc t i on CookieByName (Name : St r i ng ) : TCookie ;
40 c l a s s f unc t i on CookieCount : I n t e g e r ;
113
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
c l a s s f unc t i on GetAl low : St r i ng ;42 c l a s s f unc t i on GetCon ten t : St r i ng ;
c l a s s f unc t i on GetConten tEncod ing :St r i ng ;44 c l a s s f unc t i on GetCon ten tLeng th : I n t e g e r ;
c l a s s f unc t i on GetContentType : St r i ng ;46 c l a s s f unc t i on GetCon ten tVe rs ion : St r i ng ;
c l a s s f unc t i on GetDate : DateTime ;48 c l a s s f unc t i on GetDer ivedFrom : St r i ng ;
c l a s s f unc t i on GetExp i res : DateTime ;50 c l a s s f unc t i on GetLas tMod i f i ed : DateTime ;
c l a s s f unc t i on GetLoca t i on : St r i ng ;52 c l a s s f unc t i on GetLogMessage :St r i ng ;
c l a s s f unc t i on GetRealm : St r i ng ;54 c l a s s f unc t i on GetReasonS t r i ng :St r i ng ;
c l a s s f unc t i on GetSe rve r : St r i ng ;56 c l a s s f unc t i on GetS ta tusCode : I n t e g e r ;
c l a s s f unc t i on G e t T i t l e : St r i ng ;58 c l a s s f unc t i on GetVers ion : St r i ng ;
c l a s s f unc t i on NewCookie : TCookie ;60 c l a s s procedure S e n d R e d i r e c t ( Ur i : St r i ng ) ;
c l a s s procedure SetAl low ( Value : St r i ng ) ;62 c l a s s procedure S e t C o n t e n t ( Value : St r i ng ) ;
c l a s s procedure SetCon ten tEncod ing ( Value :St r i ng ) ;64 c l a s s procedure Se tCon ten tLeng th ( Value : I n t e g e r ) ;
c l a s s procedure SetCon ten tType ( Value :St r i ng ) ;66 c l a s s procedure S e t C o n t e n t V e r s i o n ( Value :St r i ng ) ;
c l a s s procedure SetDa te ( Value : DateTime ) ;68 c l a s s procedure SetDer ivedFrom ( Value :St r i ng ) ;
c l a s s procedure S e t E x p i r e s ( Value : DateTime ) ;70 c l a s s procedure S e t L a s t M o d i f i e d ( Value : DateTime ) ;
c l a s s procedure S e t L o c a t i o n ( Value : St r i ng ) ;72 c l a s s procedure SetLogMessage ( Value :St r i ng ) ;
c l a s s procedure SetRealm ( Value : St r i ng ) ;74 c l a s s procedure S e t R e a s o n S t r i n g ( Value :St r i ng ) ;
c l a s s procedure S e t S e r v e r ( Value : St r i ng ) ;76 c l a s s procedure S e t S t a t u s C o d e ( Value : I n t e g e r ) ;
c l a s s procedure S e t T i t l e ( Value : St r i ng ) ;78 c l a s s procedure S e t V e r s i o n ( Value : St r i ng ) ;
proper ty Allow : St r i ng read GetAl low wr i te SetAl low ;80 proper ty Conten t : St r i ng read GetCon ten t wr i te
S e t C o n t e n t ;proper ty Conten tEncod ing : St r i ng read
GetConten tEncod ingwr i te SetCon ten tEncod ing ;82 proper ty Conten tLeng th : I n t e g e rread GetCon ten tLeng th
wr i te Se tCon ten tLeng th ;proper ty ContentType : St r i ng read GetContentType wr i te
SetCon ten tType ;84 proper ty Con ten tVe rs i on : St r i ng read GetCon ten tVe rs ion
wr i te S e t C o n t e n t V e r s i o n ;
114
Rel
ease
Can
dida
te2
3.10. Web Library
proper ty Date : DateTime read GetDate wr i te SetDa te ;86 proper ty DerivedFrom : St r i ng read GetDer ivedFrom wr i te
SetDer ivedFrom ;proper ty E x p i r e s : DateTime read GetExp i res wr i te
S e t E x p i r e s ;88 proper ty Las tMod i f i ed : DateTime read GetLas tMod i f i ed
wr i te S e t L a s t M o d i f i e d ;proper ty Lo ca t i on : St r i ng read GetLoca t i on wr i te
S e t L o c a t i o n ;90 proper ty LogMessage : St r i ng read GetLogMessagewr i te
SetLogMessage ;proper ty Realm : St r i ng read GetRealm wr i te SetRealm ;
92 proper ty R e a s o n S t r i n g : St r i ng read GetReasonS t r i ngwr i te S e t R e a s o n S t r i n g ;
proper ty S e r v e r : St r i ng read GetSe rve r wr i te S e t S e r v e r ;94 proper ty Sta tusCode : I n t e g e rread GetS ta tusCodewr i te
S e t S t a t u s C o d e ;proper ty T i t l e : St r i ng read G e t T i t l e wr i te S e t T i t l e ;
96 proper ty Vers ion : St r i ng read GetVers ion wr i teS e t V e r s i o n ;
end ;98
type100 Scr i p tDoc = c l a s s( TObject )
c l a s s f unc t i on Date : DateTime ;102 c l a s s f unc t i on FileName : St r i ng ;
c l a s s f unc t i on Path : St r i ng ;104 c l a s s f unc t i on S ize : I n t e g e r ;
end ;106
type108 TCookie = c l a s s( TObject )
f un c t i on GetDomain : St r i ng ;110 f un c t i on GetExp i res : DateTime ;
f un c t i on GetHeaderValue : St r i ng ;112 f un c t i on GetName : St r i ng ;
f un c t i on GetPath : St r i ng ;114 f un c t i on GetSecure : Boolean ;
f un c t i on GetValue : St r i ng ;116 procedure SetDomain ( Value : St r i ng ) ;
procedure S e t E x p i r e s ( Value : DateTime ) ;118 procedure SetName ( Value : St r i ng ) ;
procedure S e t P a t h ( Value : St r i ng ) ;120 procedure S e t S e c u r e ( Value : Boolean ) ;
procedure SetVa lue ( Value : St r i ng ) ;122 proper ty Domain : St r i ng read GetDomain wr i te SetDomain ;
proper ty E x p i r e s : DateTime read GetExp i res wr i teS e t E x p i r e s ;
124 proper ty HeaderValue : St r i ng read GetHeaderValue ;
115
Rel
ease
Can
dida
te2
3. DWS II Standard Libraries
proper ty Name : St r i ng read GetName wr i te SetName ;126 proper ty Path : St r i ng read GetPath wr i te S e t P a t h ;
proper ty Secure : Booleanread GetSecure wr i te S e t S e c u r e;
128 proper ty Value : St r i ng read GetValue wr i te SetVa lue ;end ;
130
type132 TFormVarGroup = c l a s s( TObject )
cons t ruc to r C r e a t e ;134 f un c t i on coun t : i n t e g e r ;
f un c t i on Eof : boo lean ;136 f un c t i on Ext : St r i ng ;
procedure F i r s t ;138 f un c t i on GetAddNu l lF ie lds : boo lean ;
f un c t i on G e t P r e f i x : St r i ng ;140 procedure Next ;
f un c t i on RecNr : i n t e g e r ;142 procedure S e t A d d N u l l F i e l d s ( Value : boo lean ) ;
procedure S e t P r e f i x ( P r e f i x : St r i ng ) ;144 f un c t i on Value : St r i ng ;
proper ty AddNu l lF ie lds : boo lean read GetAddNu l lF ie ldswr i te S e t A d d N u l l F i e l d s ;
146 proper ty P r e f i x : St r i ng read G e t P r e f i x wr i te S e t P r e f i x ;end ;
148
{ F u n c t i o n s }150 f un c t i on FormVar ( ParamName :St r i ng ) : St r i ng ; forward ;
f un c t i on RtfToHtml ( R t f S t r : St r i ng ) : St r i ng ; forward ;152 f un c t i on TrimURL (sURL : St r i ng ) : St r i ng ; forward ;
f un c t i on AcceptWML : boo lean ; forward ;154 f un c t i on URLencode (sURL : St r i ng ) : St r i ng ; forward ;
f un c t i on URLdecode (sURL : St r i ng ) : St r i ng ; forward ;156 procedure _ fo rward ( NewFile : St r i ng ) ; forward ;
116
Rel
ease
Can
dida
te24. Non DWS II Standard Libraries
The DWS II installation package also ships some non standard libraries. These libraries will notbe covered by this document. Just that you get an idea which libraries are currently considered“non standard”, we’ll list some of them here.
4.1. ADO Library
For more information regarding this library (especially the functions and classes the libraryexports) please have a look at the HTML documentation.
4.2. DB Library
Consider this library as deprecated.
4.3. SMTP Library (D5, D6 only)
Since Delphi 7, Borland does not ship the FastNet components with Delphi. This library isdeprecated and no longer maintained.
117
Rel
ease
Can
dida
te2
4. Non DWS II Standard Libraries
118
Rel
ease
Can
dida
te2
Part III.
Advanced Topics
119
Rel
ease
Can
dida
te2
Rel
ease
Can
dida
te25. DWS II Tools
Future versions of this document may fill up this chapter. For now it can be considered as aplaceholder.
121
Rel
ease
Can
dida
te2
5. DWS II Tools
122
Rel
ease
Can
dida
te26. Creating Web Applications Using DWS
II 2.0
Figure 6.1 on the next page shows the WebModule of the ISAPI Demo. We’ll use this exampleto show how a DWS II ISAPI module has to be installed and how you can use it afterwards.
We won’t cover topics as ’How to setup IIS for debugging’ here.
6.1. Installation of the ISAPI Demo
If you’ve compiled the demo, and run IIS on your computer, follow the steps given in section6.1.1. In case you’ve installed Apache 2.x (Windows), follow the steps in section 6.1.2.
NO
TE
You can not run this demo under Linux, because it’s an ISAPI module.
6.1.1. Using IIS
Copy the “dws2.dll” file to the scripts directory of your server. Open thedws2\Demosdirec-tory in explorer, select the ISAPI subdirectory and press right mouse key. In the context menu,you’ll find a menu item that allows you to publish the directory via the IIS. If you chose “Is-apiDemo” as the virtual directory name on the server, you should be able to run theindex.dwsscript by typing following URL in your browser:http://localhost/scripts/dws2.dll/IsapiDemo/index.dws
6.1.2. Using Apache 2.0
Only for Win32 Platform! (Provided by Kenneth Wilcox <[email protected]> )Copy the dws2.dll to the cgi-bin directory on the server and make the following changes to
the httpd.conf file:
AddType application/x-httpd-dws .dwsAction application/x-httpd-dws "/cgi-bin/dws2.dll"AddHandler isapi-isa .dll
123
Rel
ease
Can
dida
te2
6. Creating Web Applications Using DWS II 2.0
Figure 6.1.:ISAPI Demo - WebModule
ISAPICacheFile "C:/Program Files/ApacheGroup/Apache2/cgi-bin/dws2.dll"
If you place the dll in any other directory make sure that it is aliased and that it has ExecCGIpermissions on it.
Line 1 tells Apache to set all .dws files to application/x-httpd-dws MIME typeLine 2 tells Apache that all application/x-httpd-dws MIME files are to be sent to dws2.dll for
processingLine 3 tells Apache that .dll files are ISAPI extentionsLine 4 tells Apache to load dws2.dll and keep it loaded (if this line is omitted then Apache
will load/unload the ISAPI with each request)
6.2. Other demos..
Demos for Linux may follow in another version of the document.
124
Rel
ease
Can
dida
te27. How-To
The authors of this document would be glad, if some DWS II community members could provideshort How-Tos that could be included here.
TIA!
7.1. Working with Objects
7.1.1. In Delphi, Get the Reference to a Delphi Object that is Wrapped bya Script Object
Use the GetExternalObjForID function defined in dws2comp.pas. It has the following definition:function GetExternalObjForID(Info : TProgramInfo;const AVarName:string) : TObject;
7.2. Working with DWS2Unit
7.2.1. In DWS, Use Functions/Procedures/Objects Defined in otherDws2Units
Use the Dependencies property of the Tdws2Unit component (newline-separated names of usedunits).
7.3. Working with Scripts
7.3.1. In DWS, Emulate Dynamic Arrays
The dynamic arrays of DWSII 2.0 are in fact quite static. The only way to create a dynamic arrayis to declare an array constant. The compiler allocates space on the stack for this constants rightbelow the regular stack. Because of this method there can’t be a SetLength because it wouldmean that the regular stack would have to be moved at runtime. As long as there is not memorymanager in DWSII we don’t see a better way to handle this.
There are mainly two work-arounds:
1. Use a TList
2. If you can use the COMConnector, try:
125
Rel
ease
Can
dida
te2
7. How-To
Listing 7.1:HowTo: Emulate Dynmic Arrays
var A : ComVar iantArray ;2 A. High : = 3 ; / / s e t d imens ion
A [ 0 ] : = 1 0 ;4 A [ 1 ] : = 2 0 ;
A [ 2 ] : = ’DWS’ ;6 A [ 3 ] : = ’Array’ ;
var i : I n t e g e r ;8 f o r i : = A. Low to A. High do
begin10 p r i n t l n (A[ i ] ) ;
end ;12 p r i n t l n (A.Low ) ;
p r i n t l n (A. High ) ;14 p r i n t l n (A. Length ) ;
7.3.2. In Delphi, Detect if a Variable is Used During the Running of theScript
In DWS, all variables are initialized i.e. a variable is defined immediately after the var-statementis executed. One workaround is to assign a never-used value during the variable assignment, andtest for that instead e.g.
Listing 7.2:HowTo: Detect Variable Usage
var I : I n t e g e r = −9999;2 i f I = −9999 then
/ / u n d e f i n e d or someth ing
126
Rel
ease
Can
dida
te28. Appendices
127
Rel
ease
Can
dida
te2
8. Appendices
128
Rel
ease
Can
dida
te2Listings
2.1. SimpleDemo EventHandler code . . . . . . . . . . . . . . . . . . . . . . . . .232.2. CallDemo: calling Test1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .272.3. CallDemo: calling Test4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .272.4. DWSIISyntax: Differences to Delphi . . . . . . . . . . . . . . . . . . . . . . .322.5. DWSIISyntax: Nested Declaration . . . . . . . . . . . . . . . . . . . . . . . .332.6. Working with Delphi objects in DWSII: TWindow . . . . . . . . . . . . . . . 362.7. Working with Delphi objects in DWSII: TWindow Constructor . . . . . . . . .372.8. Working with Delphi objects in DWSII: TWindow SetPosition . . . . . . . . .402.9. Working with Delphi objects in DWSII: TWindow Update . . . . . . . . . . .412.10. Advanced Techniques: Get ScriptObject in OnEval . . . . . . . . . . . . . . .412.11. Advanced Techniques: IScriptObj definition . . . . . . . . . . . . . . . . . . .423.1. Connectors: COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .463.2. Internal Functions: Maths . . . . . . . . . . . . . . . . . . . . . . . . . . . . .473.3. Internal Functions: String Functions . . . . . . . . . . . . . . . . . . . . . . .553.4. Internal Functions: DateTime Functions . . . . . . . . . . . . . . . . . . . . .623.5. Internal Functions: Variant Functions . . . . . . . . . . . . . . . . . . . . . .673.6. Internal Functions: File Functions . . . . . . . . . . . . . . . . . . . . . . . .713.7. Internal Functions: GUI Functions . . . . . . . . . . . . . . . . . . . . . . . .763.8. Internal Functions: Global Variable Functions . . . . . . . . . . . . . . . . . .793.9. Strings Unit: Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .823.10. Standard Library: Classes Library . . . . . . . . . . . . . . . . . . . . . . . .833.11. Standard Library: IBX / IBO Library . . . . . . . . . . . . . . . . . . . . . . .873.12. Standard Library: IBX / IBO Library - DataSetGrp Example . . . . . . . . . .913.13. Standard Library: Fiber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .923.14. Standard Library: Ini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .933.15. Standard Library: MFLib - Basic . . . . . . . . . . . . . . . . . . . . . . . . .953.16. Standard Library: MFLib - Connection . . . . . . . . . . . . . . . . . . . . . .953.17. Standard Library: MFLib - Dialog . . . . . . . . . . . . . . . . . . . . . . . .953.18. Standard Library: MFLib - File . . . . . . . . . . . . . . . . . . . . . . . . . .963.19. Standard Library: MFLib - Info . . . . . . . . . . . . . . . . . . . . . . . . .983.20. Standard Library: MFLib - Registry . . . . . . . . . . . . . . . . . . . . . . .993.21. Standard Library: MFLib - Shell . . . . . . . . . . . . . . . . . . . . . . . . .1003.22. Standard Library: MFLib - String . . . . . . . . . . . . . . . . . . . . . . . .1003.23. Standard Library: MFLib - System . . . . . . . . . . . . . . . . . . . . . . . .1043.24. Standard Library: MFLib - Window . . . . . . . . . . . . . . . . . . . . . . .105
129
Rel
ease
Can
dida
te2
Listings
3.25. Standard Library: MFLib - Zip . . . . . . . . . . . . . . . . . . . . . . . . . .1073.26. Standard Library: Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . .1093.27. Standard Library: WebLib - SessionLib . . . . . . . . . . . . . . . . . . . . .1113.28. Standard Library: WebLib . . . . . . . . . . . . . . . . . . . . . . . . . . . .1137.1. HowTo: Emulate Dynmic Arrays . . . . . . . . . . . . . . . . . . . . . . . . .1267.2. HowTo: Detect Variable Usage . . . . . . . . . . . . . . . . . . . . . . . . . .126
130
Rel
ease
Can
dida
te2List of Figures
1.1. DWS root in CVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151.2. ”dws2” module, directory layout . . . . . . . . . . . . . . . . . . . . . . . . .171.3. ”dws2tools” module - directory tree . . . . . . . . . . . . . . . . . . . . . . .221.4. dws2 core (above: VCL; below: CLX) . . . . . . . . . . . . . . . . . . . . . .22
2.1. SimpleDemo Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .242.2. Call Demo - Design-time . . . . . . . . . . . . . . . . . . . . . . . . . . . . .262.3. Object TreeView of the dws2Unit component found in Basic demo . . . . . . .352.4. Object TreeView of the TWindow class defined by dws2Unit . . . . . . . . . .382.5. Object Inspector: TWindow Constructor . . . . . . . . . . . . . . . . . . . . .39
3.1. DWS II tab with Common Libraries installed . . . . . . . . . . . . . . . . . .45
6.1. ISAPI Demo - WebModule . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
131
Rel
ease
Can
dida
te2
List of Figures
132
Rel
ease
Can
dida
te2Index
Abs, 51AnsiCompareStr, 60AnsiCompareText, 60AnsiLowerCase, 58AnsiUpperCase, 59AppendStringToFile, 73ArcCos, 49ArcCosh, 49ArcSin, 49ArcSinh, 49ArcTan, 50ArcTanh, 50
ChangeFileExt, 75CharAt, 58ChDir, 73Chr, 58CleanupGlobalVars, 81CompareStr, 60CompareText, 59Constants
MFLibBM_CLICK, 103BM_GETCHECK, 103BM_SETCHECK, 103BST_CHECKED, 103BST_INDETERMINATE, 103BST_UNCHECKED, 103CB_GETCOUNT, 103CB_GETCURSEL, 103CB_GETDROPPEDSTATE, 103CB_GETEDITSEL, 103CB_GETTOPINDEX, 103CB_RESETCONTENT, 103CB_SETCURSEL, 103
CB_SETEDITSEL, 103CB_SETTOPINDEX, 103CB_SHOWDROPDOWN, 103cdrLeft, 100cdrRight, 100DRIVE_CDROM, 96DRIVE_FIXED, 96DRIVE_NO_ROOT_DIR, 96DRIVE_RAMDISK, 96DRIVE_REMOTE, 96DRIVE_REMOVABLE, 96DRIVE_UNKNOWN, 96EM_GETSEL, 103EM_SETSEL, 103EM_UNDO, 104EWX_FORCE, 102EWX_FORCEIFHUNG, 102EWX_LOGOFF, 102EWX_POWEROFF, 102EWX_REBOOT, 102EWX_SHUTDOWN, 102FILEDATE_CREATION, 96FILEDATE_LASTACCESS, 96FILEDATE_LASTWRITE, 96HKEY_CLASSES_ROOT, 99HKEY_CURRENT_CONFIG, 99HKEY_CURRENT_USER, 99HKEY_DYN_DATA, 99HKEY_LOCAL_MACHINE, 99HKEY_PERFORMANCE_DATA, 99HKEY_USERS, 99LB_GETCOUNT, 104LB_GETCURSEL, 104LB_GETSEL, 104
133
Rel
ease
Can
dida
te2
Index
LB_GETSELCOUNT, 104LB_GETTEXT, 104LB_GETTEXTLEN, 104LB_GETTOPINDEX, 104LB_ITEMFROMPOINT, 104LB_RESETCONTENT, 104LB_SELITEMRANGE, 104LB_SETCURSEL, 104LB_SETSEL, 104LB_SETTOPINDEX, 104MOVEFILE_COPY_ALLOWED, 96MOVEFILE_CREATE_HARDLINK,
96MOVEFILE_DELAY_UNTIL_REBOOT,
96MOVEFILE_FAIL_IF_NOT_TRACKABLE,
96MOVEFILE_REPLACE_EXISTING,
96MOVEFILE_WRITE_THROUGH, 96SB_BOTTOM, 104SB_ENDSCROLL, 104SB_LINEDOWN, 104SB_LINEUP, 104SB_PAGEDOWN, 104SB_PAGEUP, 104SB_THUMBPOSITION, 104SB_THUMBTRACK, 104SB_TOP, 104SW_HIDE, 101SW_MAXIMIZE, 101SW_MINIMIZE, 101SW_NORMAL, 101SW_RESTORE, 102SW_SHOW, 101SW_SHOWDEFAULT, 102SW_SHOWMAXIMIZED, 101SW_SHOWMINIMIZED, 101SW_SHOWMINNOACTIVE, 101SW_SHOWNA, 102SW_SHOWNOACTIVE, 101SW_SHOWNORMAL, 101VER_UNKNOWN, 97VER_WIN2000, 98
VER_WIN32S, 97VER_WIN95, 97VER_WIN98, 98VER_WIN98SE, 98VER_WINME, 98VER_WINNT, 98VER_WINNT4, 98WM_ACTIVATE, 102WM_ACTIVATEAPP, 102WM_CHILDACTIVATE, 102WM_CLEAR, 103WM_CLOSE, 102WM_COMMAND, 102WM_COPY, 103WM_CUT, 103WM_ENABLE, 102WM_HELP, 102WM_HSCROLL, 102WM_KILLFOCUS, 102WM_LBUTTONDBLCLK, 103WM_LBUTTONDOWN, 102WM_LBUTTONUP, 102WM_MBUTTONDBLCLK, 103WM_MBUTTONDOWN, 103WM_MBUTTONUP, 103WM_MDICASCADE, 103WM_MDITILE, 103WM_MOUSEACTIVATE, 102WM_MOUSEMOVE, 102WM_MOUSEWHEEL, 103WM_MOVE, 102WM_PASTE, 103WM_QUIT, 102WM_RBUTTONDBLCLK, 103WM_RBUTTONDOWN, 103WM_RBUTTONUP, 103WM_SETCURSOR, 102WM_SETFOCUS, 102WM_SHOWWINDOW, 102WM_SIZE, 102WM_SYSCOMMAND, 102WM_UNDO, 103WM_USER, 103WM_VSCROLL, 102
134
Rel
ease
Can
dida
te2
Index
Zip_Add, 106Zip_EraseAllowUndo, 106Zip_EraseFinal, 106Zip_Extract, 106Zip_Freshen, 106Zip_Move, 106Zip_OverwriteAlways, 106Zip_OverwriteConfirm, 106Zip_OverwriteNever, 106Zip_Test, 106Zip_Update, 106
Contributors, 8Copy, 61Cos, 49Cosh, 49Cotan, 50CreateDir, 73
database connectivity standard, 87Date, 63DateTimeToStr, 63DateToStr, 63DayOfWeek, 65DecodeDate, 65DecodeTime, 66DegToRad, 50Delete, 58DeleteFile, 73dws2Hashtables, 86dws2UnitEditor, 83
emulate dynamic arrays, 125EncodeDate, 66EncodeTime, 66ErrorDlg, 77Exp, 51ExtObject, 40ExtractFileDir, 74ExtractFileDrive, 74ExtractFileExt, 75ExtractFileName, 74ExtractFilePath, 75
FileExists, 73FileSearch, 74
FloatToStr, 57FormatDateTime, 65Frac, 51
Garbage Collection, 37get reference to wrapped Delphi object, 125GetCurrentDir, 74
Hypot, 54
Inc, 54IncMonth, 65InformationDlg, 77InputBox, 77Insert, 58Instances, 40Int, 51IntToHex, 57IntToStr, 57IsDelimiter, 60IsLeapYear, 65
LastDelimiter, 60LeftStr, 61Length, 59Ln, 51load encrypted DWS II scripts, 95LoadStringFromFile, 73Log10, 51Log2, 51LogN, 51LowerCase, 58
Max, 52MidStr, 61Min, 52
Now, 63Null, 69
OkCancelDlg, 78OnAssignExternalObject, 37Ord, 58
Pi, 50Pos, 59
135
Rel
ease
Can
dida
te2
Index
Power, 52Print, Internal Function, 46PrintLn, Internal Function, 46
QuestionDlg, 77QuotedStr, 61
RadToDeg, 50RandG, 53Random, 53RandomInt, 53Randomize, 53RandSeed, 53ReadGlobalVar, 81ReadGlobalVarDef, 81RemoveDir, 74RenameFile, 73reports, 110RightStr, 61Round, 52
save compiled script, 29SaveStringToFile, 73Session Tracking Server, 111SetCharAt, 58SetCurrentDir, 74SetLength, 59SetRandSeed, 53ShowMessage, 77Sin, 49Sinh, 49Sqr, 51Sqrt, 51StringOfChar, 61StrToDate, 64StrToDateTime, 63StrToFloat, 57StrToFloatDef, 57StrToInt, 57StrToIntDef, 57StrToTime, 65
Tan, 49Tanh, 49THashTable, 86
Time, 63TimeToStr, 64TIntegerHashTable, 86Trim, 59TrimLeft, 59TrimRight, 59Trunc, 52TStringHashTable, 86
Unassigned, 69UpperCase, 59use types defined in other dws2Units, 125
VarAsType, 70VarClear, 69VarIsEmpty, 69VarIsNull, 69VarToStr, 70
WriteGlobalVar, 81
136