|
Now we will create a project to use our DLL.
- Start a new application with the default form.
- To save the project, on the main menu, click File -> Save All.
- Locate and display the same folder in which the DLL project was
created.
- Save the unit as Main and the project as ParaRect
- Design the form as follows:

- Besides the labels you can read, from top -> down, the form has
five Edit controls named edtLength, edtHeight, edtWidth, edtArea, and
edtVolume respectively. Then add two buttons named btnCalculate and
btnExit.
- On the form, double-click the Exit button
- On the form, double-click the Calculate button.
- Return to the form and double-click the Calculate button.
- To call the DLL, change the file as follows:
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
edtLength: TEdit;
edtHeight: TEdit;
edtWidth: TEdit;
edtArea: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
btnVolume: TLabel;
edtVolume: TEdit;
btnCalculate: TButton;
Shape1: TShape;
btnExit: TButton;
procedure btnExitClick(Sender: TObject);
procedure btnCalculateClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure BoxProperties(L, H, W : Double; var A, V : Double); external 'DLLProject.dll';
implementation
{$R *.DFM}
procedure TForm1.btnExitClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.btnCalculateClick(Sender: TObject);
var
Length, Height, Width, Area, Volume : Double;
begin
Length := StrToFloat(edtLength.Text);
Height := StrToFloat(edtHeight.Text);
Width := StrToFloat(edtWidth.Text);
BoxProperties(Length, Height, Width, Area, Volume);
edtArea.Text := FloatToStr(Area);
edtVolume.Text := FloatToStr(Volume);
end;
end.
|
- To save the project, on the main menu, click File -> Save All.
- To execute the project, on the main menu, click Run -> Run.
|