Einzelnen Beitrag anzeigen

alf.stefan

Registriert seit: 11. Apr 2003
88 Beiträge
 
Delphi 7 Professional
 
#1

probelm mit DLL beim kapseln in einer Klasse

  Alt 2. Jul 2009, 06:45
Hallo zusammen

habe eine wrapper DLL bekommen und für diese dann in Delphi eine Unit mit den Funktions Deklarationen geschrieben.
Funktioniert auch alles prima.
Jetzt wollte ich die ganzen Funktionsaurufe in einer Klasse kapseln und habe nicht schlecht gestaunt,
dass ich da dann die Funktionen nicht aufrufen kann (EAccessViolation).

Also so funktioniert alles!
Delphi-Quellcode:
unit uTest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

const myDll = 'O3D2xxCamera.dll';

function IfmConnect(hCP : integer; pIp : pChar; XMLPort : integer; FW_Version : pChar; sensorType : pChar):integer; stdCall;
function IfmDisConnect( force : integer):integer; stdCall;


type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function IfmConnect; external myDll name '_O3D2XXConnect@20';
function IfmDisConnect; external myDll name '_O3D2XXDisconnect@4';


procedure TForm1.FormCreate(Sender: TObject);

var
  ipAddress : string;
  fwVersion : string;
  sensorType: string;
begin
  ipAddress := '172.20.7.160';
  setLength(fwVersion, 4);
  setLength(sensorType, 8);

  IfmConnect(handle, pChar(ipAddress),8080, pChar(fwVersion), pChar(sensorType));
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    IfmDisConnect(0);
end;

end.
und siehe da SO bekomm ich immer den Fehler

Delphi-Quellcode:
unit uTest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

const myDll = 'O3D2xxCamera.dll';


type TmyClass = class
  handle : HWND;
  ipAddress : string;
  xmlPort: integer;
  fwVersion : string;
  sensorType: string;
  constructor create;
  function connect(): integer;
  private
    function IfmConnect(hCP : integer; pIp : pChar; XMLPort : integer; FW_Version : pChar; sensorType : pChar):integer; stdCall;
    function IfmDisConnect( force : integer):integer; stdCall;
end;

type
  TForm1 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  myClass : TmyClass;

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
begin
   myClass := TmyClass.create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    myClass.IfmDisConnect(0);
end;

constructor TmyClass.create;
begin
  ipAddress := '172.20.7.160';
  setLength(fwVersion, 4);
  setLength(sensorType, 8);

  self.connect;
end;


function TmyClass.IfmConnect; external myDll name '_O3D2XXConnect@20';
function TmyClass.IfmDisConnect; external myDll name '_O3D2XXDisconnect@4';

function TmyClass.connect: integer;
begin
   result := self.IfmConnect(Form1.Handle, pChar(ipAddress), 8080, pChar(fwVersion), pChar(sensorType));
end;



end.
Die zwei codeschnippsel sind doch eigentlich gar nicht so unterschiedlich.
Was ist im 2. Code falsch?

Im vorraus schon mal vielen Dank für die Mühe des anguckens!

Gruß

Stefan
  Mit Zitat antworten Zitat