Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco



Home: Code Repository: Mastering Delphi 5

Project CALLFRST

Project Structure


CALLFRST.DPR

program Callfrst;

uses
  ShareMem,
  Forms,
  CallForm in 'CallForm.pas' {Form1};

{$R *.RES}

begin
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

CALLFORM.PAS

unit CallForm;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Spin, ExtCtrls;

type
  TForm1 = class(TForm)
    BtnDouble: TButton;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    BtnTriple: TButton;
    Label2: TLabel;
    SpinEdit2: TSpinEdit;
    BtnDoubleString: TButton;
    BtnDoublePChar: TButton;
    EditSource: TEdit;
    EditDouble: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    procedure BtnDoubleClick(Sender: TObject);
    procedure BtnTripleClick(Sender: TObject);
    procedure BtnDoubleStringClick(Sender: TObject);
    procedure BtnDoublePCharClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{functions of the Delphi DLL}
function Double (N: Integer): Integer;
  stdcall; external 'FIRSTDLL.DLL';
function Triple (N: Integer): Integer;
  stdcall; external 'FIRSTDLL.DLL';
function DoubleString (S: string; Separator: Char): string;
  stdcall; external 'FIRSTDLL.DLL';
function DoublePChar (BufferIn, BufferOut: PChar;
  BufferOutLen: Cardinal; Separator: Char): LongBool;
  stdcall; external 'FIRSTDLL.DLL';

procedure TForm1.BtnDoubleClick(Sender: TObject);
begin
  SpinEdit1.Value := Double (SpinEdit1.Value);
end;

procedure TForm1.BtnTripleClick(Sender: TObject);
begin
  SpinEdit2.Value:= Triple (SpinEdit2.Value);
end;

procedure TForm1.BtnDoubleStringClick(Sender: TObject);
begin
  // call the DLL function directly
  EditDouble.Text :=
    DoubleString (EditSource.Text, ';');
end;

procedure TForm1.BtnDoublePCharClick(Sender: TObject);
var
  Buffer: string;
begin
  // make the buffer large enough
  SetLength (Buffer, 1000);
  // call the DLL function
  if DoublePChar (PChar (EditSource.Text), PChar (Buffer), 1000, '/') then
    EditDouble.Text := Buffer;
end;

end.

CALLFORM.DFM

object Form1: TForm1
  Left = 250
  Top = 134
  Width = 352
  Height = 254
  Caption = 'Call Delphi DLL'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object Bevel1: TBevel
    Left = 8
    Top = 120
    Width = 321
    Height = 97
  end
  object Bevel2: TBevel
    Left = 8
    Top = 8
    Width = 321
    Height = 105
  end
  object Label1: TLabel
    Left = 152
    Top = 24
    Width = 30
    Height = 13
    Caption = 'Value:'
  end
  object Label2: TLabel
    Left = 152
    Top = 72
    Width = 30
    Height = 13
    Caption = 'Value:'
  end
  object Label3: TLabel
    Left = 149
    Top = 140
    Width = 37
    Height = 13
    Caption = 'Source:'
  end
  object Label4: TLabel
    Left = 152
    Top = 184
    Width = 37
    Height = 13
    Caption = 'Double:'
  end
  object BtnDouble: TButton
    Left = 32
    Top = 16
    Width = 89
    Height = 33
    Caption = 'Double'
    TabOrder = 0
    OnClick = BtnDoubleClick
  end
  object SpinEdit1: TSpinEdit
    Left = 192
    Top = 19
    Width = 81
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 1
    Value = 10
  end
  object BtnTriple: TButton
    Left = 32
    Top = 64
    Width = 89
    Height = 33
    Caption = 'Triple'
    TabOrder = 2
    OnClick = BtnTripleClick
  end
  object SpinEdit2: TSpinEdit
    Left = 192
    Top = 67
    Width = 81
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 3
    Value = 10
  end
  object BtnDoubleString: TButton
    Left = 32
    Top = 128
    Width = 89
    Height = 33
    Caption = 'Double String'
    TabOrder = 4
    OnClick = BtnDoubleStringClick
  end
  object BtnDoublePChar: TButton
    Left = 32
    Top = 176
    Width = 89
    Height = 33
    Caption = 'Double PChar'
    TabOrder = 5
    OnClick = BtnDoublePCharClick
  end
  object EditSource: TEdit
    Left = 195
    Top = 137
    Width = 121
    Height = 21
    TabOrder = 6
    Text = 'Hello, world'
  end
  object EditDouble: TEdit
    Left = 195
    Top = 180
    Width = 121
    Height = 21
    ReadOnly = True
    TabOrder = 7
    Text = '(result)'
  end
end