xsharp.eu • Some more pre-Xporting issues - Page 2
Page 2 of 2

Some more pre-Xporting issues

Posted: Tue Mar 02, 2021 1:21 pm
by ic2
In May 2020 you wrote about Axit:
robert wrote:DIck,

2) I will make a change to the VO SDK code. The contents of Axit() will be moved to another method (Destroy() or Close()) and Axit will call that method. You can then call that method in your code too if you want to force close the session before the garbage collector kicks in.
Robert
But in the forelast version of X# I use I still get

Error XS0245 Destructors and object.Finalize cannot be called directly. Consider calling IDisposable.Dispose if available.

on a line like oParser:Axit() .

I assumed that with the above that should no longer give an error?

Dick

Some more pre-Xporting issues

Posted: Tue Mar 02, 2021 1:31 pm
by robert
Dick,
Axit methods should not be called directly. Also not in VO. They are called by the Garbage collector when needed.

The best approach is:
- Move the body of the Axit() method to a Destroy() method
- Call Destroy() from inside Axit()
- When you want to cleanup under program control, call Destroy() and not Axit()

Robert

Some more pre-Xporting issues

Posted: Tue Mar 02, 2021 1:44 pm
by ic2
Thanks Robert.

I concluded from your earlier reply that the error would be fixed (without change), but changing Axit to Destroy in some places should be easy as well.

Dick

Some more pre-Xporting issues

Posted: Tue Apr 06, 2021 10:47 am
by HeikoP
Robert,

I am currently trying to translate a thirdparty Lib called ClassicNuVo und fighting with the Axit as Dick did.

What if the Axit Method itself calls Axit in the last line like:

Class Foo inherit DATAWINDOW

Method Axit() Class Foo
* Do some Stuff that should be moved to a Destroy() Method in x#
return super:axit()

Class Foo1 Inherit Foo
* Do some Other Stuff that should be moved to a Destroy() Method in x#
return super:axit()


If I should not call Axit directly in my code, are all axit methods from all subclassed Classes called?

Heiko

Some more pre-Xporting issues

Posted: Tue Apr 06, 2021 11:10 am
by robert
Heko,
Try this and you will see that both destructors are called, even when there is no call to the super:destructor
Robert

Code: Select all

FUNCTION Start( ) AS VOID
	Test()
	Gc.Collect()
	Console.ReadLine()

FUNCTION test AS VOID
	LOCAL oChild AS Child
	oChild := Child{}
	? oChild
	
RETURN

CLASS Parent
    DESTRUCTOR()
        ? "Inside Parent destructor"
END CLASS    

CLASS Child INHERIT Parent
    DESTRUCTOR()
        ? "Inside Child destructor"
END CLASS    


Some more pre-Xporting issues

Posted: Tue Apr 06, 2021 11:43 am
by HeikoP
Robert,

thank you for the fast response!

Heiko