Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Posts: 1520 Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia
Post
by User_Russian » Sun Feb 17, 2013 11:55 am
If the program several times to call the function InitNetwork(), this will result in an error.
When the program consists of separate modules, then we have to somehow check if already invoked the function or not.
Need a function, for example, IsInitNetwork()
Code: Select all
InitNetwork().
If IsInitNetwork()=0
InitNetwork()
EndIf
ts-soft
Always Here
Posts: 5756 Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany
Post
by ts-soft » Sun Feb 17, 2013 1:50 pm
WorkAround:
Code: Select all
CompilerIf Defined(InitNetworkEx, #PB_Procedure) = #False
Procedure InitNetworkEx()
Static IsInit = #False
If Not IsInit
IsInit = InitNetwork()
EndIf
ProcedureReturn IsInit
EndProcedure
Macro InitNetwork()
InitNetworkEx()
EndMacro
CompilerEndIf
InitNetwork()
InitNetwork()
Or in this way:
Code: Select all
Import ""
PB_Network_Objects
EndImport
If Not PB_Network_Objects
InitNetwork()
EndIf
PureBasic 5.73 |
SpiderBasic 2.30 |
Windows 10 Pro (x64) |
Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
skywalk
Addict
Posts: 4211 Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA
Post
by skywalk » Sun Feb 17, 2013 5:09 pm
My network structure includes an InitNetwork Flag, but this is cool.
ts-soft wrote: WorkAround:
Code: Select all
Import ""
PB_Network_Objects
EndImport
If Not PB_Network_Objects
InitNetwork()
EndIf
ts-soft is the King of undocumented PB goodies
Now I need KCC to make me an awesome GIF
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User_Russian
Addict
Posts: 1520 Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia
Post
by User_Russian » Sun Feb 17, 2013 5:26 pm
ts-soft wrote: Import ""
PB_Network_Objects
EndImport
Linker error:
POLINK: error: Unresolved external symbol '_PB_Network_Objects'.
POLINK: fatal error: 1 unresolved external(s).
ts-soft
Always Here
Posts: 5756 Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany
Post
by ts-soft » Sun Feb 17, 2013 5:34 pm
In PB5.10 the objectname is changed, so use this one:
Code: Select all
CompilerIf #PB_Compiler_Version > 500
Macro _NetworkObject_
PB_Server_Objects
EndMacro
CompilerElse
Macro _NetworkObject_
PB_Network_Objects
EndMacro
CompilerEndIf
Import ""
_NetworkObject_
EndImport
If Not _NetworkObject_
InitNetwork()
EndIf
PureBasic 5.73 |
SpiderBasic 2.30 |
Windows 10 Pro (x64) |
Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
uwekel
Enthusiast
Posts: 740 Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)
Post
by uwekel » Sun Feb 17, 2013 9:39 pm
I do it that way:
Code: Select all
DisableDebugger
InitNetwork()
EnableDebugger
Best regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2