Hello,
I am trying to control a ThorLabs motor stage in Lazarus.
I could import a type library from their OCX file and it nicely shows up in the ActiveX container (see attached ActiveX.png).
But clicking anywhere inside the ActiveX container results in a "external: access violation" exception.
Also when adding any more commands that should control the motor stage it compiles OK but generates a "EOleSysError" with the message "catastrophic failure" when running.
The code of my main form is included below, the type library that was imported from the OCX file is attached.
Lazarus version = 2.2.2
I'm really stuck here, so any help is welcome,
Rik
unit MainUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
activexcontainer;
type
{ TMainForm }
TMainForm = class(TForm)
ActiveXContainer: TActiveXContainer;
Button: TButton;
procedure ButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
private
public
end;
var
MainForm: TMainForm;
implementation
uses
APTPZMotorLib_1_0_TLB;
var
Motor: _DAPTPZMotor;
{$R *.lfm}
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
begin
Motor:= CoAPTPZMotor.Create;
ActiveXContainer.ComServer:= Motor;
ActiveXContainer.Active:= True;
Motor.HWSerialNum:= 27262824; // generates a "EOleSysError" with the message "catastrophic failure"
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
ActiveXContainer.Destroy;
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
Button.Top:= Height-Button.Height-8;
Button.Left:= (Width-Button.Width) div 2;
ActiveXContainer.Top:= 8;
ActiveXContainer.Left:= 8;
ActiveXContainer.Width:= Width-16;
ActiveXContainer.Height:= Button.Top-16;
end;
procedure TMainForm.ButtonClick(Sender: TObject);
begin
Motor.HWSerialNum:= 27262824; // generates a "EOleSysError" with the message "catastrophic failure"
end;
end.