Borland® Delphi® 2005 Migration To .NET Using VCl for .Netby Bob Swart, Bob Swart Training & Consultancy
data access
We have transplanted a VCL application to .NET, now it's time to operate a big project, this time there will be more practical applications that will encounter. This code includes data access, so let us Take a look at Delphi7 / Demos / DB. In several examples of the directory, MastApp and IBMastApp are the largest, and have the most Unit (units) and FORM.
If you don't have Delphi7, you can also open the BDS / 3.0 / DEMOS / DELPHIWIN32 / DB directory, and the wrap also has two items (but have ported to new project formats).
MastApp has been ported to .NET, you can find the corresponding version in BDS / 3.0 / DEMOS / DELPHI.NET / DB / MASTAPP, and IBMastApp has not been ported to VCL for .NET, so you can't be in BDS / 3.0/DEMOS/delphi.net/db or bds / 3.0 / demos / delphi.net / VCL / DB Find the corresponding version.
So, as an important demonstration, let us start to transplant the IBMASTAPP application from Win32 to .NET - a complicated database application example.
First, we will still make a backup of the necessary documents.
Create a new subdirectory in the BDS / 3.0 / DEMOS / DELPHI.NET / VCL / DB directory, the name is ibmastapp. We work to finally get an example of a new Delphi for .NET VCL DB project.
Copy all files under the BDS / 3.0 / DEMOS / DELPHIWIN32 / VCLWIN32 / DB / IBMASTAPP directory to BDS / 3.0 / DEMOS / DELPHI.NET / VCL / DB / IBMASTAPP directory
Delete file mastapp.bdsproj because this file contains information that specifies this project as a Delphi Win32 project (and now we want to transplant it to .NET)
Now we are ready to start working on a new IBMastApp project and port it to .NET.
Run Delphi 2005
Click the Open Project button on Welcome Page and open the mastapp.dpr file under the BDS / 3.0 / DEMOS / DELPHI.NET / VCL / DB / IBMASTAPP directory (because we are copy from Win32)
Because the project does not include .bdsproj files, Delphi 2005 IDE needs to ask you to determine whether it is an upgraded item for Win32 or .NET project. So, a upgrade dialog will pop up with you, as shown below
Select to upgrade MastApp to .NET in the Project Upgrade dialog
Select Delphi for .NET and press OK button
We will get a mastapp.bdsproj file with .NET Personality information. Save the file now, the new personality information will be saved to the mastapp.bdspro file.
Select Menu File | Save All, all files of the MastApp project are saved, including file mastapp.bdsproj.
Transplant data module (Data Module)
Now we have associated this project as Delphi for .NET, first checking that the database control is pointing to the correct data connection. You must do this before you have done it. When the data connection is normal, we can Concentrate concentrate on the transplantation of the code.
Open the data module, which is DATAMOD.PAS. You can double-click the node corresponding to DataMod.Pas in the project manager (Project Manager)
The data module is designed as shown in the screenshot below, an architecture of Interbase Express as a data access is used.
VCL for .NET data module in design period
We must reset the Database control, which can be found in the lower right corner of the data module.
Click on the Database control on the data module (corresponding type to TibDatabase)
Right-click on the Database control, you will display a pop-up menu tells you that INTERBASEEXPRESS (9.09) is now used, as well as options to datase Database Editor. Select Database Editor, show a dialog as shown below:
Database control
Note that this d: / is the file path. You may want to modify C: /, and use the Common file instead of the Borland in the path to set the interbase to join this database. I default to install Mastsql.gdb to C : / Program files / common files / borland shared / data / mastsql.gdb - Your settings may be a bit different
Click the TEST button to verify that it can be connected to the Interbase database mastsql.gdb correctly. If not, confirm that the mastsql.gdb is not on the specified path, and check InterBase has already been run.
If you have clicked the Test button, you get the "Successful Connection" message, you can turn off the data control editor.
* Note that when you transplant VCL items to .NET, you may need to do this: First, confirm that data access controls on the data module can point to the correct database. And, although most of the database controls There is a version of the corresponding VCL for .NET, but the SQL link is not supported under .NET, you must transplant these projects to DBEXPRESS, DBGO for ADO, InterBaseExpress, or other VCL for .NET data access technology.
Transplanted source code
When the data module and the specified data access control are successfully modified, we can start the first project to finish work.
Press SHIFT F2 to save all files in the project
Press CTRL F9 for the first time to complete the MASTAPP project
You will get about 17 warning messages, there is an error message, as shown below:
[Warning] mastapp.dpr (23): w1005 Unit 'borland.vcl.form [Warning] main.pas (6): w1005 unit' borland.vcl.windows' Is Specific To a platform [Warning ] Main.pas (6): w1005 unit 'borland.vcl.Mersages' Is Specific to a platform [Warning] main.pas (6): w1005 unit 'borland.vcl.graphics' Is Specific to a platform [Warning] main .PAS (6): w1005 Unit 'borland.vcl.controls' is specific to a platform [Warning] main.pas (7): w1005 unit 'borland.vcl.form' is specific to a platform [Warning] main.pas (7): w1005 unit 'Borland.vcl.dialogs' Is Specific to a platform [Warning] main.pas (7): w1005 unit 'borland.vcl.Buttons' Is Specific to a platform [Warning] main.pas (7 : W1005 Unit 'Borland.vcl.stdctrls' Is Specific To a platform [Warning] main.pas (7): w1005 unit 'borland.vcl.menus' Is Specific To a platform [Warning] main.pas (7): W1005 Unit 'Borland.vcl.extCtrls' Is Specific To a Platform [Warning] DataMod.Pas (8): w1005 Unit 'Borland.vcl.windows' Is Specific To a Platform [Warning] DataMod.PAS 8): W1005 Unit 'Borland.vcl.Messages' Is Specific To a platform [Warning] Datamod.Pas (8): w1005 unit 'borland.vcl.graphics' is specific to a platform [Warning] DataMod.PAS (8) : W1005 Unit 'Borland.vcl.controls' Is Specific To a platform [Warning] Datamod.Pas (8): w1005 unit 'borland.vcl.form' is specific to a platform [Warning] DataMod.Pas (8): W1005 Unit 'borland.vcl.dialogs' Is Specific To a platform [Fatal Error] DataMod.Pas (9): F1026 File Not Found: 'VARUTILS.DCUIL' We can ignore the warning information - because most only remind us now Units using VCL for .NET can only run at a specific platform. To avoid this platform warning message, you can block them.
Select Project | Options to open the Project Management option (Project Options). In the Compiler Messages Category, you can select the "Platform Unit" to remove (as shown in the screenshot of the picture below). If you re-re-now Cut the project, you will not get the same warning information. Project Management Options - Warning Information List
Select Menu Project | Build MastApp, or you can press SHIFT F9 to perform the end. Now, the original 17 warning messages have no longer appear again, but there will be error messages.
[Fatal Error] Datamod.Pas (9): F1026 File Not Found: 'Varutils.dcuil'
The reason for causing this error is that the VARUTILS unit has been canceled in VCL for .NET (which may be merged into the Variants unit). So, we can remove the VARUTILS units that are not existing.
Remove Varutils from the USES section at Datamod.PAS file interface
* Note If you think your project can also be docked at Win32, you may be more willing to place the Varutils unit in a pair of {$ IFDEF WIN32} .... {$ ENDIF} block, not simple It removed from the USES clause.
If you decide to use the IFDEF solution, you can modify the Uses Clause clause like the following:
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, DB, IBQuery, IBCustomDataSet, Ibtable, IBDATABASE, IB, VARIANTS {$ IFDEF WIN32}, VARUTILS {$ ENDIF};
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
Now the result is 3 tips and 2 errors
[Error] edcust.pas (54): E2010 Incompatible Types: 'Variant' and 'Double' [Fatal Error] Brcstord.Pas (48): F2063 Could Not Compile Used Unit 'edcust.pas'
This hate function that is incorporated by the type is not compatible code is as follows:
Procedure Tedcustform.ED (Custno: double);
Begin
Mastdata.cust.open;
Mastdata.cust.locate ('Custno', Custno, []);
ShowModal;
END;
This error message is that the parameter Custno is caused by MastData.cust.locate. Its type is Double, but the function requires a variant type. This should be no problem, but it is necessary to add Variant's unit to the USES clause The sector can be done.
Increase the USES clause of the importation section in the EDCUST.PAS file
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
3 prompts and 1 error message will now be obtained.
[Fatal Error] Edorders.Pas (10): F1026 File Not Found: 'DBLOOKUP.DCUIL'
This pointed out that the dblookup unit has no VCL for .NET - or needs to be referenced in this project. We can easily remove this error.
The interface section from Edorders.Pas is removed in the USES clause.
* Note that if you want your project to be compatible with Win32, you can put the dblookup unit in the {$ IFDEF WIN32} .... {$ ENDIF} block, not simple to delete it from the USES clause If you decide to use the IFDEF solution, you can modify the code as below:
Sysutils, Messages, Clitiess, Graphics, Controls, Dialogs, Forms, Stdctrls, DBGRIDS, DBCTRLS, DB, Buttons, Grids, {$ IFDEF WIN32} DBLOOKUP, {$ ENDIF} Extctrls, Mask;
P Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-add the project.
3 prompts will now be obtained, and there are 4 errors.
[Error] srchdlg.Pas (54): E2010 Incompatible Types: 'Variant' and 'DOUBLE'
[Error] srchdlg.Pas (64): E2010 Incompatible Types: 'Variant' and 'DOUBLE'
[Error] srchdlg.pas (98): E2010 Incompatible Types: 'Variant' and 'Tcaption'
[Fatal Error] Edorders.Pas (76): F2063 Could Not Compile Used Unit 'srchdlg.PAS'
The first three errors are very similar to the mistakes we have just solved, and they can also be solved by adding the Variants unit in the USES clause.
Add a VariantS unit in the USES clause under the IMplementation section of the srchdlg.Pas unit
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
3 prompts now, 1 warning, and 2 error messages.
[Error] Edorders.Pas (105): E2010 Incompatible Types: 'Variant' and 'DOUBLE'
[Warning] edorders.pas (229): w1050 widechar reduced to byte char in set expnesss
[Fatal Error] Brcstord.Pas (48): F2063 Could Not Compile Used Unit 'Edorders.PAS'
Now we already know the cause of the wrong, there is also a solution. Warning information section will be processed in the next process - or let us first concentrate on all done errors.
The USES clause to the importation section of the EDORDERS.PAS unit adds the Variants unit.
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
There are still 3 tips, 1 warning, and 3 error messages.
Add the USES clause under the Implementation section of the BrcStord.Pas unit Add a Variants unit.
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
3 prompts, 1 warning, and 1 error message
Remove dblookup from edparts.pas (Interface) Uses clause, or place the DBLookUp unit into blocks of {$ IFDEF WIN32}, as shown below:
uses SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs, DB, StdCtrls, ExtCtrls, Mask, DBCtrls, {$ IFDEF WIN32} DBLookup, {$ ENDIF} Buttons; all files Press Shift F2 to save the project, Then press SHIFT F9 to re-add the project
3 prompts, 1 warning, and 2 error messages
The USES clause under the Implementation section of Edparts.PA unit adds the Variants unit.
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
3 prompts, 1 warning, and 2 error messages
The USES clauses under the Implementation section of the BrPARTS.PAS unit add a Variants unit.
Press SHIFT F2 to save all files of the project, then press SHIFT F9 to re-establish the project
If you run the Delphi 2005 version that has already been upgraded (installed), now your program is already able to re-link, you can directly refer to this article "Running the Marine" Adventure Order Entry Application "section. If you find it still encountered an error, then you can look down.
3 prompts, 1 warning, and 1 severe error message
[Hint] DATAMOD.PAS (244): H2443 Inline Function 'ExpandFileName' HAS NOT BEEN Expanded
Because Unit 'System.io' Is Not Specified in Usees List
[Hint] DATAMOD.PAS (743): H2443 Inline Function 'FileExists' Has NOT BEEN Expanded Because
Unit 'system.io' is not specified in usees list
[Hint] DATAMOD.PAS (748): H2443 Inline Function 'ExtractFileName' HAS NOT BEEN Expanded
Because Unit 'System.io' Is Not Specified in Usees List
[Warning] edorders.pas (229): w1050 widechar reduced to byte char in set expnesss
[Fatal Error] Custrpt.Pas (6): F1026 File Not Found: 'Quickrpt.dcuil'
At this time, you will also encounter a runtime error dialog prompt when the Delphi 2005 VCL Designer is trying to display the Custrpt unit. Can't find the corresponding attribute.
Unsolicited