Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

Project CALLCPP

Project Structure


CALLCPP.DPR

program Callcpp;

uses
  Forms,
  CallCppF in 'CallCppF.pas' {Form1};

{$R *.RES}

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

CALLCPPF.PAS

unit CallCppF;

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;
    BtnAdd: TButton;
    Label3: TLabel;
    Edit1: TEdit;
    Bevel1: TBevel;
    procedure BtnDoubleClick(Sender: TObject);
    procedure BtnTripleClick(Sender: TObject);
    procedure BtnAddClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{definition of the functions of the DLL}
function Add (A, B: Integer): Integer;
  stdcall; external 'CPPDLL.DLL' name '@Add$qqsii';
function Double (N: Integer): Integer;
  stdcall; external 'CPPDLL.DLL' name 'Double';
function Triple (N: Integer): Integer;
  stdcall; external 'CPPDLL.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.BtnAddClick(Sender: TObject);
begin
  Edit1.Text := IntToStr (Add (
    SpinEdit1.Value, SpinEdit2.Value));
end;

end.

CALLCPPF.DFM

object Form1: TForm1
  Left = 205
  Top = 166
  Width = 371
  Height = 190
  Caption = 'Call C++ DLL'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 176
    Top = 24
    Width = 30
    Height = 13
    Caption = 'Value:'
  end
  object Label2: TLabel
    Left = 176
    Top = 64
    Width = 30
    Height = 13
    Caption = 'Value:'
  end
  object Label3: TLabel
    Left = 176
    Top = 120
    Width = 27
    Height = 13
    Caption = 'Total:'
  end
  object Bevel1: TBevel
    Left = 168
    Top = 96
    Width = 161
    Height = 9
    Shape = bsTopLine
  end
  object BtnDouble: TButton
    Left = 40
    Top = 16
    Width = 89
    Height = 33
    Caption = 'Double'
    TabOrder = 0
    OnClick = BtnDoubleClick
  end
  object SpinEdit1: TSpinEdit
    Left = 232
    Top = 20
    Width = 81
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 1
    Value = 10
  end
  object BtnTriple: TButton
    Left = 40
    Top = 56
    Width = 89
    Height = 33
    Caption = 'Triple'
    TabOrder = 2
    OnClick = BtnTripleClick
  end
  object SpinEdit2: TSpinEdit
    Left = 232
    Top = 60
    Width = 81
    Height = 22
    MaxValue = 0
    MinValue = 0
    TabOrder = 3
    Value = 10
  end
  object BtnAdd: TButton
    Left = 40
    Top = 112
    Width = 89
    Height = 33
    Caption = 'Add'
    TabOrder = 4
    OnClick = BtnAddClick
  end
  object Edit1: TEdit
    Left = 232
    Top = 116
    Width = 79
    Height = 21
    ReadOnly = True
    TabOrder = 5
  end
end