Miscellaneous questions about converting VO code to X#

This forum is meant for questions and discussions about the X# language and tools
User avatar
Kees Bouw
Posts: 133
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi Chris,

Thank you very much for your reply. Using NEW is indeed the answer, now that you mentioned this I looked at the "Class hierarchy modifiers" page in the online documentation again and it is explained there. I did see this page yesterday but I did not read it carefully because there was so much text and I missed the NEW keyword. Instead I tried OVERRIDE which did not work. Sorry about that but thank you for helping me out.
I have already created an alternative for the windows hierarchy problems. I separated the two underlying classes from the winform and use them by passing the winform object to them. So now the winform itself inherits from the Form class directly again and this works. It is quite a large application with a complicated structure and I have added and imported a lot of code, I feel that it may be difficult to isolate the problem. Also there is a fair chance that if I do that in a new test app then the problem can't be reproduced. This has happened before. I don't think it will be worth the time and effort at the moment.

Kees.
User avatar
Chris
Posts: 5080
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Kees,

Yes, OVERRIDE is for overriding a parent method which is VIRTUAL. In this case, the method is not virtual (it was done on purpose this way, so you cannot override it), so you need to define a new method as NEW, if you want to use the same name.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Antonangeli
Posts: 2
Joined: Fri Jan 31, 2025 2:32 pm
Location: Italia

Re: Miscellaneous questions about converting VO code to X#

Post by Antonangeli »

Hi all,
just installed xSharp and beginning to convert my VO code, so obviously some problem with conversion ;-)
I use INI file, and i use some function I found time ago to read/write; may be now can be done different, but ...
for read a string I use
LOCAL ptrBuffer AS PTR
aEntry := {}
ptrBuffer := MemAlloc( INI_STRING_LEN )
siLen :=GetProfileString( PSZ( sSection ), NULL_PSZ, PSZ( "" ), ptrBuffer, INI_STRING_LEN )

sValue := Left( STRING( _CAST, ptrBuffer ), siLen)
MemFree( ptrBuffer )
Now it say cannot convert type ptr to string
How to convert?

INSTANCE variables
Inside the CLASS Registro i have an instance variable, NomeChiave. I have the error
error XS0200: Property or indexer 'Registro.NomeChiave' cannot be assigned to -- it is read only 118,1 Registro.prg Registro:EsisteChiave
Why I cannot assign a value?

Thanks
Alessandro
Last edited by Antonangeli on Sat Feb 01, 2025 6:10 pm, edited 1 time in total.
User avatar
Chris
Posts: 5080
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Alessandro,

Welcome here!

For the GetProfileString() issue, you just need to define ptrBuffer AS PSZ instead of AS PTR. Then you can do a simple sValue := Psz2String( ptrBuffer ).
Also please change the PSZ() conversions to String2Psz().

For the INSTANCE variables, maybe you also have an ACCESS with the same name?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Antonangeli
Posts: 2
Joined: Fri Jan 31, 2025 2:32 pm
Location: Italia

Re: Miscellaneous questions about converting VO code to X#

Post by Antonangeli »

Thanks Chris, I'll soon try.
Yes I have an ACCESS, I need to see the value from outside the CLASS. I suppose that if there is an ACCESS is mandatory to have an ASSIGN? :-(
User avatar
Chris
Posts: 5080
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Miscellaneous questions about converting VO code to X#

Post by Chris »

Hi Alessandro,

INSTANCE variables are visible only to code of the classs (and subclasses) declaring them, so indeed if you need to have access to them from code outside of it you need to use an ACCESS and if you want to assign them, then you need an ASSIGN. Or both if you want to do both.

I just checked VO and from what I see the compiler does not complain when you try to assign a value directly to an instance variable from outside the class! But at runtime such code fails with a runtime error "No exported variable".
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Kees Bouw
Posts: 133
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Miscellaneous questions about converting VO code to X#

Post by Kees Bouw »

Hi,

Are there differences in the Error class between VO and X#? The code of the app I am working on at some point tries to access an array element that does not exist. Because it is in a BEGIN SEQUENCE construction it goes to RECOVER USING oError and there oError:Severity is 0 (ES_WHOCARES) in VO but 2 (ES_ERROR) in X#. Is it normal that it is 0 in VO or could something have been done in the VO code to make it 0, perhaps a setting? Also, in X# I don't even get to the RECOVER USING because it throws a break window first, then when I choose Continue it gets to the RECOVER.

Kees.
Post Reply