Hello,
the help tells me that I cannot call a function from outside a module if I'm within a module. Ok. I have a module and want to call the errorhandler of the program, if an error occurs. I currently have an own errorhandler, which I want to get rid of, within the module. Is there a way to circumvent this restriction?
Call Function from outside of a module
Call Function from outside of a module
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
- NicTheQuick
- Addict
- Posts: 1227
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Call Function from outside of a module
You can only create an other Module "Common" which contains your Errorhandler and then call it from your Module. But you can not call anything in the main scope without working with pointers and Prototypes and such things.
Small Example:
Small Example:
Code: Select all
DeclareModule Common
Declare.i globalFunction()
EndDeclareModule
Module Common
Procedure.i globalFunction()
Debug "Error!"
EndProcedure
EndModule
DeclareModule myModule
Declare myFunction()
EndDeclareModule
Module myModule
Procedure myFunction()
Common::globalFunction()
EndProcedure
EndModule
myModule::myFunction()
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Call Function from outside of a module
The way you have it set up now seems correct. If workarounds were possible for crossing the module/caller boundary the result would be convoluted logic and you'd lose the purpose of using modules.
My advice would be, stop wanting that.I currently have an own errorhandler, which I want to get rid of, within the module.
BERESHEIT
Re: Call Function from outside of a module
Well, ok. Just to clear it up: My program writes a log onto a MySQL-Server and I wanted to include my Modules too (in case they encounter an error). That's why I need a more complex and universal ErrorHandler.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB