10.4.2.2 Delphi Application Invoke Reuse form
To invoke a reused form in a Delphi application, you must first include the Passform.dll two output functions:
function GetPassword (Password:pchar): Boolean;
Far External ' c:\dlls\PassForm ';
function SetPassword (Password:pchar): Boolean;
Far External ' c:\dlls\PassForm ';
This is the implementation part of the program unit.
The implementation code for the Password Settings section is:
Procedure Tform1.setbuttonclick (Sender:tobject);
Begin
PassWord: = Stralloc (40);
If SetPassword (PassWord) = False Then
Messagedlg (' PassWord is not set ', mtinformation,[mbok],0);
End
First allocates memory for the password string. Displays the appropriate information when the password settings form is canceled by the Cancel button.
The implementation code for the password check section is:
Procedure Tform1.testbuttonclick (Sender:tobject);
Begin
If PassWord = Nil Then
Begin
Messagedlg (' Set password ', mtinformation, [Mbok], 0);
Setbutton.setfocus;
Exit;
End
If GetPassword (PassWord) Then
Label1.Caption: = ' you are Wellcome! '
Else
Label1.Caption: = ' sorry,you are InValid User. '
End
Displays the appropriate information in the Label box, based on the results of the password check.
10.4.2.3 VB application invoke Reuse form
VB is a visual development tool strongly recommended by Microsoft Company. Although it does not support the creation of dynamic link libraries, you can invoke standard Windows API dynamic-link libraries and dynamic-link libraries written in other languages. To verify the universality of the generated DLLs, we developed a simple program using VB to invoke the form stored in the Passform.dll.
The following is the complete code of VB program, and the corresponding part of the Delphi program is basically consistent.
Option Explicit
Declare Function getpassword Lib "C:\dlls\passform.dll" (ByVal PassWord as String) as Integer
Declare Function setpassword Lib "C:\dlls\passform.dll" (ByVal PassWord as String) as Integer
Dim PassWord as String * 40
Sub Check_click ()
If PassWord = "" Then
MsgBox ("Enter Sample Password")
Setpass.setfocus
Else
If GetPassword (PassWord) Then
Statuslbl.caption = "You are welcome!"
Else
Statuslbl.caption = "Sorry,you are Invalid User."
End If
End If
End Sub
Sub Setpass_click ()
If SetPassword (PassWord) = 0 Then
MsgBox ("PassWord is not Set.")
End If
End Sub
Some specific questions about VB programming, readers can refer to the relevant VB reference books.
Summary of 10.4.3
In this chapter we discuss dynamic link library programming. Many visual development tools, such as visual Basic, do not support the creation of DLLs, and Delphi has a superb performance here. In particular, the form reuse mechanism is a significant improvement of Delphi's DLLs programming under Windows. In the general DLLs programming also embodies the Delphi fast, convenient characteristics. Dynamic link libraries are an important way to organize programs in Windows, and using dynamic link libraries can greatly protect the work that users do at different development tools and periods. Using dynamic link library, users can gradually build their own program module library, accumulate material for future work.