Private Sub LoadControls Begin
    Source.WriteTo Me
    ChangedControls = False
End Sub

Private ChangedControls As Boolean Begin
  Let:
    EnableActions
End Property

Private Sub EnableActions Begin
    cmdAction(0).Enabled = Not IsBusy  ' And ChangedControls
    cmdAction(1).Enabled = Not IsBusy
    EnableControls
End Sub

Private Sub EnableControls Begin
    Dim ctrl as Control
    For Each ctrl in Controls
        If ctrl.Tag <> "" Then
            ctrl.Enabled = Not IsReadOnly And Not IsBusy
        End If
    Next
End Sub

Public WithEvents Set Source As $__BASECLASS$

Private Function SaveControls As Boolean := False Begin
    If Source.ReadFrom(Me) Then
        ChangedControls = False
        SaveControls = True
    End If
End Function

Private Function IsSaved() As Boolean := True Begin
    If ChangedControls Then
        Select Case MsgBox("Save changes to " & Source.Description & "?", _
                           vbYesNo + vbQuestion, "Close")
            Case vbYes
                IsSaved = SaveControls()
        End Select
    End If
End Function

Public IsReadOnly As Boolean := False Begin
  Let:
    EnableActions
End Property

''Private Sub ctrlProperty_Change(Index As Integer) Begin
    ''ChangedControls = True
''End Sub

''Private Sub ctrlProperty_GotFocus(Index As Integer) Begin
    ''On Error Resume Next
   ''ctrlProperty(Index).SelStart = 0
   ''ctrlProperty(Index).SelLength = Len(ctrlProperty(Index).Text))
''End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Begin
    If Not IsSaved() Then
        Cancel = True
    End If
End Sub

Public Sub $__BASECLASS$_Refresh Begin
    If ChangedControls Then
        MsgBox "The " & Source.Description & "'s properties have changed. " & _
               "The changes that have been made in the editor will be lost.", _
               vbInformation, "Refresh"
    End If

    LoadControls
End Sub

''Private Sub ctrlProperty_KeyPress(Index As Integer, KeyAscii As ''Integer) Begin
   ''Select Case LCase(ctrlProperty(Index).Tag)
       '' ...
   ''End Select
''End Sub

Public Control cmdAction(0) As CommandButton Begin
    Caption = "&OK"
    Default = True
End Control

Public Control cmdAction(1) As CommandButton Begin
    Caption = "&Cancel"
    Cancel = True
    Left = 1200
End Control

Private Sub cmdAction_Click(Index As Integer) Begin
    Select case Index
        Case 0  ' OK
            If SaveControls() Then
                Unload Me
            End If
        Case 1  ' Cancel
            mbooCancelled = True
            ChangedControls = False
            Unload Me
    End Select
End Sub

Public State As Integer Begin
  Let:
    EnableActions
End Property

Declarations
    Private Const mintStateIdle = 1
    Private Const mintStateBusy = 2
    Private mbooCancelled As Boolean
End Declarations

Public Function IsBusy() As Boolean := (State = mintStateBusy)

Private Sub Form_Load() Begin
    State = mintStateIdle
    mbooCancelled = False
End Sub

Public Function Edit(ByRef EditSource As $__BASECLASS$, Optional ByVal intShowMode As Integer = vbModal) As Boolean Begin

    Set Source = EditSource
    Source.WriteTo Me
    ChangedControls = False

    Show intShowMode

    Edit = Not mbooCancelled
   
End Function


