IsInitNetwork()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

IsInitNetwork()

Post by User_Russian »

If the program several times to call the function InitNetwork(), this will result in an error.

Code: Select all

InitNetwork()
InitNetwork()
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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: IsInitNetwork()

Post by ts-soft »

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.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: IsInitNetwork()

Post by skywalk »

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 8)
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
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: IsInitNetwork()

Post by User_Russian »

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).
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: IsInitNetwork()

Post by ts-soft »

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.
Image
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: IsInitNetwork()

Post by uwekel »

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
Post Reply