⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delphi tutorials_ dynamic link libraries.htm

📁 Examples of dynamic libraries creation
💻 HTM
字号:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><meta name="ProgId" content="FrontPage.Editor.Document"><link rel="stylesheet" type="text/css" href="main.css"><title>Delphi Tutorials: Dynamic Link Libraries</title></head><body topmargin="0" leftmargin="0" marginwidth="0" margintop="0"><table border="0" width="730">  <tr>    <td width="100%"><script language="JavaScript1.1" type="text/javascript" src="http://context5.kanoodle.com/cgi-bin/ctpub_adserv.cgi?id=84881453&amp;site_id=85190478&amp;format=728x90b&amp;bdcl=c5c5c5&amp;bgcl=f0f0f0&amp;tlcl=0235CE&amp;ttcl=000000&amp;ulcl=339900"></script>    </td>  </tr></table><p>&nbsp;</p><table border="0" width="100%" cellspacing="0" cellpadding="0">  <tr>    <td width="100%">      <p class="maintitle">Creating a Dynamic Link Library</td>  </tr>  <tr>    <td width="100%" bgcolor="#FF9900" height="1"></td>  </tr></table>&nbsp;<table border="0" width="100%">  <tr>    <td width="100%">A dynamic link library or DLL is a program that another      program needs for its functionality. It usually has an extension of .dll      although it could sometimes have another extension. DLLs are created for      various reasons, the most regular of which allows different programs to      &quot;call&quot; the same DLL.      <p>&nbsp;</p>    </td>  </tr></table><table border="0" width="100%" cellspacing="1">  <tr>    <td width="100%">      <ol>        <li>Start Borland Delphi if you didn't yet. From the Standard          toolbar, click the New button <img border="0" src="../buttons/new1.gif" width="31" height="26">.</li>        <li>From the New Items dialog box, click DLL Wizard<br>          &nbsp;<br>          <img border="0" src="dlgboxes/dlgdllwiz1.gif" width="443" height="372"></li>        <li>Click OK.</li>        <li>To save the current project, on the main menu, click File -&gt; Save          All</li>        <li> To make          things easier, from the Save Unit1 As dialog box, locate the common          folder called <a href="../references/common.htm">Programs</a> and          display the Delphi folder it in the Save In combo box.</li>        <li>Click the Create New Folder button, type DLLExercise and press          Enter.</li>        <li>Double-click the new folder to display it in the Save In combo box.          In the File Name edit box, change the name of the project to DLLProject and click Save.</li>        <li>Examine and read the whole file, especially the commented section.</li>        <li>Change the content of the file as follows:<br>          &nbsp;          <table border="0" width="100%" bgcolor="#ECF5FF">            <tr>              <td width="100%">                <pre>library DLLProject;uses  SysUtils,  Classes;function BoxArea(L, H, W : Double) : Double;begin  Result := 2 * ((L*H) + (L*W) + (H*W));end;function BoxVolume(L, H, W : Double) : Double;begin  Result := L * H * W;end;procedure BoxProperties(L, H, W : Double; var A, V : Double);begin  A := BoxArea(L, H, W);  V := BoxVolume(L, H, W);end;exports  BoxProperties;beginend.</pre>              </td>            </tr>          </table>        </li>        <li>To save your project, on the main menu, click File -&gt; Save All.        </li>        <li>To build the DLL, on the main menu, click Project -&gt; Build          DLLProject.</li>        <li>Save your project</li>      </ol>    </td>  </tr></table>&nbsp;<table border="0" width="100%">  <tr>    <td width="100%">      <p class="ParaJust">Now we will create a project to use our DLL.</p>      <ol>        <li>Start a new application with the default form.</li>        <li>To save the project, on the main menu, click File -&gt; Save All.</li>        <li>Locate and display the same folder in which the DLL project was          created.</li>        <li>Save the unit as Main and the project as ParaRect</li>        <li>Design the form as follows:<br>          &nbsp;<br>          <img border="0" src="../bcb/images/form1a.gif" width="284" height="205"></li>        <li>Besides the labels you can read, from top -&gt; down, the form has          five Edit controls named edtLength, edtHeight, edtWidth, edtArea, and          edtVolume respectively. Then add two buttons named btnCalculate and          btnExit.</li>        <li>On the form, double-click the Exit button&nbsp;</li>        <li>On the form, double-click the Calculate button.</li>        <li>Return to the form and double-click the Calculate button.</li>        <li>To call the DLL, change the file as follows:<br>          &nbsp;          <table border="0" width="100%" bgcolor="#ECF5FF">            <tr>              <td width="100%">                <pre>unit Main;interfaceuses  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;  <b>procedure BoxProperties(L, H, W : Double; var A, V : Double); external 'DLLProject.dll';</b>implementation{$R *.DFM}procedure TForm1.btnExitClick(Sender: TObject);begin  <b>Close;</b>end;procedure TForm1.btnCalculateClick(Sender: TObject);var  <b>Length, Height, Width, Area, Volume : Double;</b>begin  <b>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);</b>end;end.</pre>              </td>            </tr>          </table>        </li>        <li>To save the project, on the main menu, click File -&gt; Save All.</li>        <li>To execute the project, on the main menu, click Run -&gt; Run.</li>      </ol>    </td>  </tr></table>&nbsp;<table border="0" width="100%">  <tr>    <td width="100%" valign="middle" align="center" colspan="3">      <hr color="#FF9900">    </td>  </tr>  <tr>    <td width="33%" valign="middle" align="center"><font color="#FF0000"><a href="index.htm">Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -