[fpc-pascal] support for using an activex

Ludo Brands ludo.brands at free.fr
Mon May 23 15:51:29 CEST 2011


When using CreateOleObject you are using what they call late binding. During
compile time you don't know what methods the object support. The object is
queried for its interfaces, methods and datatypes at runtime. No header file
translations needed except when custom data types are defined. The use of
variants is definitely recommended. Variants are mandatory to store the
reference to the OleObject. 

If you know the CLSID of the ACTIVEX Object (should be in the header file
describing the interface) and the object is registered you can find the
ProgID easily in the registry. For Word.Application
{000209FF-0000-0000-C000-000000000046}  you find it under
HKEY_CLASSES_ROOT\CLSID\{000209FF-0000-0000-C000-000000000046}\VersionIndepe
ndentProgID. 
If you have the sources of the ActiveX Object you should find the progID in
there also.

Don't know if your ActiveX sends events that you want to catch. Creating
"event sinks" is relatively complex. 

Com reference information can be found here:
http://msdn.microsoft.com/en-us/library/ms221375.aspx

Ludo


-----Message d'origine-----
De : fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Roberto
Padovani
Envoyé : lundi 23 mai 2011 15:07
À : FPC-Pascal users discussions
Objet : Re: RE : [fpc-pascal] support for using an activex


Wow, this sound like good news!

The activex I have is not visual; it is "simply" a class that creates a
thread in which a physical device is controlled through a serial port, with
a particular protocol. The class then has methods like "Open channel", "Read
Mesaure", and so on.

Is there any documentation I can read? I think I have to translate some
header files to understand the exchanged data...or shall I use only variant
?
I suppose I have to change   MSWord :=
CreateOleObject('Word.Application');   into something related to my
class; where do I discover the "name.surname" ?

Thanks all!


2011/5/23 Ludo Brands <ludo.brands at free.fr>:
> If the activex is not a visual control that you want to put on a LCL 
> form you can use CreateOleObject. Note that you don't load ActiveX 
> dll's directly. ActiveX objects are registered in Windows by the 
> installer or manually with Regsvr32.exe. Windows loads the ddl for you 
> when you call CreateOleObject. Ole components are reference counted 
> and released when not used anymore.
>
> Here is a simple sample program when you have MS Word installed.
>
>
> program Project1;
>
> {$mode objfpc}{$H+}
>
> uses
>  {$IFDEF UNIX}{$IFDEF UseCThreads}
>  cthreads,
>  {$ENDIF}{$ENDIF}
>  Classes
>  { you can add units after this }
>  ,sysutils,ComObj;
>
> {$R *.res}
>
> var
>  MSWord,WordDoc,WordPara: Variant;
> begin
>  MSWord := CreateOleObject('Word.Application');
>  MSWord.Visible:=true;
>  WordDoc := MSWord.Documents.Add;
>  WordDoc.Activate;
>  WordPara := WordDoc.Content.Paragraphs.Add;
>  WordPara.Range.Text := 'Hello World!';
>  WordDoc.SaveAs('C:\Test.Doc');
>  Sleep(10000);
>  WordDoc.Close(False);
>  MSWord.Quit;
>  MSWord := Unassigned;
>  WordDoc := Unassigned;
>  WordPara := Unassigned;
> end.
>
>
>
> -----Message d'origine-----
> De : fpc-pascal-bounces at lists.freepascal.org
> [mailto:fpc-pascal-bounces at lists.freepascal.org] De la part de Roberto 
> Padovani Envoyé : lundi 23 mai 2011 12:24
> À : FPC-Pascal users discussions
> Objet : [fpc-pascal] support for using an activex
>
>
> Hi List!
>
> I looked around the archives and forum, but I didn't come up with a 
> clear answer. Besides, I'm not expert of the win32 and COM world.
>
> If I am given an ActiveX, with source code included, is it possible to 
> using from a freepascal / lazarus app like any other dll? I mean 
> loading the dll, instantiating the object and calling some methods.
>
> If so, can anyone point me to some documentation or example?
>
> Thanks a lot,
>
>  Roberto
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org 
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list