473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Passing Parameters to COM constructors?

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
6 2042
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Doug | last post by:
I have probably a simple question: How do I declare a class to have a parameter of a certain type? I want to declare frmAppointment to pass a parameter of DateTime so when I call it, I call do...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
19
by: Daniel Billingsley | last post by:
I think it's really nice to be able to do code like someVariable = someMethod(new SomeClass("some text")); However, as method signatures are number and types of parameters, you're limited to...
17
by: Ben R. | last post by:
I'm reading about attribute classes and specifically, named versus positional parameters. Was this implimented instead of multiple constructors for flexibility or is there another reason I'm...
2
by: Colin McGuire | last post by:
Hi everyone. This is a question and something new and neat I have found. But to recap - a few months back I learnt about overloading, how to create the same method with a different signature. With...
3
by: Kürşat | last post by:
Hi, I want to set a plug-in architecture and need object creation at run-time. I can create objects at run-time using Activator.CreateObject method, so far so good. But some objects have...
5
by: Chris Ashley | last post by:
I'm getting a little confused at the behaviour of C# with one of my class constructors. A code example will probably help: public class RawBitmap { internal BITMAPFILEHEADER fileHdr; internal...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
7
by: =?iso-8859-1?Q?S=F8ren_M._Olesen?= | last post by:
Hi How do I pass a complex type to a webservice?? What I have is a Class 'MyComplexClass' which lives in it's own dll/namespace. I'd like to pass this class to my webmethod: <WebMethod()_...
6
by: raylopez99 | last post by:
This thread is about how variables or parameters (including objects) are passed between forms (namely, using parameterized constructors, e.g., to pass an int between forms (e.g., a calling form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.