B4J Tutorial Logserver using in multiple modules / classes.

Discussion in 'B4J Tutorials' started by stevel05, Apr 30, 2018.

  1. stevel05

    stevel05 Expert Licensed User

    LogServer can only accept one connection at a time, therefore we should not initialize the LogServerClient multiple times to access it from different classes / modules.

    Instead, declare it as a Public Process_Global and initialize the LogServerClient in your Main module, then access it from Main in other modules you want to use it from.

    Code:
    Main.LS.Message("Send Message")
    If like me, you want to save typing, declare it as a Private Global in the module you want to access it from, and in the initialize sub of the class, or before you first access it in a module, assign the Public variable from Main to the Private Global in the module.

    In Main :

    Code:
    Sub Process_Globals
    Private fx As JFX
        
    Private MainForm As Form
        
        
    'Create a Global variable to point to the LogServerClient
        Public LS As LogServerClient
    .
    .
    .
    End Sub
    In other modules :

    Code:
    Sub Class_Globals
        
    Private fx As JFX
        
    Private LS As LogServerClient
    End Sub

    Public Sub Initialize

    LS = Main.LS
    .
    .
    .
    End Sub
     
    Erel likes this.
Loading...