Some more pre-Xporting issues

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

Some more pre-Xporting issues

Post 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
User avatar
robert
Posts: 4348
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Some more pre-Xporting issues

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1822
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Some more pre-Xporting issues

Post 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
HeikoP
Posts: 48
Joined: Mon May 30, 2016 4:19 pm
Location: Germany

Some more pre-Xporting issues

Post 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
User avatar
robert
Posts: 4348
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Some more pre-Xporting issues

Post 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    

XSharp Development Team
The Netherlands
robert@xsharp.eu
HeikoP
Posts: 48
Joined: Mon May 30, 2016 4:19 pm
Location: Germany

Some more pre-Xporting issues

Post by HeikoP »

Robert,

thank you for the fast response!

Heiko
Post Reply