Jump to content
xisto Community

Clinica do PC

Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by Clinica do PC

  1. In this example, we are going to use a Form, 2 text box (which the user should enter the both real numbers) and a button. See the Source example: unit usadll; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Button1: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; function Max(a, b : double):double;stdcall; var Form1: TForm1; implementation {$R *.DFM} function Max(a, b : double):double;external 'MaxDLL'; procedure TForm1.Button1Click(Sender: TObject); var x, y, resultado : double; begin x := StrToFloat(Edit1.Text); y := StrToFloat(Edit2.Text); resultado := Max(x,y); ShowMessage('Valor Máximo ' +FloatToStr(resultado)); end; end. (That's it.. Thank you)
  2. First of all, I'd like to apologise because my English is not tha good. Well, It's a very popular doubt. like How can I use a DLL? How can I create one? What is it for? So, DLL or Dynamic Link Libraries, allows a set of functions developed in one especific programmer language to be used for softwares developed in other language. For example, you can create a DLL in DELPHI and use it with a software developed in C++ for example. So, let's get started: Select the Item NEW in the menu FILE to show the dialog box NEW ITEMS. Now select DLL and OK to generate the main code of the DLL. This one below: library Project1; { 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 are nested in records and classes. 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; begin end. (In many situations, including this, the file DELPHIMM.DLL should be distributed with the application) Let's continue creating our DLL. Just to show let's create a function which receives as parameters two real numbers and returns the greater from them. Lets see: Function Max (a b : double ) : double ; Export ; stdcall ; begin If (a > then Result :=a else Result := b ; end ; Export = indicate that the function can be used for others applications Stdcall = allow applications, developed in other languages, to call the function After alterations, save the project as MAXDLL. This is how it should be: library Project1; { 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 are nested in records and classes. 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; function Max(a, b : double):double:expert:stdcall: begin if (a > then result:= a else result := b; end; exports Max index 1; begin end. The DLL was created and the function inside it. You can also create procedures, etc. This is a very simple example.. In the Next Article I'll show how to call this DLL from DELPHI Source Code. SEE YA
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.