xsharp.eu • How to disable option "vo16" for one entity?
Page 1 of 1

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 3:18 pm
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

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 3:36 pm
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.

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 5:23 pm
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

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 6:12 pm
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

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 6:36 pm
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.

How to disable option "vo16" for one entity?

Posted: Fri Jul 24, 2020 7:25 pm
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