[fpc-pascal] support for using an activex

Ludo Brands ludo.brands at free.fr
Mon May 23 13:44:52 CEST 2011


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




More information about the fpc-pascal mailing list