- 1. Including the files of the Visual Basic interface of WINDEV
- 2. Including the HFSQL declarations
- Declaration and initialization
- 1. Declaring the HFSQL context and the working buffers of each file
- 2. Initializing the WINDEV DLLs
- 3. Initializing HFSQL
- 4. Loading the WINDEV library (WDL)
- 5. Opening the project analysis and associating buffers with the data files
- Running WINDEV codes from the external language
- 1. Initialization code of the WINDEV project
- 2. Calling a WLanguage code
- 3. Retrieving the events triggered in the WINDEV windows
- Ending the application
External language: Programming in Visual Basic
We are going to call the elements developed in WINDEV (project, windows, analysis, ... ) from Visual Basic. This system is based on the use of the functions declared in the wdxxxle.dll of WINDEV. The WLanguage code used from the external language will be dynamically compiled and run during its call.
This mode is illustrated in City.VBP (in Visual Basic 6 format) supplied in the "ExternalLanguages\Basic" sub-directory of the setup directory of WINDEV.
1. Including the files of the Visual Basic interface of WINDEV
If you are using a database in your application, the first step consists in generating your analysis. In the description of this analysis, specify the programming language used as well as the directory that will contain the source files.
Via the generation, a program skeleton (*.bas) is generated. This operation will also create the .gbl file (see below) required to use your data files.
The following files must be included in a Visual Basic project in order to call the Visual Basic interface of WINDEV:
The .glb and .bas files that describe the structure of the data files will be automatically generated by WINDEV when generating the analysis.
2. Including the HFSQL declarations
The .gbl and .bas files corresponding to the description of the analysis files must be added to the Visual Basic project. The declarations of the data files are included in the file whose extension is.gbl (this file replaces the.wdr created with the earlier WINDEV version).
For example, in the City.vbp project (supplied with WINDEV in the "ExternalLanguages" directory), this file is named "WD External language.gbl".
Declaration and initialization
1. Declaring the HFSQL context and the working buffers of each file
If the application must manage data files, a HFSQL working context must be declared as well as a buffer for each data file.
These declarations are performed by the following lines in the WD25 External Language.bas project:
' Manage the context of the 3 HFSQL files
gCtx = EL_CreateHFContext(3) ' Structure of the CITY file
' Zip Codes & Cities
ZIPCODE As String * 5
F_ZIPCODE As String * 1
CITY As String * 30
F_CITY As String * 1
Global CD As TYPECD
2. Initializing the WINDEV DLLs
The first step before using the elements developed in WINDEV is to load the WINDEV DLLs in memory and to initialize them.
These operations are performed by the call to InitModule in the callwd procedure as follows:
If your application is calling a database, the access to HFSQL must be prepared now. The test below is used to check whether this initialization is performed properly:
'Initialization of HF
If EL_HinitShare(gCtx,WDLong) = 0 Then
MsgBox ("Error initializing the HF context.")
4. Loading the WINDEV library (WDL)
The WINDEV library (.WDL extension) contains all the project elements (windows, reports, classes, queries, analysis, ...). Therefore, it must be loaded in memory in order for its components to be called.
The load operation is performed by callwd("Library,disk ...") as follows:
Caution: If the library to load contains windows, the code of each one of these windows must be included in the corresponding ".WDW" file ("Include the compiled code" must be checked in the "Details" tab of the description of each window).
' Open the library
' if WDInt is not null, the library was not found!
If WDInt <> 0 Then
' Library not found
Call callwd("Error,The CITY.WDL library must be found in the current directory.")
' indicate to WINDEV that the program will be ended
5. Opening the project analysis and associating buffers with the data files
Opening the analysis allows you to call the data files. Once this analysis has been opened by /HOpenAnalysis, all you have to do is associate the working buffers with the files described in this analysis:
'open the analysis
If HOpenAnalysis(gCtx, sAnalysisName, sPassword,"", "", "") = 0 Then
MsgBox ("Error opening the analysis " + sAnalysisName)
' HF buffer of the City file
Call EL_HDescribeRecord(gCtx, "CITY", 37, lArrItmCD(0), 2, sTypeCD, CD)
' HF buffer of the State file
Call EL_HDescribeRecord(gCtx, "STATE", 34, lArrItmDP(0), 2, sTypeDP, DP)
Running WINDEV codes from the external language
1. Initialization code of the WINDEV project
This code is used to start the WINDEV project by declaring the global variables for example. It is run from the external language by CallWD("Project, ProjectName"). For example:
2. Calling a WLanguage code
All the WLanguage functions can be called from the external language. The behavior of these WLanguage functions as well as the returned values are identical whether they are called:
- from WINDEV or
- from the interface of external language
To find out the parameters and the return values of a WLanguage function, see the online help or the documentation about WLanguage.
The call to a WLanguage procedure from the external interface is done via CallWD. For example:
' Open a WINDEV window
You will notice that the parameter expected by CallWD is a character string containing the WLanguage code to run.
Like the WLanguage coded in WINDEV, this string is not case sensitive (uppercase/lowercase characters). Therefore, the "Info" command can also be written as "INFO".
3. Retrieving the events triggered in the WINDEV windows
The input in the WINDEV windows requires to retrieve the events triggered in these windows.
To retrieve the user events (click on a menu, on a button, ...), you must implement a system based on a loop in your Visual Basic program. This loop will remain active as long as the WINDEV window is opened and it will be used to intercept each user action.
To find out the type of action performed by the user, you have the ability to use a character string variable (in WLanguage) named 'WDKey'. This variable will be used in your WLanguage code to signal to the Visual Basic program which button has been pressed for example. This string has no size limit and it can contain the detailed statements that will be retrieved from your Visual Basic code.
Example: Visual Basic code
' open the first window of the program that contains the menu
' the program loops until the File Exit option
' is selected
While WDKey <> "ESC"
' perform the input of the menu
' Test of the selected option.
If WDKey = "FE" then WDKey = "ESC" ' Exit
If WDKey = "RN" Then Call SearchCity ' Search by City
If WDKey = "RD" Then Call SearchState ' Search by State
If WDKey = "DD" Then Call LstState ' Display list.
If WDKey = "DI" Then Call LstPrint ' Print.
If WDKey = "DC" Then Call LstConfig ' Configure printer
' close the window
Code of "File .. Exit" of the WINDEV "Menu" window (WLanguage):
When the user clicks "File..Exit", WDKey will be returned to the Visual Basic code to perform the next action.
Note: The WDKey variable being a character string, its content can be a detailed description of the action to perform. For example, "Close the application".
To end the use of the external interface, all you have to do is call WDEnd
that expects no parameter. For example:
Click [Add] to post a comment