Delphi USE DLL

xiaoxiao2021-03-06  41

Delphi dynamometer call DLL

Explicit example:

Unit main;

Interface

Uses

Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Stdctrls, ExtCtrls, Grids, DBGRIDS, DB, DBTABLES, DBCTRLS

Type

TFORM1 = Class (TFORM)

Button1: tbutton;

EDIT1: TEDIT;

EDIT2: TEDIT;

Image1: timage;

DataSource1: TDataSource;

Table1: TTable;

Table1speciesno: tfloatfield;

Table1category: TStringField;

Table1common_name: tstringfield;

Table1SpeciesName: tstringfield;

Table1Lengthcm: tfloatfield;

Table1Length_in: tfloatfield;

Table1Notes: TMEMOFIELD;

Table1Graphic: TGRAPHICFIELD;

DBGRID1: TDBGRID;

Procedure Button1Click (Sender: TOBJECT);

Private

{Private Declarations}

public

{Public declarations}

END;

// Function GetInteger (i: integer): integer; stdcall; exTernal 'Dllone.dll';

// Function getDouble (f: double): double; stdcall; external 'dllone.dll';

Tgetdouble = function (f: double): double; stdcall;

VAR

FORM1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

VAR D: Double;

DllHandle: Thandle;

Func: tgetdouble;

Begin

Image1.Picture.Assign (Table1graphic);

Table1Graphic.Assign (Image1.Picture);

EXIT;

DllHandle: = loadLibrary ('dllone.dll');

Try

@Func: = getProcaddress (DLLHANDLE, 'GETDOUBLE');

//Edit1.text: = INTOSTR (Getinteger (2));

// D: = getDouble (2.2);

IF assigned (@func) THEN

Begin

D: = func (2.2);

Edit2.text: = floattostr (d);

END;

Finally

Freelibrary (DLLHANDLE);

END;

END;

End.

Implicit example:

Library Dllone;

Uses

SYSUTILS,

Classes;

{$ R * .res}

Function getDoublexT (f: double): double; stdcall; external 'dlltwo.dll';

Function GetInt (I: Integer): Integer; stdcall; external 'DLLTWO.DLL'; Function GetInteger: Integer; stdcall;

Begin

Result: = GetInt (i);

END;

Function getDouble (d: double): double; stdcall;

Begin

Result: = getDoubleext (d);

END;

Exports

Getinteger,

Getdouble;

Begin

End.

Library DLLTWO;

{Important Note About DLL Memory Management: ShareMem Must Be The

First Unit in Your Library's Uses Clause and Your Project'S (SELECT

Project-view source) Uses Clause if your dll exports Any Procedures OR

Functions That Pass strings as parameters or function results. this

Applies to all strings passed to and from your dll - Even those That

Arene Nested in Records and class. ShareMem is the interface unit to

The borlndmm.dll Shared Memory Manager, Which Must Be Deployed Along

With your dll. to avoid using borlndmm.dll, pass string information

Using Pchar or shortstring parameters.

Uses

SYSUTILS,

Classes;

{$ R * .res}

Function getDoublexT (D: Double): double; stdcall;

Begin

Result: = D;

END;

Function GetInt (i: integer): integer; stdcall;

Begin

Result: = i;

END;

Exports

GetDoubleext,

Getint;

Begin

End.

转载请注明原文地址:https://www.9cbs.com/read-59970.html

New Post(0)