Passing Parameters to COM constructors?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mheydman@yahoo.com

    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.Merced es");

    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.Merced es('SL600')");

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

    Thanks,

    Matt

  • Mike Willbanks

    #2
    Re: Passing Parameters to COM constructors?

    Matt,[color=blue]
    > e.g.:
    >
    > $car = new COM("Car.Merced es('SL600')");
    >
    > ...or something like that. Is it possible? Is there a work-around?[/color]


    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

    Comment

    • Chung Leong

      #3
      Re: Passing Parameters to COM constructors?

      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.

      Comment

      • mheydman@yahoo.com

        #4
        Re: Passing Parameters to COM constructors?

        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!

        Comment

        • NC

          #5
          Re: Passing Parameters to COM constructors?

          mheyd...@yahoo. com wrote:[color=blue]
          >
          > 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[/color]
          ....[color=blue]
          > 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![/color]

          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 PresentationCon tainer
          Public ContainedPresen tation As Aspose.PowerPoi nt.Presentation
          Public Sub New()
          Set ContainedPresen tation to Nothing
          End Sub
          Public Sub InitPresentatio n(file As String)
          Me.ContainedPre sentation = New Aspose.PowerPoi nt.Presentation (file)
          End Sub
          End Class

          Then you compile the container and access the Presentation from
          PHP as PresentationCon tainer::Contain edPresentation.

          Cheers,
          NC

          Comment

          • mheydman@yahoo.com

            #6
            Re: Passing Parameters to COM constructors?

            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.Sav e(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!

            Comment

            • NC

              #7
              Re: Passing Parameters to COM constructors?

              mheydman@yahoo. com wrote:[color=blue]
              >
              > With a little tweaking to your code I have succesfully done
              > what I set out to do: create an instance of that *&%^
              > presentation object :-)[/color]

              :)
              [color=blue]
              > 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.Sav e(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).[/color]

              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

              Comment

              Working...