How to disable option "vo16" for one entity?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

How to disable option "vo16" for one entity?

Post by leon-ts »

Hi!

The project that was transported from VO has the "vo16" (generate clipper constructors) option enabled. This option is required in this project.

But in one of the places there is a class declaration for interoperating with COM:

Code: Select all

[ComImport, Guid("17D6CCD8-3B7B-11D2-B9E0-00C04FD8DBF7")];
INTERNAL CLASS DSObjectPicker
END CLASS
The compiler throws an error:
XS0669 A class with the ComImport attribute cannot have a user-defined constructor.
I tried to change the code like this:

Code: Select all

#pragma options ("vo16", off)
[ComImport, Guid("17D6CCD8-3B7B-11D2-B9E0-00C04FD8DBF7")];
INTERNAL CLASS DSObjectPicker
END CLASS
#pragma options ("vo16", default)
But it didn’t help. The compiler issued a warning:
XS9096 Unrecognized or unsupported #pragma option value "vo16".
Is it possible to disable the "vo16" option for one entity only?

P.S. #pragma options ("option", default) reverts to the value set in the project properties or some initial value?

Best regards,
Leonid
Best regards,
Leonid
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to disable option "vo16" for one entity?

Post by Chris »

Hi Leonid,

"default " would reset the state of the option to what you have set it to in the options, which means "on" in this case. But as you saw, "vo16" is not supported to be set/reset this way, and I suspect it will be difficult to support it, because of the way the compiler works/adds the missing constructors.

Unless Robert thinks it's doable of course! Or maybe make the compiler automatically disable this, when it sees the "COMImport" attribute, again if this is possible though, I will open a ticket about this. If not, I guess the best solution is to have a separate library with /vo16 disabled and put in there this class definition.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

How to disable option "vo16" for one entity?

Post by leon-ts »

Hi Chris,
thanks for the answer!

Moving a class to another project is the first thing I thought of. But this class is very small. And I don't really want to lead a whole project for this. But your idea to automatically disable the option for classes where the COMImport attribute is specified - I like it. But since Robert is on vacation, I will try to find some ways right now. Maybe turn off the vo16 option for the project and see what happens :)

Best regards,
Leonid
Best regards,
Leonid
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

How to disable option "vo16" for one entity?

Post by robert »

Chris, Leonid,

Please create a ticket and I will try to implement this. I don't think this will be very difficult to do.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to disable option "vo16" for one entity?

Post by Chris »

Robert, added!

Leonid, That's a good point, you maybe even not need to have /vo16 enabled at all! It is meant to be used for cases like this:

Code: Select all

FUNCTION Start() AS VOID
LOCAL o AS Child
o := Child{1,2,3}

CLASS Parent
CONSTRUCTOR(a,b,c)
? a,b,c
END CLASS

CLASS Child INHERIT Parent
END CLASS
which is common in VO, to not include the Init() method of the child class, but magically pass the parameters when instantiating the object to the parent Init(). This is not allowed in .Net and you would get a compiler error in X#, but when using /vo16 the compiler automatically adds the missing constructor, including the appropriate call to the parent one.

So, yes, it's a good idea to simply disable the option and see if you get any compiler errors. If not you are safe, and if you get only a few ones, it's probably best to just go to the code and insert the missing constructors.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
leon-ts
Posts: 435
Joined: Fri Feb 03, 2017 1:43 pm

How to disable option "vo16" for one entity?

Post by leon-ts »

Chris,
thanks for the clarification!

I disabled vo16 and got 23 errors (23 classes without a constructor, and having a parent class). It's really not a lot, and I'll add a constructor to each such class. But nevertheless vo16 is very useful, because it is a good opportunity in VO/XSharp not to make a copy of the parent constructor in the inherited class, if it is not necessary. And accordingly, it is useful to be able to disable it for individual entities. If Robert can do it, it will be great.

Best regards,
Leonid
Best regards,
Leonid
Post Reply