Forum > Packages and Libraries

Error:Automation Object Aplication

(1/4) > >>

acapa:
Hello

I´m my porting   to Lazarus (from Delphi )  software for astronomical telescopes mount control.
Its  is a standaloné windows GUI application   with  a embedded automation object compliant with ASCOM (most extended  windows com based architecture for astronomical device control and interoperation,not phone manufacturer).
http://www.ascom-standards.org/index.htm
 
I have ported graphical interface and logic for standalone operation with ease.It works fine now.
http://www.picgoto.com/
I'm using Lazarus1.0 ,2012-10-05 , FPC 2.6.0 SVN 38415 ,i386-win32-win32/64 under Windows XP sp3.

Automation objecs for it are many years working fine compiled for dellphi Delphi  and

To check for automation object under FPC I used delphi wizard to generate a type library  for  the simplest ascom device (motorized focuser).Compile it under Delphi and checked  it was accesible for  some ASCOM compliant software.

I convert it to Lazarus by  using IDE tools ,I Corrected some warnings and minor tips and got compiled aplication without error messages.
But when invoke my test application built under Lazarusaplication popups but after some time  got  this error
"Failed to load lazydriver.focuser System.RunTime.Interop.Services.COMexception(0x80080005)

Lazydriver.focuser is registered comobjet name.
I have checked windows registry for required interface , typelib ,objects and all is there in its place for this object

I really don know what Im doing wrong or it related to my FPC/ Lazarus  working version
I read  a post at this forum about  some comserv bugs correction for FPC 2.6.0.
I dont want to bother you posting my code.Only wanto to know if FPC is the actual state readyfor automation objects.
Thanks in advance
Angel Caparrós

Phil:

--- Quote from: acapa on October 10, 2012, 03:55:23 pm ---"Failed to load lazydriver.focuser System.RunTime.Interop.Services.COMexception(0x80080005)

--- End quote ---

That looks like  a .NET exception:

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.aspx

I've seen that before when .NET code traps an exception raised by a COM server.


With FPC 2.6.0, Automation on Windows works quite well as long as you're aware of the differences from Delphi. Notably you have to make sure you pass in WideString for string params. Delphi always converted AnsiStrings for you automatically, but his won't work with FPC. However, that doesn't sound like the problem you're having.

Thanks.

-Phil

acapa:
Ok Phil. Sorry , think  will have to bother a bit  with my sources :(
I not aware of these diferences.I have very little experience COM as I read once it works very close as  voodo does.
There are no string parameters  in any procedure or function excepting "createremote" method generated by delphi's wizard .at TBL unit
 
--- Code: ---unit Lazfocus_TLB;

// ************************************************************************ //
// WARNING                                                                   
// -------                                                                   
// The types declared in this file were generated from data read from a       
// Type Library. If this type library is explicitly or indirectly (via       
// another type library referring to this type library) re-imported, or the   
// 'Refresh' command of the Type Library Editor activated while editing the   
// Type Library, the contents of this file will be regenerated and all       
// manual modifications will be lost.                                         
// ************************************************************************ //

// PASTLWTR : $Revision:   1.130.1.0.1.0.1.6  $
// File generated on 08/10/2012 15:32:57 from Type Library described below.

// ************************************************************************  //
// Type Lib: C:\Archivos de programa\Borland\Delphi6\Projects\lazyfocus\lazyfocusp.tlb (1)
// LIBID: {45589AD9-8197-4925-866B-E8F510842871}
// LCID: 0
// Helpfile:
// DepndLst:
//   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
//   (2) v4.0 StdVCL, (C:\WINDOWS\system32\stdvcl40.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

uses Windows, ActiveX, Classes, Graphics,  Variants;
 

// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:       
//   Type Libraries     : LIBID_xxxx                                     
//   CoClasses          : CLASS_xxxx                                     
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                       
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  LazfocusMajorVersion = 1;
  LazfocusMinorVersion = 0;

  LIBID_Lazfocus: TGUID = '{45589AD9-8197-4925-866B-E8F510842871}';

  IID_IFocuser: TGUID = '{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}';
  CLASS_Focuser: TGUID = '{70CB798E-182E-489A-8F05-3A9F2E14C5E9}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                   
// *********************************************************************//
  IFocuser = interface;
  IFocuserDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)             
// *********************************************************************//
  Focuser = IFocuser;


