Override of function?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Override of function?

Post by ic2 »

In VO we have written our own version of LoadResString. From X# 2.13 this gives WarningXS9043 'LoadResString' is ambiguous.
Not sure why it didn't do that earlier, because is a correct warning.

However, as LoadResString is Init generated with every caption, it is not simple to replace. Can override be used in some way?

Kees tried

Code: Select all

PUBLIC OVERRIDE FUNCTION LoadResString(uDef AS USUAL , uid AS USUAL , uModule AS USUAL ) AS STRING


and got:

Error XS9002 Parser: unexpected input 'FUNCTION'


Dick
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Override of function?

Post by robert »

Dick,

You cannot override functions like this.
Functions become static methods in a static class.
Static classes cannot inherit from another class.
So there is no function to override.

I understand that you want to hide the warning message.

The only thing that I can think of is the following:
- we add an attribute to the X# runtime. Something like the SilentlyReplaceAttribute
- you mark your code with this attribute

Code: Select all

[SilentlyReplace];
PUBLIC FUNCTION LoadResString(uDef AS USUAL , uid AS USUAL , uModule AS USUAL ) AS STRING
- when the compiler detects this attribute then it uses the function or method marked with the attribute without "nagging".

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
VR
Posts: 101
Joined: Sun Aug 23, 2020 3:07 pm
Location: Italy

Override of function?

Post by VR »

If you just want to get rid of the warning, you can also put it's code on the list of the ignored warnings. But this of course get's rid of all the XS9043 warnings, not just the one for the LoadResString function
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Override of function?

Post by ic2 »

Hello Robert, Volkmar,
robert post=23517 userid=253 wrote: I understand that you want to hide the warning message.

The only thing that I can think of is the following:
- we add an attribute to the X# runtime. Something like the SilentlyReplaceAttribute
- you mark your code with this attribute

Code: Select all

[SilentlyReplace];
PUBLIC FUNCTION LoadResString(uDef AS USUAL , uid AS USUAL , uModule AS USUAL ) AS STRING
- when the compiler detects this attribute then it uses the function or method marked with the attribute without "nagging".
This sounds very good if that's not too much work. Indeed I don't want to completely hide the warning and a quick rename is not the solution given the number of "rerouted" loadressting's in (generated) code.

Thanks,

Dick
FFF
Posts: 1535
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Override of function?

Post by FFF »

ic2 post=23524 userid=455 wrote:given the number of "rerouted" loadressting's in (generated) code.
Dick
Renaming was my first thought, when i read your post, then saw the "generated" part... But the generation is to follow some definition, as e.g. in VO's CAVOWed.tpl.
Is this done otherwise in VS? If not, you could edit these files once.
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Override of function?

Post by Chris »

Hi Karl,

The code generation for LoadResString() is hardcoded in both VS and XIDE, which I think is the case also in VO (since there's no entry in the template files for that).
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Override of function?

Post by robert »

Guys,

I'll add the attribute for the next build and will tell the compiler to silently choose the alternative that is marked with the attribute (if any).
In retrospect the name "SilentlyReplaceAttribute" should probably be something like "PreferredOverloadAttribute"

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

Override of function?

Post by Chris »

Robert,

Yeah, PreferredOverloadAttribute sounds better!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
VR
Posts: 101
Joined: Sun Aug 23, 2020 3:07 pm
Location: Italy

Override of function?

Post by VR »

If this new Attribute is introduced, it might also be a good idea to have some check in the compiler, that there is only one "PreferredOverload" per function overload in a solution and all it's dependencies...
Post Reply