Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Delphi ActiveX OCX, how to get access to public variables without chaning the CLSID

Hello all,

I have an ActiveX object  and I want to know how I can get access to its publicly declared variables.  This OCX is already deployed so I don't want to make changes that would affect the CLSID.  

If I embed this object in Microsoft PowerPoint I only get access to the published properties and public methods.  I don't see the public variables from the design mode in PowerPoint.  What changes can be made to access these public variables without causing a change in the CLSID?  

Thank you.
0
cyman73
Asked:
cyman73
  • 3
  • 2
1 Solution
 
ziolkoCommented:
go to project -> import TypeLibrary or Component -> Import Component -> ActiveX (BDS2006)
delphi will generate everything You need.

ziolko.
0
 
cyman73Author Commented:
Thank you Ziolko for the suggestion.  How does this help with the ActiveX deployment?  How does this help me with Powerpoint?









0
 
ziolkoCommented:
ActiveX components are deployed by using regsv32 xxxx.ocx or xxxx.dll this makes it accessible by delphi type library importer.
when You import type library delphi generates xxxx_TLB.pas file with including all objects and its properties that ActiveX export
those objects are accessible as interfaces or regular delphi objects (if You select Genreate Component Wrapper during import).

If it comes to PowerPoint, check "Server" tab on Your component palette TPowerPointApplication should be there.

ziolko.
0
 
cyman73Author Commented:
Thanks,

So when you say ..."including all objects and its properties that ActiveX export
those objects are accessible as interfaces or regular delphi objects (if You select Genreate Component Wrapper during import).", this means that the object's properties are not available if the Component Wrapper is not specifically exposing them?

I have the MyActiveX.ocx, I open Microsoft Powerpoint and I place this ActiveX on a slide, now I want to setup the object's properties so I easily have access to them via the Properties Window.  But I also want access to this object's public variables.  So if the Component Wrapper did not expose these variables, you are saying that I cannot get to them otherwise?

If one of the properties was a public boolean bValid I would like to be able to say MyActiveX.bValid := True;, I can't access it unless this was defined as in the properties section?

Thank you.
0
 
ziolkoCommented:
Only way to access public variables is via properties, as I understand MyActiveX.ocx is some library that You wrote. open MyActiveX.tlb editor and add some properties (read/write) delphi will generate Get_ Set_ methods implement them to read/write You variables, this should look like this

in xxx_TLB.pas file:
type
   
     ISampleobject2 = interface(IDispatch)
       ['{FC9618C2-E6F4-4425-AADB-239781C10EDE}']
       function Get_MyProperty: Integer; safecall;
       procedure Set_MyProperty(Value: Integer); safecall;
       property MyProperty: Integer read Get_MyProperty write Set_MyProperty;
    end;


in implementation file:

interface

uses
  ComObj, ActiveX, Project1_TLB, StdVcl;

type
  TSampleobject2 = class(TAutoObject, ISampleobject2)
  private
    FPublicVariable: Integer; <- it's in private section but thanks to property it's accessible as public one
  protected
    function Get_MyProperty: Integer; safecall;
    procedure Set_MyProperty(Value: Integer); safecall;

  end;

implementation

uses ComServ;

function TSampleobject2.Get_MyProperty: Integer;
begin
  Result := FPublicVariable;
end;

procedure TSampleobject2.Set_MyProperty(Value: Integer);
begin
  FPublicVariable := Value;
end;

initialization
  TAutoObjectFactory.Create(ComServer, TSampleobject2, Class_Sampleobject2,
    ciMultiInstance, tmApartment);
end.

ziolko.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now