Non-Modal Dialog Contents not displaying properly

Hi Everyone

I’m writing a BASE application in Windows (v24.8.03), and I have created a non-modal window to let the users know that an operation is executing: There’s just a label in the dialog, no user-interaction is necessary.

When I call the dialog using .SetVisible(true), a blank window appears (with a close window X in the top right corner), with no contents, and which disappears correctly when I issue .SetVisible(false).

Following the examples I have seen in the documentation, I have set up global variables to track whether the dialog has been loaded or not. Additionally, I have a function msgMaker() that translates the message into the user’s language. (When I issue .execute() for a modal dialog, the dialog content appears correctly, but I want non-modal)

I would dearly love to have a non-modal window with the label displaying, if possible without the close window option for the dialog.

I would be grateful for any advice on this. The code is below:

Best wishes,

CB

I execute :

Global oNMDialog AS Object
Global gDlgLoaded AS Boolean

 If gDlgLoaded = 0 then  'is the dialog already in memory? No

    With GlobalScope.BasicLibraries  'not sure I need this...
         If ( Not .isLibraryLoaded("Tools") ) Then
            .LoadLibrary( "Tools" )
         End If
    End With 

    ThisComponent.DialogLibraries.loadLibrary("DlgLib")
    
    oDialogLibrary = ThisComponent.DialogLibraries.GetByName("DlgLib")       
    oModule=oDialogLibrary.getByName("DlgPlsWaitAdding")        

    gDlgLoaded = 1   
   
    oNMDialog=CreateUnoDialog(oModule)

    oLabel1 = oNMDialog.GetControl("Label1")
    oLabel1.Text = msgMaker(15)  'set contents to correct language
    
 End if

 oNMDialog.setVisible(true)

 'issue commands     ...
 
 oNMDialog.setVisible(false)

Please upload a test file with a modal dialog and we will convert it into a non-modal one.

Try this.
You can call the ShowNMDialog and StopNMDialog macros multiple times.

Option Explicit

Global oNMDialog AS Object

Sub ShowNMDialog()
  Dim oDoc As Object, oDP As Object
  Dim args(0) As New com.sun.star.beans.NamedValue
  oDoc=ThisComponent
   
  If oNMDialog Is Nothing Then
    oDoc.DialogLibraries.loadLibrary("DlgLib")

    oDP = GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider2", Array(oDoc)) 
    args(0).Name = "ParentWindow"
    args(0).Value = oDoc.CurrentController.Frame.ContainerWindow
    oNMDialog = oDP.createDialogWithArguments("vnd.sun.star.script:DlgLib.DlgPlsWaitAdding?location=document", args)
    oNMDialog.GetControl("Label1").Text = "Please Wait!"
  End If 

  oNMDialog.setVisible True
End Sub

Sub StopNMDialog()
  If Not (oNMDialog Is Nothing) Then
    oNMDialog.setVisible False
  End If  
End Sub

Dlglib.ods (12.6 KB)

Hi Soko192.

I apologise for the delay, and BIG THANKS for all your help.

When I test your code in the Macro area, all runs sweetly!

When I run the code from within my application, however, I get an error.

The line that throws the error in ShowNMDialog() is:
oNMDialog = oDP.createDialogWithArguments(“vnd.sun.star.script:DlgLib.DlgPlsWaitAdding?location=document”, args)

And the error message is:

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: DialogProviderImpl::getDialog: library container not found! at C:/cygwin64/home/buildslave/source/libo-core/scripting/source/dlgprov/dlgprov.cxx:315.

I’ve tried in vain to find any documentation that can help me with your code. If can point me in the right direction that would be great.The dialog DlgPlsWaitAdding is not stored in ‘My Macros & Dialogs’ or ‘Application Macros and Dialogs’ but under the application itself ‘CAAL DB Entry screen’ if that helps, and the code is all stored in Module1_DB.(see pic)

Any ideas? Any help with this will be greatly appreciated

Best wishes,

CB
image

Please upload your file and indicate the sequence of actions that lead to the error.
You can delete from the file anything that is not related to the error we are analyzing.

