fbpx

Calling a class that has no public constructor

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 11 months ago #1 by Jean-Pierre Maertens
Calling a class that has no public constructor was created by Jean-Pierre Maertens
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,

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #2 by Phil Hepburn
Replied by Phil Hepburn on topic Calling a class that has no public constructor
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.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #3 by Robert van der Hulst
Replied by Robert van der Hulst on topic Calling a class that has no public constructor
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

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 11 months ago #4 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
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.

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 11 months ago #5 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
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'

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #6 by George Theopoulos
Replied by George Theopoulos on topic Calling a class that has no public constructor
Jean-Pierre,

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

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 11 months ago #7 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
Thank you, but does not work either.

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #8 by Fabrice Foray
Replied by Fabrice Foray on topic Calling a class that has no public constructor
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

Please Log in or Create an account to join the conversation.

More
1 year 11 months ago #9 by Chris Pyrgas
Replied by Chris Pyrgas on topic Calling a class that has no public constructor
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

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 11 months ago #10 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
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

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #11 by Chris Pyrgas
Replied by Chris Pyrgas on topic Calling a class that has no public constructor
Hi Jean-Pierre,

Ahh, I love seeing c# code, it is so clear to read...

Well, this method declaration in the c# code:

public void FromVegas(Vegas vegas)

defines the FromVegas() method with one parameter, named vegas and its type is Vegas (I know...). The equivalent VO/x# definition would be:

METHOD FromVegas(vegas AS Vegas) AS VOID

So the c# code MessageBox.Show(vegas.Version) operates on the "vegas" local (parameter), not on the "Vegas" (with capital V) type itself. In VO/x# syntax again, this would be:

MessageBox.Show(vegas:Version)

so this should compile fine in x:

METHOD FromVegas(vegas AS Vegas) AS VOID
MessageBox.Show(vegas:Version)

or I would suggest to change the parameter name to something else, so it is more clear what the code does, something like (for example):

METHOD FromVegas(oVegas AS Vegas) AS VOID
MessageBox.Show(oVegas:Version)

the reason why you get a compiler error in this code:

FUNCTION start() AS VOID
MessageBox.Show(vegas:version)

is that there is no variable named "vegas" defined in this function, so the compiler thinks that you are attempting to call a static method on the same named "Vegas" class itself. If you had defined a "LOCAL vegas AS Vegas", then it would again compile fine, but would obviously fail at runtime, because "vegas" (the var...) would be NULL.

Chris

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 10 months ago #12 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
Thank you very much Chris !! This compiles without errors.

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #13 by Phil Hepburn
Replied by Phil Hepburn on topic Calling a class that has no public constructor
Hi you guys,

Now you may understand why I can't count properly any more!

Or why I code like NASA folks programmer their Lunar/Mars probes ;-0)

Recently I spent a few consecutive days translating code directly from C# into X#. It does get easier - BUT - at least my C# code did not have the irritating "vegas / Vegas" sorts of confusion.

Personally I find this (too often) common style of coding 'name choice' VERY unclear, even when it is syntactically correct - or should that be semantically correct ?

Either way, onward and upward, and X# syntax for Leonardo and his mates !!!

Regards,
Phil.

P.S. I really use the single dot a lot in my CORE apps - so much easier (and possibly sloppier too).

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #14 by Frank Maraite
Replied by Frank Maraite on topic Calling a class that has no public constructor
Hi Jean-Pierre,

from Vegas pro Scripting API

from here
www.vegascreativesoftware.com/de/downloads/#c24726
download link
www.vegascreativesoftware.com/fileadmin/...as_scripting_api.zip

Vegas Class
Represents the Vegas application. You can get access to this singleton object via DomainManager.VegasDomainManager.GetVegas()

HTH

Frank

Please Log in or Create an account to join the conversation.

  • Jean-Pierre Maertens
  • Jean-Pierre Maertens's Avatar Topic Author
  • Offline
More
1 year 10 months ago #15 by Jean-Pierre Maertens
Replied by Jean-Pierre Maertens on topic Calling a class that has no public constructor
Thank you Frank ! I already made a dll that can be called by Sony Vegas, and thanks to the help I got on this forum, it works (does nothing great for the moment ;-))
Wish I had the professional version of Visual Studio, because the Community version doesn't have the option to start an external program through the debugger, and neither has Xide I think. As I am a retired programmer I can no longer deduct the costs of buying such software (650 €) from my tax bill.

Please Log in or Create an account to join the conversation.

More
1 year 10 months ago #16 by Robert van der Hulst
Replied by Robert van der Hulst on topic Calling a class that has no public constructor
Jean-Pierre,

In XIDE you can connect to an external process to start debugging your code inside another app:
- Set a breakpoint in your code
- Choose 'Attach to Process' in the Debug menu
Then the debugger should stop as soon as your breakpoint is reached.


Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.