Thanks Jack for holding up the light :-)

So to conclude the thread(might be of help for someone later)

This is what I did:

No code is needed in the individual fields (their code is placed in the subclass (sqlite_XXXX) open event. In this event the control subscribes to the array (App.StudentControls.Append me). The subclass has an interface which defines the methods DisplayStudentInfo and ClearInfo. Every subclass defines a property (visible) DBColumnName which is filled when placing the control onscreen. The App.TheCoach.SelectOneStudent method builds a dictionary SelectedStudent (key = dbColumnName, Value = dbvalue) based on the sqlite data. The DisplayInfo method defines
----
for a sqlite_field:

  if App.TheCoach.SelectedStudent.HasKey(me.DBColumnName) then
    me.Text = App.TheCoach.SelectedStudent.Value(me.DBColumnName)
  end if

---
for a popupmenu:

  // Part of the UpdateStudentInfo interface.

  Dim myInfo As String
  Dim i As integer

  if App.TheCoach.SelectedStudent.HasKey(me.DBColumnName) then
    myInfo = App.TheCoach.SelectedStudent.Value(me.DBColumnName)

    for i = 0 to me.ListCount
      if me.List(i) = myInfo then
        me.ListIndex = i
        exit
      end if
    next

  end if

---

for a radiobutton

  // Part of the UpdateStudentInfo interface.

  if me.Name = "rb_coach" then
    if App.TheCoach.SelectedStudent.Value(me.DBColumnName) = 1 then
      me.Value = True
    else
      me.Value = False
    end if
  ElseIf me.Name = "rb_Student" then
    if App.TheCoach.SelectedStudent.Value(me.DBColumnName) = 0 then
      me.Value = True
    else
      me.Value = False
    end if
  end if

---
Following code is placed in the change event of the listbox holding the overview of trainee's.


  Dim i, NrOfFields As Integer
  Dim ThisUserId As String
  Dim OK As Boolean
  if me.ListCount>0 Then // change is not coming from deleteAllRows
    ThisUserId = me.Cell(me.ListIndex,0)
    OK = App.TheCoach.SelectOneStudent(ThisUserId)
    for i = 0 to UBound(App.StudentControls)
      if App.StudentControls(i) isa sqlite_field then
        sqlite_field(App.StudentControls(i)).DisplayStudentInfo
      ElseIf App.StudentControls(i) isa sqlite_pumenu then
        sqlite_pumenu(App.StudentControls(i) ).DisplayStudentInfo
      ElseIf App.StudentControls(i) isa sqlite_rb then
        sqlite_rb(App.StudentControls(i) ).DisplayStudentInfo
      end if
    next

    // set the button to update

    pb_addUser.Caption = "Update Trainee Info"

  else
    for i = 0 to UBound(App.StudentControls)
      if App.StudentControls(i) isa sqlite_field then
        sqlite_field(App.StudentControls(i)).ClearInfo
      ElseIf App.StudentControls(i) isa sqlite_pumenu then
        sqlite_pumenu(App.StudentControls(i) ).ClearInfo
      ElseIf App.StudentControls(i) isa sqlite_rb then
        sqlite_rb(App.StudentControls(i) ).ClearInfo
      end if
    next

    // set the button to Add

    pb_addUser.Caption = "Voeg Trainee Toe"

  end if
--


Thanks for helping out


Bart

On 28-sep-06, at 04:50, CV wrote:


On Sep 27, 2006, at 10:54 AM, Bart Pietercil wrote:


On 27-sep-06, at 18:29, CV wrote:



On Sep 27, 2006, at 8:17 AM, Bart Pietercil wrote:


Hi,

this worked:

defined and filled CurrentStudentRecord as a Dictionary having the DBColumnName as Key

defined a subclass from editfield named sqlite_field
with an extra property DBColumnName

added an interface to the class  with a DisplayStudentInfo method

defined App.StudentFields() As sqlite_fields

in the change event of my listbox the code

for i = 0 to Ubound(App.StudentFields)
App.StudentFields(i).DisplayInfo
next

updates all the sqlite_fields with their appropriate values

JOY

now I want to add some popupmenus to the dance

so I subclassed a popupmenu as sqlite_pumenu that interfaces with the DisplayStudentInfo method

-------
this does not work and where I am at lost

I cannot add my sqlite_pumenu's to App.StudentFields (it is not a sqlite_field)

I changed the StudentFieldsArray to type Control. This seems to work as RB does not complain when I add the sqlite_xxxx to the array. However RB does not accept the line App.StudentsFields (i).Displayinfo . This line only seems to work when the array is of type sqlite_field


At this point you should be able to cast to expose the subclass functionality: Sqlite_field(App.StudentsFields(i)).DisplayInfo, since, as I understand it, App.StudentsFields(i) of data type Control is actually a Sqlite_field.


Although I hadn't thought about casting this seems to be defying the purpose since what I want to achieve is an array consisting of several kinds of controls (editfields,popupmenu,radios,checkboxes,....) which share (through the interface) the DisplayInfo method. In this way I hoped to avoid a lot of "cases" and "Isa's"; If I am to follow your lead on this, I would still have to introduce "isa sqlite_pumenu" or "isa sqlite_field" checking , wouldn't I ?

Alternately you could dimension your array to your interface. Then you could access the interfaced methods directly without casting or "isa". However, you will have to cast to the subclass that implemented the interface in order to expose the methods/properties of that subclass should you need them, and that will require 'isa'.


Best,

Jack




Perhaps a dictionary would be a better design choice than any array, however.



I've been thinking about this. Since I have already a dictionary representing the SelectedStudent (key = DBColumnName, Value = DBValue), I could make a "mirroring" Dictionary built on DBColumnname and the object representing the info on screen. But wouldnt I still need to cast ? Or should this work:

myDict.Value("DBColumnName").DisplayInfo ?


No, I think you will have to cast as well. If Value was assigned into the dictionary as an instance of a subclass that implemented the interface declaring DisplayInfo then you have to cast to the subclass. As a somewhat related example:

  dim dd as new Dictionary
dd.Value("Element1") = StaticText1 'an instance of MyStaticText, a subclass of statictext which implements an interface containing the Display method.
  If dd.Value("Element1") IsA StaticText then
    MyStaticText((dd.Value("Element1"))).Display
  End
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to