By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,407 Members | 1,583 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,407 IT Pros & Developers. It's quick & easy.

Passing Parameters to COM constructors?

P: n/a
I posted this to the notes page of the COM PHP documentation... I will
post an update there if I find a solution here.

I have need for a commercial COM/DOTNET class library that requires a
paramater to be passed when the object is created.

It does not appear as though PHP allows for the instantiation of
COM/DOTNET objects that require a parameter to be passed to their
constructor... I am not sure if I am being clear, but suppose to create
a new Mercedes you would use:

$car = new COM("Car.Mercedes");

What if the constructor for that class required that you specified a
model of the car in order to instantiate it?

e.g.:

$car = new COM("Car.Mercedes('SL600')");

....or something like that. Is it possible? Is there a work-around?

Thanks,

Matt

Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matt,
e.g.:

$car = new COM("Car.Mercedes('SL600')");

...or something like that. Is it possible? Is there a work-around?

I do not know if it is possible since I haven't used com for a project
since 2001. My first thought is no. My thought process is basically
that PHP is calling the com object and allocating the memory for the com
object but not exactly maintaining it as an object like PHP would.

However, most languages will allow you to call the constructor after you
have initialized the object (depending). However it is not known as the
best practice but yet again workarounds are not best practice either.

You might be able to find something that deals with this in the PEAR
library, however without spending time looking for it I am unsure.

Mike
Jul 17 '05 #2

P: n/a
There is such a thing as a COM constructor? The standard way to create
an object in COM is to get its class factory, then call
TClassFactory::CreateInstance, which doesn't accept initialization data.

Jul 17 '05 #3

P: n/a
Thanks guys, for the info. I am actually trying to get a 3rd party
DOTNET component working in PHP. The main class of this component
requires me to pass a parameter to the constructor (see my example
above) -- sorry that I used COM in the example instead of DOTNET- I was
just trying to be demonstrative and thought that both approached would
work the same way.

As it stands, it looks as though I am SOL in trying to use this product
(Aspose Powerpoint) with PHP :( I am really hoping there is a way!

Jul 17 '05 #4

P: n/a
NC
mheyd...@yahoo.com wrote:

I am actually trying to get a 3rd party DOTNET component working
in PHP. The main class of this component requires me to pass a
parameter to the constructor .... As it stands, it looks as though I am SOL in trying to use this
product (Aspose Powerpoint) with PHP :( I am really hoping there
is a way!


There might be, but most of the work is going to be done outside
PHP.

I am guessing you are trying to work with the Presentation class.
If I remember correctly, this class is not inheritable, so you
can't extend it. You need to create a container object for the
Presentation object. In VB.NET, it could look like this:

Public Class PresentationContainer
Public ContainedPresentation As Aspose.PowerPoint.Presentation
Public Sub New()
Set ContainedPresentation to Nothing
End Sub
Public Sub InitPresentation(file As String)
Me.ContainedPresentation = New Aspose.PowerPoint.Presentation(file)
End Sub
End Class

Then you compile the container and access the Presentation from
PHP as PresentationContainer::ContainedPresentation.

Cheers,
NC

Jul 17 '05 #5

P: n/a
Wow.. such a simple idea, but a perfect solution. With a little
tweaking to your code I have succesfully done what I set out to do:
create an instance of that *&%^ presentation object :-)

I will post more formal directions & sample code to this thread once I
work out a few more details using .NET with PHP. For example, the
component returns a .net Image object. Well, if I want to save this
image to a file, I can call ImageObject.Save(Filename, Format) but the
Format is a .net enumeration that I can't seem to access from PHP (nor
can I find the actual values for this enumeration).

Thank you very much, NC, for your help on this- I knew there was a way!

Jul 17 '05 #6

P: n/a
NC
mh******@yahoo.com wrote:

With a little tweaking to your code I have succesfully done
what I set out to do: create an instance of that *&%^
presentation object :-)
:)
I will post more formal directions & sample code to this thread
once I work out a few more details using .NET with PHP. For example,
the component returns a .net Image object. Well, if I want to save
this image to a file, I can call ImageObject.Save(Filename, Format)
but the Format is a .net enumeration that I can't seem to access
from PHP (nor can I find the actual values for this enumeration).


Again, consider implementing this functionality inside the
container object and expose to PHP only things that you can't
mess up. Also, I have a different recollection of the Image::Save()
method syntax: the second argument is not an enumeration, but an
ImageFormat object...

Cheers,
NC

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.