Hi soko192

Uploading the file may be tricky, as it points to a 26k+ remote dataset with secure data (PostgreSQL). The application is multilingual and pulls its label names and pull-down vocabularies from that database according to the language of the logged-in user (captured from a modal dialog), so it may require some fiddling.before I can send it to you!

What I can say now is that I execute the SaveRecord button from addition that executes this code: the addition works and the only thing that isn’t yet running is the non-modal dialog. The code isn’t great because I’m learning on the job and it’s my first application… so apologies for that…

Thanks a lot,

CB

Sub Btn_SaveTheRecord
Dim oForm As Object
Dim oSubForm as Object
Dim oControl as Object

oForm  = ThisComponent.DrawPage.getForms().getByName("MainForm")
oSubForm = oForm.getByIndex(0)

IF oSubForm.isNew THEN
    
    ' osubForm.insertRow()

   call Me_insert
   oSubform.reset
ELSE
    oSubForm.updateRow()
END IF

oSubform.allowUpdates=False

'finally, enable all navigation during add and edit
oControl=oForm.getByName("MainForm_Grid")
oControl.Enabled = True

End Sub

Sub Me_Insert
’ 1. gathers the info from the current subform row
’ 2. inserts the data through an SQL call
’ 3. resets the data so that we are no longer .IsNew or .IsModified

'1.
Dim oForm As Object
Dim oSubForm as Object
Dim oControl as Object
Dim strSQL as String 'holds the SQL Call
Dim iKey as Integer 'grabs the key

Dim strModFldList as String 'holds the modified fields for adding
Dim strModValList as String 'holds the modified values for adding

Dim oDataSource As Object
Dim oConnection As Object
Dim oStatement As Object
Dim iResult As Integer

Dim oDialogLibrary as Object
Dim oModule as Object
Dim oLabel1 as Object

oDataSource = ThisDatabaseDocument.DataSource
oConnection = oDataSource.getConnection(sUser, sPassword)
oStatement = oConnection.createStatement()

oForm = ThisComponent.DrawPage.getForms().getByName(“MainForm”)
oSubForm = oForm.getByIndex(0)
strSQL= GetSQLInsertStrings(oSubForm)

IF InStr(strSQL, “||”) > 0 then

 strModFldList = LEFT(strSQL, InStr(strSQL, "||")-1)
 strModValList = Mid(strSQL, InStr(strSQL, "||") + 3)
 'Now reset strSQL to contain the SQL Call   
 strSQL= " INSERT INTO ""public"".""My_Database"" (" 
 strSQL= strSQL + strModFldList + ")"     
 strSQL= strSQL + " VALUES (" + strModValList +");"
 
 'call the INSERT statement     
  iResult = oStatement.executeUpdate(strSQL)

Else
MsgBox “Error with Adding Record Please try again”
End if

oForm.reset

IF iResult = 1 then 'successful insert

  oForm  = ThisComponent.DrawPage.getForms().getByName("MainForm")
 
 ShowNMDialog     

 'we may be able to improve speed here...
 
 oForm.Reload
 oForm.Last 
 oForm.RefreshRow
      
 StopNMDialog

Else
msgbox “Unsuccessful Addition, Please report this to the DB Manager”
End if

oConnection.close()

End Sub

Replace the line in my macro:

oDP = GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider2", Array(oDoc)) 

with:

oDP = GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider2", Array(ThisDatabaseDocument)) 

The sun should shine!

Hi soko192

Firstly, THANKS for all your help. I replaced the line and it now reads:

oDP = GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider2", Array(ThisDatabaseDocument))

The sun is not quite out yet (it is mainly grey in the UK!)…The non-modal dialog now displays, but without the content of the dialog window as before. If I issue a msgbox statement after oForm.Reload i.e. before StopNMDialog then the content of the dialog displays.

I’m stopping tonight. back tomorrow…

Best wishes,

Candido Bandido

I have prepared a stand (see attached file) where we can model problems and solve them.
Forum122004.odb (14.3 KB)