🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.program
Article #866

����Delphi������ʹ�ö�̬���ӿ�

#866
From: ���ܵ�Сʨ
Date: Thu, 07 May 1998 00:00
97 lines
5704 bytes
   ��̬���ӿ�(DLL)��Windows������Ҫ�IJ���֮һ,Windows�е���
�г�����Թ���DLL�е������,�Ӷ�ʹӦ�ó�����Թ������,����
�ڴ�ռ�á����ļ�Ҫ������Delphi������ʹ��DLL��

    һ��������̬���ӿ�

    1.����һ���µĹ����ļ�
    ���ڴ˹���ֻ�Ǹ����ļ�,��˲�����ҪForm������ѡ�����˵�V
iew|Project Manage, ���Զ���ɵ�Unit1��Form1��ȥ,Ȼ��ѡ��Fil
e|Save Project As,���˹���ȡ��Ϊ Mydl.d pr����(��������� ),
 ��ϵͳ�����Ƿ񱣴�Unit1ʱ�ش�NO��,��ѡ��View|Projectourc 
e,��������޸�����:
    library  Mydll;
      uses   WinTypes;
      begin
      end.
    ���ļ���һ�㹤���ļ���Ҫ��֮ͬ�����ڽ���ʶ��"program"��
Ϊ"library"��
    2.��̬���ӿ��м��뱻���Ӧ�ó����õ������(��̼���
�� )
    ����һ���µ�Unit,�������Ӧ�ó����õ����������������
��ʵ�֡�ע�������Ui t��Interface�������������β��Ҫ�ӹؼ�
��"export",��ʾ������ܹ���"���",Ҳ�����ܱ�����Ӧ�ó������
������:��һ�����ú���Plus,�������ǽ������������,��Unit�Ĵ�
������:
    Unit    Content; {������̵�Ԫ,���������}
    interface
    function  plus (a,b:integer):integer;export;
    implementation
    function  plus (a,b:integer):integer;
      begin
       Result:=a+b;
      end;
    end.

    3.����������
    ѡ��View|Project Source,��Mydll.dpr��uses����֮�����:
    exports
    plus; {������������}
    ����Ĺ����ļ�����:
    library  Mydll;
    uses    WinTypes,
            Content   in  ��CONTENT.PAS��;
    exports
     plus;
    begin
    end.
    ���Ͼ������DLL��Ĵ���,ѡ��Compile������롣
    ����ʹ�ö�̬���ӿ�
    DLL�е���Դ���Ա����EXE�ļ�����,���ڿ�����Delphi������
��Ӧ�ó���,��ͬʹ��y dll.dll�еĺ���Plus:

    1.����һ���µĹ����ļ� Usedll.dpr, ��ȥ���е�Unit��Form
��
    2.Ϊ���� Mydll.dll �еĺ���Plus,����һ���µ�Unit,��Ŀ��
��Ϊ��˵��Ҫ���õ���̴������ĸ�DLL����(�ùؼ���"external"),
��Unit�Ĵ�������:
    Unit  useunit;  {����ʹ��DLL�ĵ�Ԫ}
    interface
    function  plus (a,b:integer):integer;
    implementation
    function  plus; external ��Mydll��;
    {˵��������������ⲿMydll.dll����ʵ�ֵ�}
    end.
    ���Կ���,�����ⲿ���,��interface���ֵ���������ͨ���һ
��,������implementai on����Ҫʹ�ùؼ���"external",��ʾ�����
���ڳ����ⲿʵ�ֵġ�
    3.����Ҫʹ�ú���Plus��Unit��,ֻҪ����Implementation����
��Uses��useunit��������ɡ�
    ����:�½�һForm,����Edit��Button�ؼ�,ΪButton����OnClick
�¼�,��Form��ӦUni��implementation��������:
    implementation
      {$R *.DFM}
    uses useunit;     {��useunit��Ԫ}
      procedure TForm1.Button1Click(Sender: TObject);
      {Button1��OnClick�¼�}
    begin
      Edit1.Text:=IntToStr (Plus (10,20));
      {ʹ��DLL���еĺ���}
    end;
        end.
    ���˹��̱���,���Usedll.exe,����ʱ����Button���ɿ���Edit
�ؼ���Text�����30��
    ��������Խ������EXE�ļ�,��ͬʹ��Mydll�еĺ���Plus,�ɴ�
���Կ�����̬���ӿ����Խ��,�ر����ڿ����������ʱ,��̬���ӿ�
����ʹ�á�
    ���ϳ�����Delphi 1.0/Win3.2��Delphi2.0/Win95������ͨ��
--
 ________ _____          _____        ______________  _____ 
 ___  __ \___(_)________ ___(_)       __  ___/___  /_ ___(_)
 __  /_/ /__  / ___  __ \__  /        _____ \ __  __ \__  / 
 _  ____/ _  /  __  /_/ /_  /         ____/ / _  / / /_  /  
 /_/      /_/   _  .___/ /_/          /____/  /_/ /_/ /_/   
                /_/                                         

�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn]
Technical Details
Message-ID: <3OOYkJ$uLD@bbs.nju.edu.cn>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: fc86e,369031647508c54b,start
X-Google-Attributes: gidfc86e,public
From: pipishi.bbs@bbs.nju.edu.cn (���ܵ�Сʨ)
Subject: ����Delphi������ʹ�ö�̬���ӿ�
Date: 1998/05/07
Message-ID: <3OOYkJ$uLD@bbs.nju.edu.cn>
X-Deja-AN: 351560196
X-Filename: Programming/M.894548659.A
Organization: nju_bbs
Newsgroups: cn.bbs.comp.program