ឧទាហរណ៍កម្មវិធីសម្រាប់វត្ថុបញ្ជាក្នុងកម្មវិធីនិពន្ធប្រអប់
ឧទាហរណ៍ដូចខាងក្រោមគឺសម្រាប់ ប្រអប់ ថ្មីមួយ ហៅថា "Dialog1" ។ ប្រើឧបករណ៍លើរបារ ប្រអប់ឧបករណ៍ក្នុងកម្មវិធីនិពន្ធប្រអប់ ដើម្បីបង្កើតប្រអប់ និងបន្ថែមវត្ថុបញ្ជាដូចខាងក្រោម ៖ ប្រអប់ធីក មួយ ហៅថា "CheckBox1" វាលស្លាក មួយ ហៅថា "Label1" ប៊ូតុង មួយ ហៅថា "CommandButton1" និងប្រអប់បញ្ជី មួយ ហៅថា "ListBox1" ។
ធ្វើឲ្យប្រាកដជាមួយអក្សរធំ និងអក្សរតូច ពេលអ្នកភ្ជាប់វត្ថុបញ្ជាមួយទៅអថេរវត្ថុមួយ ។
អនុគមន៍សកល សម្រាប់ផ្ទុកប្រអប់
Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
Dim oLib as Object
Dim oLibDialog as Object
Dim oRuntimeDialog as Object
If IsMissing(oLibContainer) Then
oLibContainer = DialogLibraries
End If
oLibContainer.LoadLibrary(LibName)
oLib = oLibContainer.GetByName(Libname)
oLibDialog = oLib.GetByName(DialogName)
oRuntimeDialog = CreateUnoDialog(oLibDialog)
LoadDialog() = oRuntimeDialog
End Function
ការបង្ហាញប្រអប់មួយ
rem global definition of variables
Dim oDialog1 AS Object
Sub StartDialog1
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
oDialog1.Execute()
End Sub
អាន ឬកែសម្រួលលក្ខណសម្បត្តិនៃវត្ថុបញ្ជាក្នុងកម្មវិធី
Sub Sample1
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM get dialog model
oDialog1Model = oDialog1.Model
REM display text of Label1
oLabel1 = oDialog1.GetControl("Label1")
MsgBox oLabel1.Text
REM កំណត់អត្ថបទថ្មីសម្រាប់ត្រួតពិនិត្យ Label1
oLabel1.Text = "ឯកសារថ្មី"
REM បង្ហាញលក្ខណសម្បត្តិម៉ូដែលសម្រាប់ត្រួតពិនិត្យ CheckBox1
oCheckBox1Model = oDialog1Model.CheckBox1
MsgBox oCheckBox1Model.Dbg_Properties
REM កំណត់សភាពថ្មីសម្រាប់ CheckBox1 សម្រាប់ម៉ូដែលនៃវត្ថុបញ្ជា
oCheckBox1Model.State = 1
REM បង្ហាញលក្ខណសម្បត្តិម៉ូដែលសម្រាប់ត្រួតពិនិត្យ CommandButton1
oCMD1Model = oDialog1Model.CommandButton1
MsgBox oCMD1Model.Dbg_Properties
REM បង្ហាញលក្ខណសម្បត្តិនៃវត្ថុបញ្ជា CommandButton1
oCMD1 = oDialog1.GetControl("CommandButton1")
MsgBox oCMD1.Dbg_Properties
REM ប្រអប់ប្រតិបត្តិ
oDialog1.Execute()
End Sub
បន្ថែមធាតុមួយទៅប្រអប់បញ្ជីមួយ
Sub AddEntry
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM បន្ថែមធាតុថ្មីទៅប្រអប់បញ្ជី
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
Dim iCount as integer
iCount = oListbox.ItemCount
oListbox.additem("New Item" & iCount,0)
End Sub
យកធាតុមួយចេញពីប្រអប់បញ្ជីមួយ
Sub RemoveEntry
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM យកធាតុទីមួយចេញពី ListBox
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
oListbox.removeitems(0,1)
End Sub