'// Assumes Form-1 shows a list of records and Form2 to create a new record. The purpose of this delegate is to update the list view in Form-1 after saving the record.
FORM-1
Public Class Form1
Private Sub AddOrUpdateRecordallbackFn(ByVal xRec As AuctionInword)
//Arg - 'AuctionInword' user defined type
//METHOD IMPLIMENTATION
End Sub
Private Sub Button1_Click()
'// CALL FORM 2
Dim xfm As New Form2
'// Point the function
xfm.AddOrUpdateAICallBack = AddressOf AddOrUpdateRecordallbackFn
xfm.Show()
End Sub
End Class
FORM-2
Public Class Form2
'//Delegate to Form1 function AddOrUpdateRecordallbackFn
Public Delegate Sub AddOrUpdateRecord(ByVal xRecord As AuctionInword)
'//variable to point the function
Public AddOrUpdateAICallBack As AddOrUpdateRecord
Private Sub SaveRecord()
//Save record implementation
Dim _CurrentRecord = New <<User Type>> '//To store new record
-----------------------
-----------------------
//After Saving, call the Form1 function 'AddOrUpdateRecordallbackFn' using delegate
If AddOrUpdateAICallBack IsNot Nothing Then AddOrUpdateAICallBack(_CurrentRecord)
End Sub
End Class
FORM-1
Public Class Form1
Private Sub AddOrUpdateRecordallbackFn(ByVal xRec As AuctionInword)
//Arg - 'AuctionInword' user defined type
//METHOD IMPLIMENTATION
End Sub
Private Sub Button1_Click()
'// CALL FORM 2
Dim xfm As New Form2
'// Point the function
xfm.AddOrUpdateAICallBack = AddressOf AddOrUpdateRecordallbackFn
xfm.Show()
End Sub
End Class
FORM-2
Public Class Form2
'//Delegate to Form1 function AddOrUpdateRecordallbackFn
Public Delegate Sub AddOrUpdateRecord(ByVal xRecord As AuctionInword)
'//variable to point the function
Public AddOrUpdateAICallBack As AddOrUpdateRecord
Private Sub SaveRecord()
//Save record implementation
Dim _CurrentRecord = New <<User Type>> '//To store new record
-----------------------
-----------------------
//After Saving, call the Form1 function 'AddOrUpdateRecordallbackFn' using delegate
If AddOrUpdateAICallBack IsNot Nothing Then AddOrUpdateAICallBack(_CurrentRecord)
End Sub
End Class
No comments:
Post a Comment