Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

How can I display a SplashSreen? 13 Jul 2020 09:09 #15188

  • Frank Müßner
  • Frank Müßner's Avatar
  • Topic Author


  • Posts: 259
  • Hello,

    I try to display a splash screen at startup. The SplashScreen is a DevExpress component.
    So that the SplashSreen is updated, I think it has to be started in a separate task.
    Unfortunately I get this error:
    System.ArgumentNullException: Der Wert darf nicht NULL sein.
    Parametername: start
       bei System.Threading.Thread..ctor(ThreadStart start)
       bei XApp.Start(__Usual[] Xs$Args) in F:\VS\Visual Studio 2017\XSWinQuickDev20\VOMDIApp1\Start.prg:Zeile 21.
       bei VOMDIApp.Exe.Functions.Start() in F:\VS\Visual Studio 2017\XSWinQuickDev20\VOMDIApp1\Start.prg:Zeile 8.

    But the SplashSreen is Show.

    My code is:
    USING System
    USING System.Threading.Tasks
    [STAThread];
    FUNCTION Start() AS INT
    	LOCAL oXApp AS XApp
    	TRY
    		oXApp:=XApp{}
    		oXApp:Start()
            
    	CATCH oException AS Exception
    		ErrorDialog(oException)
    	END TRY
    RETURN 0
    
    CLASS XApp INHERIT App
    
    	METHOD Start() 
    	LOCAL oMainWindow AS StandardShellWindow
            local i AS DWORD
            local thread1 as System.Threading.Thread
    
            thread1:=System.Threading.Thread{XApp:ShowSreen()}
            thread1:Start()
            
            //Do Some Start routine
            For I:=1 to 100
                sleep(50)
            NEXT
            
            //how to close the SplashSreen Form? Kill the Task?
            thread1:Abort() 
            
    	oMainWindow:Show(SHOWCENTERED)
            
            local Nw1 as Window1
            Nw1:=Window1{oMainWindow}
            Nw1:Show()
            
    	SELF:Exec()
            
        RETURN NIL
        
        Static method ShowSreen() as System.Threading.ThreadStart
        Local sp as AuftragSQLKasseCSWinForms.SplashScreen1        
        sp:=AuftragSQLKasseCSWinForms.SplashScreen1{}    
        sp:Show()
           
        return 
        
    END CLASS
    

    What am i thinking wrong?

    VS2019 / X#2.4a

    Regards, Frank

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 09:17 #15189

    • SHirsch
    • SHirsch's Avatar


  • Posts: 266
  • Hallo Frank,

    try this:
    thread1:=System.Threading.Thread{ThreadStart{ShowSreen}}
    ...
    
    method ShowSreen() as void
        Local sp as AuftragSQLKasseCSWinForms.SplashScreen1        
        sp:=AuftragSQLKasseCSWinForms.SplashScreen1{}    
        sp:Show()
    return 
    
    

    Stefan

    Please Log in or Create an account to join the conversation.

    Last edit: by SHirsch. Reason: not checked what ShowScreen returned

    How can I display a SplashSreen? 13 Jul 2020 09:34 #15190

    • Frank Müßner
    • Frank Müßner's Avatar
    • Topic Author


  • Posts: 259
  • Hi Stefan,

    Thanks for your two examples.

    I have change:
    thread1:=System.Threading.Thread{ShowSreen}
    ...
    Static method ShowSreen() as void
    Local sp as AuftragSQLKasseCSWinForms.SplashScreen1        
    sp:=AuftragSQLKasseCSWinForms.SplashScreen1{}    
    sp:Show()

    Error:
    XS1503	Argument 1: cannot convert from 'method' to 'System.Threading.ThreadStart'	

    thread1:=System.Threading.Thread{ThreadStart{ShowSreen}}
    ...
    method ShowSreen() as void
    Local sp as AuftragSQLKasseCSWinForms.SplashScreen1        
    sp:=AuftragSQLKasseCSWinForms.SplashScreen1{}    
    sp:Show()

    Error:
    XS0123	No overload for 'ShowSreen' matches delegate 'System.Threading.ThreadStart'	

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 11:19 #15191

    • Chris
    • Chris's Avatar


  • Posts: 3751
  • Hi Frank,

    Most likely you have the /vo5 compiler option enabled, and this options makes methods without parameters to be emitted as CLIPPER methods, which are indeed incompatible with the ThreadStart delegate and this is why you get that error message.

    Please add the STRICT clause to the method declaration and it should work fine:

    Static method ShowSreen() as void STRICT
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 11:39 #15193

    • Frank Müßner
    • Frank Müßner's Avatar
    • Topic Author


  • Posts: 259
  • Hi Chris,

    you are right, the option /VO5 is activated.
    I no longer get an error message, and the method ShowSreen() is called , but the SplashSreen is not displayed either. Another tip on what I'm doing wrong?
    My final Code:
    CLASS XApp INHERIT App
    
    	METHOD Start() 
    		LOCAL oMainWindow AS StandardShellWindow
            local i AS DWORD
            
            oMainWindow := StandardShellWindow{}
            local thread1 as System.Threading.Thread
            thread1:=System.Threading.Thread{ThreadStart{ShowSreen}}
            thread1:Start()
            
            //Do Some Start routine
            For I:=1 to 100
                sleep(50)
               
            NEXT
            
            thread1:Abort() 
            
    		oMainWindow:Show(SHOWCENTERED)
            
            local Nw1 as Window1
            Nw1:=Window1{oMainWindow}
            Nw1:Show()
            
    	    SELF:Exec()
            
        RETURN NIL
        
    Static method ShowSreen() as void STRICT
        Local sp as AuftragSQLKasseCSWinForms.SplashScreen1        
        sp:=AuftragSQLKasseCSWinForms.SplashScreen1{}    
        sp:Show()
    return 
           
        return 
        
    END CLASS

    FRank

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 15:15 #15197

    • Chris
    • Chris's Avatar


  • Posts: 3751
  • Hi Frank,

    Maybe you need to use ShowDialog() instead of Show()? At least for regular forms, you'd need to use ShowDialog(), not sure how this particular component works.

    If that still doesn't work, try using a simple regular (empty) Form instead, does it work with that? If yes, then we need to find what is special about this component.

    But a general comment, I do not think you need a thread anyway. You'd need a thread in order to do things in parallel, but when you just want to show a splash screen for a while, you can simply do it in the Start() function. Or maybe I did not understand correctly how you plan to use this?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 16:25 #15199

    • Frank Müßner
    • Frank Müßner's Avatar
    • Topic Author


  • Posts: 259
  • Hi Chris,

    normal Winforms work with Show() That i have tested.

    I can not use ShowDialog() this is modal. So the Program Stop at ShowDialog().

    I think the Problem is the DexExpress Control.

    i am looking for another solution, need more time

    Thanks, Frank

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 17:07 #15201

    • Chris
    • Chris's Avatar


  • Posts: 3751
  • Hi Frank,

    You do not have a message loop running when you are showing the window, so I believe a simple Show() will just show the window for a brief moment and it will close right after. Did you have success using the exact same code with a regular windows forms Form?

    Btw, another thing that you need to pay attention when using threads and GUI, is that you need to make sure you have included a STAThread attribute on your Start() funcntion:

    [STAThread];
    FUNCTION Start() AS VOID
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 13 Jul 2020 18:53 #15203

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Frank,

    When you build with VO a StandardMDI app there´s also a splash window included. The splash window is created at the beginning of the VO App Start() and it´s destroyed via a timer. That´s the content of the SplashScreen Show() method.
    METHOD Show(kShowState) CLASS SplashScreen
    	SUPER:show(kShowState)
    	// Make window topmost
    	SetWindowPos(SELF:handle(), HWND_TOPMOST, 0, 0, 0, 0, DWORD(_OR(SWP_NOSIZE, SWP_NOMOVE)))
    	// Register Timer
    	SELF:RegisterTimer(3, TRUE)
    	// Remove the following two lines if you don't want to show the Splashscreen separatly
    	GetAppObject():Exec(EXECWHILEEVENT)
    	Sleep(1000)
    	RETURN NIL
    
    METHOD Timer() CLASS SplashScreen
    	SELF:Destroy()
    RETURN SELF
    But you don´t really need a timer. Just paint a centered and *modeless* DialogWindow. Now your X# Start() method might look like:
    METHOD Start() 
    	LOCAL oMainWindow AS StandardShellWindow
     
    
    	// ------------------
    
    	LOCAL oSplashScreen := DlgSplash{SELF}
    	oSplashScreen:Show()
    
    	// Make window topmost
    //	SetWindowPos(SELF:handle(), HWND_TOPMOST, 0, 0, 0, 0, DWORD(_OR(SWP_NOSIZE, SWP_NOMOVE)))
    
    	DoEvents()  // ensures that the content of the splash window is drawn !
    	Sleep(1000)
     
    	// -----------
           
            oMainWindow := StandardShellWindow{}
     	oMainWindow:Show(SHOWCENTERED)
            
            local Nw1 as Window1
            Nw1:=Window1{oMainWindow}
            Nw1:Show()
    
    	oSplashScreen:Destroy()  // <---------  
            
    	SELF:Exec()
            
        RETURN NIL

    Regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    How can I display a SplashSreen? 14 Jul 2020 09:04 #15204

    • Frank Müßner
    • Frank Müßner's Avatar
    • Topic Author


  • Posts: 259
  • @ Chris,

    Regular windows forms Form is show normal. The DevExpress SplashScreen need DoEvents() to show correctly.

    I have [STAThread];
    but not work.

    @Karl-Heinz,

    the normal *modeless* DialogWindow. is not nice as the DevExpress Control :-) Fadein Fadeout .


    I have now this working code:
    CLASS XApp INHERIT App
    
    	METHOD Start() 
    		LOCAL oMainWindow AS StandardShellWindow
            LOCAL I as DWORD
            
            local SplashScreenHelper AS AuftragSQLKasseCSWinForms.XSTools
            SplashScreenHelper:=AuftragSQLKasseCSWinForms.XSTools{}
            SplashScreenHelper:TestAsyncWaitForm()
           
            For I:=1 to 100
                sleep(50)
            NEXT
            
            SplashScreenHelper:nStatus=1 //Close 
            
            For I:=1 to 20
                sleep(50)
                DoEvents()
                if SplashScreenHelper:nStatus=0  //is Closed
                    Exit
                endif
            next
            
            SplashScreenHelper:=NULL_OBJECT 
            
    		oMainWindow := StandardShellWindow{SELF}
    		oMainWindow:Show(SHOWCENTERED)
    	    SELF:Exec()
       RETURN NIL
    END CLASS
    public class XSTools
        {
    
            public Int16 nStatus;
            public async void TestAsyncWaitForm()
            {
                SplashScreenManager.ShowForm(typeof(SplashScreen1), true, false);
                await Task.Run(() =>
                {
                    for (int i = 0; i < 200; i++)
                    {
                        System.Threading.Thread.Sleep(100);
                        if (nStatus == 1)
                        {
                            i = 300;
                        }
                    }
                });
                SplashScreenManager.CloseForm();
                nStatus = 0;
            }
    }


    This work and I hope there are no side effects.

    Frank

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1