xsharp.eu • Calling a class that has no public constructor
Page 1 of 2

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 10:53 am
by Anonymous
How can I solve this ? The Vegas class has no public constructor

#using ScriptPortal.Vegas

FUNCTION Start( ) AS VOID
LOCAL oVegas AS Vegas

oVegas:=Vegas{}

error XS1729: 'Vegas' does not contain a constructor that takes 0 arguments

Vegas is a class part of the video-edting software Sony Vegas,

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 11:53 am
by Phil Hepburn
The message says it does not have a constructor which takes zero arguments - BUT - the does not mean that it has no constructor.

Try supplying one or more nulls !?

Just a thought off the top of my head.

Cheers,
Phil.

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 12:11 pm
by robert
JP,

What Phil said, or there is a static method in the class or a static property that allows you to create/access instances.

Robert

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 12:17 pm
by jpmaertens
When I right click on the Vegas{} to see the parameters, it says it has no public constructor.

Of course I tried with 1...4 null parameters, the resulting error is : it has no constructor with 1..4 parameters.

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 12:26 pm
by jpmaertens
I tried to do this simple test

cTest:=Vegas:Version

the Xide interface shows all methods and accesses of Vegas when I type the :

This however gives another compiler error :

error XS0120: An object reference is required for the non-static field, method, or property 'Vegas.Version'

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 3:56 pm
by George
Jean-Pierre,

you have to type:
cTest := Vegas.Version to access a Static-Class member

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 4:10 pm
by jpmaertens
Thank you, but does not work either.

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 4:33 pm
by Fabrice
Hi Jean-Pierre,
that's the kind of scenario where you don't need to call the constructor, either :
. because you must use a static Method that will always return the same Vegas object that is created internally, so you have a Singleton
. because you will receive the Vegas object when your code is called by the application that will consume your extension (Here that's my favorite option)

Hope this helps.

Cheers,
Fabrice

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 4:51 pm
by Chris
Hi Jean-Pierre,

It is a bug of XIDE that it shows members on "Vegas:", ":" is used on instances of types only, is not valid on types themselves, so this should show nothing. But try a dot instead, to see the static members of the class, with "Vegas.", does the list now contain an entry like "Create", "CreateInstance" or something like that?

In any case, as others already pointed out, the fact that there does not exist a public constructor means that the developer of the class did not intend (and does not allow) to let the programmer create an instance of this class directly. Instead they must have provided another means of getting such an instance, but it's too hard to say how, without some documentation or without looking at the full contents of the dll in a disassembler like ILSpy or Reflector. Is there some documentation for this library? If not, would it be possible to zip and upload it for us to have a look?

Chris

Calling a class that has no public constructor

Posted: Wed Feb 22, 2017 5:12 pm
by jpmaertens
Hello Fabrice,

I was just trying to translate a c# sample.
this is the sample :

using System;
using System.Text;
using System.Windows.Forms;
using ScriptPortal.Vegas;

namespace SampleScript1
{
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
MessageBox.Show(vegas.Version);
}
}
}

That is all. I can't generate code to run inside Vegas, when I have compiler errors. It is also very puzzling because when I type Vegas: the IDE shows me all the methods and accesses of Vegas.


#using System
#using System.Windows.Forms
#using ScriptPortal.Vegas


FUNCTION start() AS VOID

MessageBox.Show(Vegas:version) // error XS0120: An object reference is required for the non-static field, method, or property 'Vegas.Version'

RETURN