Http://www.programfan.com/article/2722.html
Abstract: This article mainly discusses the key to compilation and release of PowerBuilder 8.0 applications based on Windows platform.
Problem
And solution, including execution
File Creation, resource file creation, installation program creation, addition of data sources and SQL Anywhere Database mobile processing and other issues. Keywords: Software
Development, PowerBuilder 8.0, application release, and setup.
Introduction
PowerBuilder + ODBC + SQL
Anywhere is a popular mode for developing database applications. However, Powerbuilder is only a development tool. After an application is developed and debugged
You need to create an executable file for it and transplant it to the end user's machine. The ODBC configuration and SQL
Anywhere installation is difficult. This article discusses the key technical issues and solutions for compiling and releasing Windows-based PowerBuilder 8.0 applications.
Execution File Creation
1. Select the compilation format
PowerBuilder
8.0 two compilation formats are provided for the production of executable files: pseudocode (pcode) and machine code (machinecode ). Pseudocode is a type
All explanatory languages supported on the PowerBuilder platform. Their formats are similar to those supported by PowerBuilder.
Like the Runtime Library (. PBL), it saves a single object in the executable State, which has the advantages of convenience and portability. The machine code is truly completely out of PowerBuilder.
Environment executable files, its advantage is fast, but the file capacity is relatively large. The format of the compiled code is generally based on the following three aspects:
① Speed. If the goal is to optimize the running speed and apply enhanced script processing, select the machine code. If loop structures, floating-point operations, or integer algorithms and function calls are used in many codes, machine code can do better than pseudo code. However, pseudo-code compilation is faster than machine code, especially when developers need to quickly create executable files for testing;
② Size. Files generated by pseudo-code are smaller than those generated by machine code. If the terminal machine that runs the application is insufficient, You need to discard the faster machine code and select the pseudocode;
③ Transplantation. Pseudocode is very useful for cross-platform applications.
. It is easy to use across platforms (supported by PowerBuilder), including Microsoft Windows (16-bit and 32-bit), applemacintosh, and UNIX. The machine code depends on the platform. That is to say, the generated code must be consistent with the executable application platform, but it can achieve better performance.
2. Dynamic Library Creation
Publishing a PowerBuilder 8.0 application can place some objects in a dynamic library instead of an executable file, so that the application can be split into smaller modules for management and maintenance.
Select the pseudo-code (pcode) compilation method to generate the PowerBuilder dynamic library (. PBD file), select the machine code (machinecode) method in
Generate a dynamic link library (. dll file, for example, compile test. PBL into test. dll) on Windows and UNIX platforms, and generate
Shared Library (such as test. Lib ). If there are two applications on Windows, the compiled. PBD contains a user object that calls the global external function. To ensure that the correct function call must be
Each application separately compiles and releases the. PBD file.
When a dynamic library is created, the compiled versions of all objects in the source Library (. PBL file) are copied to the dynamic library. To use only the required objects in some libraries, you can place them in a standard PowerBuilder Library (. PBL.
When creating a dynamic library, PowerBuilder does not check all objects, but simply removes the source format of the object. Therefore, for some resources (graphics, icons
Or pointer). If you do not want to provide individual resources, you must list these resources in the resource file (. PBR) to ensure that these resources are included when a dynamic library is created.
There are two ways to create a dynamic library: one is to create a paint brush in the library management, and the other is to create a project object together in the paint brush.
3. Use of resource files
Executable files or dynamic libraries can contain some resources (graphics, icons, or pointers), or they can be saved as separate resource files (. PBR files.
(1) independent distribution of resources
If a resource is not included in an executable file or a dynamic library, PowerBuilder searches for the resource according to the query path when the application references it. Therefore, you must put it in the query path together with the application.
The query path for Windows is: Current Directory, Windows Directory, Windows System directory, and all directories set in PATH environment variables.
(2) resource files
You can use the PowerBuilder resource file (. PBR) to replace individual resources. All dynamically allocated resources can also contain dynamically allocated data window objects. PowerBuilder compiles these resources into executable files or. PBD files, which can be directly used during execution.
If you dynamically allocate a data window object to the data window control, you must create a resource file that contains the object in the executable file or dynamic library file, or include it in a separate dynamic library.
Resource file (.pbr] is an ascii code file, in which various types of resources (such as. BMP,. cur,. ICO,. RLE, And. WMF files) and
Data window object. Use a text editor (such as Windows notepad) to create a text file, which lists the resource files dynamically referenced in the application, and a resource is listed in one row. The format is as follows:
Appico. ICO
Appbmp 1.bmp
Appbmp 2.bmp
......
The above files and objects are assumed to be in the current directory. If they exist in another directory, they must contain the path. The format is as follows:
E:/MyApp/test.jpg.
In. the file name specified in the PBR file must match the resource referenced in the script. If the reference contains a path. the PBR file must also contain the same path. Otherwise, the resource cannot be found because PowerBuilder simply compares strings during execution.
If an application contains a data window with dynamic reference, the. PBR file must contain a data window object. The format is as follows:
MyApp. PBL (dw_infodisplay)
Specifically, MyApp. PBL is the application library, and dw_infodisplay is the data window object, which is generally in the current directory or specified path. If a resource is referenced during execution, PowerBuilder first checks the executable file and finds it in the directory of the. PBD file and file query path.
When creating a project object in the project paint brush, you can specify the resource file it uses for an executable file or every dynamic library, or you can use it when creating a dynamic library in the library management paint brush.
Configure the PowerBuilder 8.0 Application
Generally, a PowerBuilder 8.0application is released. In addition to the executable file (.exe) of the application and the dynamic library of the application (. PBD or. dll), the following files should be included:
1. Files supported by PowerBuilder 8.0 when the application is running
PowerBuilder 8.0 support files (. dll) when the application is running should be stored in the same directory as the application or in the search path.
The above files can be obtained in C:/program files/Sybase/shared/PowerBuilder.
2. Database Interfaces
All database interface files and drivers (pbtra80.dll, pbodb80.dll, and pbodb80.ini) must be placed in the application directory or system directory.
The above files can be found in C:/Program
Files/Sybase/shared/PowerBuilder. Copy them to the application directory or system directory. If you use the dedicated database interface and
ActiveX. For the file to be copied, see the onlinebook of PowerBuilder.
3. Microsoft ODBC driver and DLLs
Ds16gt. dll, ds32gt. dll, odbc32.dll, odbc32gt. dll, odbcad32.exe, odbccp32.cpl ,_
Odbccp32.dll, odbccr32.dll, odbcinst. CNT, odbcinst. HLP, odbcint. dll, odbctrac. dll
The above files can be obtained in the system directory system32 of window. The specific path varies with the operating system. Copy them to the application directory or system directory.
4. ODBC database driver for Adaptive Server Anywhere and its supporting files
Pbbas15.dll, pbflt15.dll, pbutl15.dll, pbtrn15.dll, ivpb. LIC, pbdrv15.cnt, pbdrv15.hlp.
The above files can be obtained in C:/program files/Sybase/shared/merantodbc. We will copy them to the application directory or system directory.
5. Adaptive Server Anywhere running system files
Dbodbc7.dll, dbbackup. EXE, dbcon7.dll, dbisqlc. EXE, dblgen7.dll, dblib7.dll, dbodtr7.dll ,_
Dbtool7.dll, dbunload. EXE, dbvalid. EXE, dbeng7.exe, dbctrs7.dll, dbserv7.dll, and dbwtsp7.dll.
The above files can be obtained in C:/program files/Sybase/SQL Anywhere 7/Win32. We will copy them to the application directory or system directory.
6. Ole System File
If the ole control is used in the application, the end user's machine should have Ole system files, which are:
Compobj. dll, ole2nls. dll, ctl3dv2. dll, ole2prox. dll, ole2.dll, storage. dll, ole2conv. dll ,_
Typelib. dll, ole2disp. dll, tdole. TLB
If they do not exist, copy them to the application directory or system directory.
Not all of the supporting files listed above must be copied to the application directory or system directory. You can flexibly decide based on your situation. Before publishing an application, to determine which dynamic link libraries are required, a feasible and reliable method is as follows:
(1) copy the generated application to another computer without PowerBuilder installed and run it.
(2) Find the dynamic library that the application prompts cannot be found and cannot run.
(3) copy the corresponding dynamic library file from the machine where the application is developed.
(4) Repeat Step (2) (3) until all dynamic linked databases are included.
Installation Program Creation
Applications developed on Windows platforms cannot be published and installed after simple copy in a DOS environment. Therefore, creating a setup becomes an essential step for publishing Windows applications.
1. Basic setup Functions
The only purpose of the setup program is to install the application and process the installation process. The setup program should have the following basic functions:
(1) transfer a file. Transfer the applications to be installed and related support files to the target machine and handle errors during the transfer. This is the most basic function of the setup program.
(2) Ask the end user about necessary information, such as the user name, product serial number, and target path, and respond to user input.
(3) give users the opportunity to change their ideas, such as changing the installation path and canceling the installation.
(4) access to the registry. Such as setting the application search path key and creating the application information key.
(5) The uninstall function should be used to uninstall and register the installed files and registry settings, so that you can unmount the application and change it back to the registry when you cancel installation or do not need it.
(6) After the installation is complete, you should receive a prompt to complete the installation.
2. Application installation rules
When applications are installed on machines, many rules should be followed, most of which are common sense. They make your applications easier to maintain and rarely cause problems caused by file replication.
(L) Avoid copying any files to the system directory unless you are upgrading common files (such as ODBC or local database drivers) used by external applications ). This helps avoid downgrading the performance of the operating system by changing files in these regions.
(2) If a file is a common file shared only between applications of a single user, an entry should be created in the common files subdirectory of program files.
(3) In Windows, put your own applications in your own directory under program flies.
(4) Support files (. HLP,. dll, etc.) should be distributed in a sub-directory called the System user's own application for Windows. Register its location in the registry of the apppaths sub-key at the hkey_localmachine/software entrance of the application.
(5) The registry should be used to store all required information about the application, instead of modifying the system. ini, win. ini, or INI file of the application.
(6) Create an entry in the startup engine of the operating system to provide access to your applications. For Windows, you should place a shortcut icon of the application on the desktop or in the program folder of the Start Menu.
(7) Any file stored in the system directory should be registered in the sharedll subkey of hkey_localmachine.
3. Select the Installation Tool
Installshield is a well-known installation program production software developed by InstallShield software company. InstallShield provides easy-to-use Wizard and
An integrated environment to help you create application installation programs. However, the use of Installshield is complicated. Installshield is not a free software, but a copyrighted
Commercial software. Most PowerBuilder
8.0 when talking about publishing an application, books and materials give an extremely simple prompt to use InstallShield to create an installation program. There is very little information about the use of InstallShield.
Therefore, we often encounter many difficulties.
The commonly used installation and production tool during installation is createinstall 2000. It is a shared software that supports Chinese characters. Can be downloaded at www.gentee.com. If it is not registered, a prompt will be displayed when the created installation disk is running, but the function is unlimited.
Another installation and preparation tool that is more convenient and useful than Installshield is GP-install. GP-install is a free software compiled using Delphi.
Although it is a free software, it does not mean that it has fewer or less powerful functions. On the contrary, a software installation should have many functions, which are quite convenient and practical. After the software is installed
2 m, only the zero header of InstallShield. Some functions of InstallShield, GP-install, are basically available, and the generated installer interface is also very similar, but GP
-Install is more friendly. The biggest feature of GP-install is to allow the generation of installation programs in multiple languages, which contains languages from multiple countries.
Language, and the language you select during the installation, which will be displayed during the reverse installation (uninstallation. This is very useful for programmers who want to promote their programs to other countries and regions.
GP-install home page: http://www.qsc.co.uk where you can download the latest version, which is currently 5.0.2.57.
Other commonly used software that can be used to create the installation program include setup factory.
4. Add Registry Information
This is the key! ODBC installation and data source configuration are involved. Never make a mistake.
There are two ways to add registry information:
(1) Add directly, mainly when manually adding a data source or creating an installer. Generally, you only need to set the following items:
Root Key sub-key value name value
HKEY_CURRENT_USER software/ODBC. INI/demo (replace with your own data source name) autostop Yes
HKEY_CURRENT_USER: Same as databasename demo (replace with your own database name)
HKEY_CURRENT_USER same as databasefile demo. dB (replace with your own database file)
HKEY_CURRENT_USER same as driver C:/program files/Sybase/SQL Anywhere 7/Win32/dbodbc7.dll
HKEY_CURRENT_USER same as PWD SQL
HKEY_CURRENT_USER same as uid DBA
You may also need to set the following items:
Root Key sub-key value name value
HKEY_CURRENT_USER software/ODBC. INI/demo (replace it with your own data source name) Description my database (replace it with your description of your own database, which can be Chinese)
HKEY_CURRENT_USER is the same as enginename my database (replace it with your own data engine description, which can be Chinese)
HKEY_CURRENT_USER same as start C:/program files/Sybase/SQL Anywhere 7/Win32/dbeng7.exe-C 8 m, 0
HKEY_LOCAL_MACHINE software/ODBC drivers Adaptive Server Anywhere 7.0 installed
HKEY_LOCAL_MACHINE software/ODBC/Adaptive Server Anywhere 7.0 driver C:/program files/Sybase/SQL Anywhere 7/Win32/dbodbc7.dll
HKEY_LOCAL_MACHINE software/ODBC/Adaptive Server Anywhere 7.0 setup C:/program files/Sybase/SQL Anywhere 7/Win32/dbodbc7.dll
HKEY_CURRENT_USER software/ODBC. INI/ODBC Data Sources your own data source name, for example, demo Adaptive Server Anywhere 7.0
HKEY_LOCAL_MACHINE software/Microsoft/Windows/CurrentVersion/APP
Paths/myapp.exe (replace with your Executable File Name) path C:/Program
Files/Sybase/shared/PowerBuilder;
C:/program files/Sybase/SQL Anywhere 7/Win32/; C:/program files/Sybase/shared/merantodbc
HKEY_LOCAL_MACHINE software/Microsoft/Windows/CurrentVersion/APP paths/myapp.exe (replace it with your executable file? Default myapp.exe (replace with your executable file name)
The above items are the registration executable file and search path. You can also change it to another path. The specific situation is determined flexibly when the installation program is created.
(2) Using programs in PowerBuilder to dynamically add ODBC data sources, mainly using PowerBuilder to operate functions in the Registry
Registryset (), and then use
The profilestring () and setprofilestring () functions of PowerBuilder read and set predefined parameters in the ini configuration file.
Number.
Registryset (Key, valuename, valuetype, value)
Function: Set Information in the Registry in the PowerBuilder program.
Key indicates the primary key; valuename indicates the key value name; valuetype indicates the key value type; value indicates the key value.
Profilestring (filename, section, key, value)
Function: read information in the ini configuration file in the powerbuilde program.
Filename indicates the file name, section indicates the segment name, key indicates the keyword, and value indicates the keyword value.
Setprofilestring (filename, section, key, value)
Function: Set Information in the ini configuration file in the powerbuilde program.
Filename indicates the file name, section indicates the segment name, key indicates the keyword, and value indicates the keyword value.
Now, ODBC and data sources are configured.
For different database management systems, the above methods and statements will be different, but you can use the following methods as the basis for adding ODBC Data Sources Using programs: ① open ODBC Data Source Management in the control panel
Manually add a data source. ② Run regedit, open registry editor, find the added data source, and write down the values of its key values. ③ In the installation program or in
The registset () function is used in the PowerBuilder program to write the values of each key value to the Registry. Of course, some key values will certainly be different, such as the specific path of the database.
5. Mobile processing of database files (. DB)
SQL Anywhere in PowerBuilder 8.0
A database consists of two files, namely. DB and. log. The. DB file is used to store database information (including table structure, view, and data ). The. log file is a log file.
To record every operation that has an impact on the database, such as creating or deleting tables, views, triggers, and other objects, and inserting, deleting, and modifying table data. When we create an SQL
In addition to generating a database file (. DB), A. log file is created by default.
When moving the SQL Anywhere Database, copy the. DB file and the. log file together to configure ODBC,
Configure the profile in PowerBuilder to connect. However, log files (. Log) often cause some troubles, so that the database cannot be easily moved to other machines for use. Because
If SQL
Anywhere stores the path information of log files in the database when creating a database. When you copy the database to another machine, if the directories are different, the database cannot be connected.
.
The general solution is to create a directory on the terminal user machine. That is, if the. log file path when the database is created is: H:/pb8.0/share/
MyApp. log, create a virtual disk with the disk Number H: On the end user machine, and then create the corresponding directory to replace the MyApp. copy the log to this directory (or copy it again.
To open and call the database. Another solution is to re-register the. Log File and enter SQL Anywhere in DOS mode.
Run dblog-T X1:/path1/xxx. Log
X2:/path2/xxx. DB. X1:/path1/xxx. log is the path and name of the generated new. log file. X2:/path2/xxx. DB
It is the. DB file that your current application wants to use. Be sure not to make a mistake.
In general, if the requirement is not too high, you can omit the. log file, that is, do not attach the. log file to the database during database creation, so that the library file can be moved easily.
Sudden Power failure or abnormal shutdown or accidental operations may damage sqlanywhere data, resulting in a great deal of loss, if only damaged. DB file. log is normal, you can
To restore most of the data in the damaged database. the contents of the log file are converted into SQL statements, and then an empty database is created, and then these SQL statements are executed to restore the data
The problem is solved. Sybase provides several utilities to complete the above functions.
Assume that the database system file is named MyApp. DB and MyApp. Log respectively. If MyApp. DB is damaged. Create a new database. Assume that the files are named new. DB and new. log.
Use the sybase‑enabled dbtran=exe, db32‑exe, rtsqlw.exe, and other utilities to complete the recovery. The steps are as follows:
1. dbtranw-r-k-y MyApp. Log dB. SQL // SQL statement used to convert the content of the. Log File
2. attrib-r MyApp. DB // modify the attribute of the read-only file MyApp. dB to writable.
3. attrib-r MyApp. Log // modify the attribute of the read-only file MyApp. log to writable.
4. Copy new. DB MyApp. DB // overwrite the damaged old library file with the new empty library file
5. Copy new. Log MyApp. Log // overwrite the old log file with the new Log File
6.db32w.exe-D MyApp. DB // start the database sqlanywhere
7. rtsqlw-Q-c "userid = DBA; Password = SQL" read dB. SQL // execute the SQL statement from the. log file.
The first step is to convert the old log file into an SQL statement and put it in a database named dB. in the SQL file, note that it can only be operated before step 5; otherwise, the log file will be
The data cannot be restored because the new. log is overwritten. The last step is to read and execute SQL statements from the file dB. SQL. Assume that the database username is dBA and the password is SQL.
For more detailed usage of each command and parameter data, see the corresponding help. Note: The. log file cannot be deleted. Otherwise, the recovered data is incomplete.
Conclusion
This article is based on Windows PowerBuilder
8.0 key issues of application compilation and publishing are analyzed and detailed solutions are provided, including developing PowerBuilder
8.0 when an application is running, the execution file is created, the resource file is created, the installation program is created, and the data source and SQL Anywhere are added.
Database mobile processing and other issues. This method is not limited to PowerBuilder, but also useful for other development tools. The technology mentioned is already in the MPs Integrated Management System for graduate students in the computer department of Guangxi Normal University.
Development is verified. At the same time, this technology has been applied to multiple management information systems and has achieved good results.