Dynamical renaming of the text box

TextBoxRename.ods (11.8 KB)
I try to dynamically rename the TextBox in my dialog, but LO doesn’t recognize new assigned name. What is wrong in sub ShowNewName? LO 6.3.6.2 x64, Windows 10. (It may seem strange to want to rename a dialog item, but I really need it).

Sub ShowOriginalName()
dim oDlg as object
DialogLibraries.LoadLibrary(“Standard”)
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dlg1)
oDlg.GetControl(“Txt1”).GetModel.Text = oDlg.GetControl(“Txt1”).GetModel.Name
oDlg.Execute
end sub

Sub ShowNewName()
dim oDlg as object
dim o as object
DialogLibraries.LoadLibrary(“Standard”)
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dlg1)
oDlg.GetControl(“Txt1”).GetModel.Name = “Txt2”
o = oDlg.GetControl(“Txt2”)
o.GetModel.Text = “Txt2”
oDlg.Execute
end sub

There is no need to rush, don’t place such long structures (oDlg.GetControl(“Txt1”).GetModel.Name) to the left of the assignment sign.

Do it gradually:

oControl=oDlg.GetControl(“Txt1”)
oModel=oControl.GetModel
oModel.Name = “Txt2”
oControl.SetModel(oModel)

A little longer way:

' Change control name
Sub ShowNewName()
  Dim  oDlg, oControl, oModel
  DialogLibraries.LoadLibrary("Standard")
  oDlg = CreateUnoDialog(DialogLibraries.Standard.Dlg1)
  
  oControl=oDlg.GetControl("Txt1")
  oModel=oControl.GetModel
  oModel.Name = "Txt2"
  oControl.SetModel(oModel) 
   
  oDlg.removeControl oControl
  oDlg.addControl "Txt2", oControl
   
  oControl=oDlg.GetControl("Txt2")
  oModel=oControl.GetModel
  oModel.Text = "Txt2"
  oControl.SetModel(oModel)  
  
  oDlg.Execute
End Sub 
1 Like

@sokol92 Большое спасибо