// *********************************************************************//
// Interface: IFocuser
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}
// *********************************************************************//
  IFocuser = interface(IDispatch)
    ['{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}']
    procedure SetupDialog; safecall;
    function Get_Absolute: WordBool; safecall;
    function Get_MaxStep: Integer; safecall;
    procedure Set_MaxStep(Value: Integer); safecall;
    function Get_TempCompAvailable: WordBool; safecall;
    property Absolute: WordBool read Get_Absolute;
    property MaxStep: Integer read Get_MaxStep write Set_MaxStep;
    property TempCompAvailable: WordBool read Get_TempCompAvailable;
  end;

// *********************************************************************//
// DispIntf:  IFocuserDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}
// *********************************************************************//
  IFocuserDisp = dispinterface
    ['{97FBDD9A-A1B6-4663-9CEA-8DD237BA528D}']
    procedure SetupDialog; dispid 1;
    property Absolute: WordBool readonly dispid 6;
    property MaxStep: Integer dispid 7;
    property TempCompAvailable: WordBool readonly dispid 8;
  end;

// *********************************************************************//
// The Class CoFocuser provides a Create and CreateRemote method to         
// create instances of the default interface IFocuser exposed by             
// the CoClass Focuser. The functions are intended to be used by             
// clients wishing to automate the CoClass objects exposed by the         
// server of this typelibrary.                                           
// *********************************************************************//
  CoFocuser = class
    class function Create: IFocuser;
    class function CreateRemote(const MachineName: string): IFocuser;
  end;

implementation

uses ComObj;

class function CoFocuser.Create: IFocuser;
begin
  Result := CreateComObject(CLASS_Focuser) as IFocuser;
end;

class function CoFocuser.CreateRemote(const MachineName: string): IFocuser;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_Focuser) as IFocuser;
end;

end.

--- End code ---

I really have only implemented minimal class focuser interface  and coinitialize just before create AutoObjectFactory.
procedure registerthyself is comment out(uses ASCOM framework helper libraries)  because  objects registration is done at install using innosetup resources.

--- Code: ---unit Lazyi;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, Lazfocus_TLB, Dialogs;//, StdVcl;

type
  TFocuser = class(TAutoObject, IFocuser)
  protected
    function Get_Absolute: wordbool; safecall;
    function Get_MaxStep: integer; safecall;
    function Get_TempCompAvailable: wordbool; safecall;
    procedure Set_MaxStep(Value: integer); safecall;
    procedure SetupDialog; safecall;
    { Protected declarations }
  end;

implementation

uses ComServ;

function TFocuser.Get_Absolute: wordbool;
begin
  Result := True;
end;

function TFocuser.Get_MaxStep: integer;
begin
  Result := 10000;
end;

function TFocuser.Get_TempCompAvailable: wordbool;
begin
  Result := False;
end;

procedure TFocuser.Set_MaxStep(Value: integer);
begin
end;

procedure TFocuser.SetupDialog;

begin
end;

{--------------------------------------------------------------}
procedure RegisterThySelf;
{--------------------------------------------------------------}
// Test id this interface is registered int he ASCOM registry area
// If not register it so the Choose can find it and also to store persistent data
var
  ProfileObject: variant;

begin
  ProfileObject := CreateOLEObject('ASCOM.Utilities.Profile');
  ProfileObject.DeviceType := 'Focuser';
  if (not ProfileObject.IsRegistered('lazydriver.focuser')) then
  begin
    //ShowMessage('Self-Registering: ASCOM ' );
    ProfileObject.Register('lazydriver.focuser',
      'Lazarus Generated ASCOM TestFocuser');

    // set persistent default values if any
  end;//else ShowMessage('it was yet registered)
end;

initialization

  // RegisterThySelf;
  CoInitializeex(nil, COINIT_APARTMENTTHREADED);
  TAutoObjectFactory.Create(ComServer, TFocuser, Class_Focuser,
    ciMultiInstance, tmApartment);
end.

--- End code ---

Phil:

--- Quote from: acapa on October 10, 2012, 06:18:26 pm ---

--- End quote ---

Try using late binding and see if you can use very simple code to create your COM object without error. Late binding doesn't use any type library that you have to supply. See example for Word Automation server here:

http://wiki.lazarus.freepascal.org/Office_Automation

Thanks.

-Phil

acapa:
By default ASCOM helper libraries use late binding,early binding has been discouraged for lates version.
I test both and both failed with my code.
I think i will have to wait for Ludob wiki page about this subject .
Thanks a lot Phil.
Ángel.

Navigation

[0] Message Index

[#] Next page

Go to full version