Delphi Programming
Advertisement

In VB 6 create a new project with a label (Label1) and a textbox side-by-side (Text1). Set the Index property to 0. This will set up a control array. Add the following code to the form:

  Option Explicit
  
  Private Function mfPixelsToTwips(ByVal vlngPixels As Long) As Long
     mfPixelsToTwips = vlngPixels * 15
  End Function
  
  Private Sub Form_Load()
     Dim llngIndex As Long
     
     For llngIndex = 1 To 5
        Load Label1(llngIndex)
        Label1(llngIndex).Top = Label1(llngIndex - 1).Top 
                        + Label1(llngIndex - 1).Height + mfPixelsToTwips(3)
        Label1(llngIndex).Visible = True
        Load Text1(llngIndex)
        Text1(llngIndex).Top = Label1(llngIndex - 1).Top 
                        + Label1(llngIndex - 1).Height + mfPixelsToTwips(3)
        Text1(llngIndex).Visible = True
     Next
  End Sub
  
  Private Sub Text1_GotFocus(Index As Integer)
     Label1(Index).Tag = Label1(Index).Caption
     Label1(Index).Caption = "Enter-->"
  End Sub
  
  Private Sub Text1_LostFocus(Index As Integer)
     Label1(Index).Caption = Label1(Index).Tag
  End Sub

This illustrates how VB deals with a single event handler for multiple controls. There is a better way with Delphi.

Advertisement