Display class instance property in window label when property changes

Using a CalendarTimeChooser class button, with an instance on my window.

I can read the class instance property with a Button Action Event :

msgbox str(QS_PushButton1.CalTimeChooser.GoDate)

Is it possible to have the text in a label ( label is on the window, not part of the class ) update with the GoDate property when the property in the instance of the class changes, or can it only be done using a timer on the window that reads the GoDate property ( much like the PushButon action above ) ?

After an entire day trying to solve this, I would appreciate the ‘idiots instructions’ if it is possible.

TIA

This would be a good example on how to use Sam’s notification center.
Read here: https://forum.xojo.com/22834-sam-rowlands-notificationcenter-is-awesome/p1#p190439

Here is an example project to download:
http://www.xdevmag.com/browse/12.5/12504/index.shtml

Once you understand the usage of the interface, you don’t want to miss it again.

There is an event called SelectedDate (and one called SelectedTime). Put your code which updates the label in there. A notification center is an overkill in this case IMHO.

Thanks Eli

But that’s the bit I can not get to work.

The label is on the window that contains the instance of the button, not in the class itself.

So how do I set the text property of a label that is external to the class instance ?

As a work around, I have done this :

in the class, created a Property called GoActive, Boolean, Default False

in the Window, added a timer, interval = 500, status = Off.

Sub Action()
    self.label3.text =  str(QS_PushButton1.CalTimeChooser.GoDate)
    if QS_PushButton1.CalTimeChooser.GoActive = false then
    timer2.enabled = false
  end if
    Tcounter = Tcounter + 1
  label4.text = str(Tcounter)
  End Sub

In the QS_PushButton1 Action Event, set the Timer mode to multiple.

  QS_PushButton1.mSetOptions
  
  QS_PushButton1.CalTimeChooser.VisiblePickers = Date_Time_Container.PickerElements_CalendarOnly
  QS_PushButton1.CalTimeChooser.Date_Time_Container1.Calendar_Container1.RecurringCanvas1.visible = false

  QS_PushButton1.CalTimeChooser.GoActive = true
  
  timer2.Mode = timer.ModeMultiple
  timer2.Enabled = true

So the QS_PushButton1 Action displays the chooser ( which I changed to a Modal window ) and starts the timer. The timer then checks if the GoActive property is True ( indicates the Chooser window is still open ) and when it changes to False, gets the GoDate value from the instance, and updates the label.text, and then disables the timer.

Hope this helps someone else, although I am sure there is likely a better solution for the experienced coders.

Put this line in the SelectedDate event of CalTimeChooser:

Self.Label3.Text = Str(Me.GoDate)

[quote=190600:@Eli Ott]Put this line in the SelectedDate event of CalTimeChooser:

Self.Label3.Text = Str(Me.GoDate)

Hi Eli

I have looked through the Cal-Time folders and find the following with SelectedDate. I do not know which to add it to. Could you please guide me ?

Cal-Time Chooser Window
DateTimeWindow
Properties
SelectedDate As Date
Get
  return Date_Time_Container1.SelectedDate
End Get
Set
  Date_Time_Container1.SelectedDate=value
End Set


Cal-Time Chooser Custom Classes
CalendarButtonClass
Properties
SelectedDate As Date



Cal-Time Chooser Container Controls
Calendar_Container
Event Definitions
Event SelectedDate(inSelectedDate as Date)  // this does not allow editing



Cal-Time Chooser Container Controls
Date_Time_Container
Properties
SelectedDate As Date
Get
  dim d as new date(Calendar_Container1.Calendar1.SelectedDate)
  if Time_Container1.Time_AMPM="AM" then
    if Time_Container1.Time_Hour="12" then
      d.Hour=0
    else
      d.Hour=val(Time_Container1.Time_Hour)
    end if
  else
    if Time_Container1.Time_Hour="12" Then
      d.Hour=val(Time_Container1.Time_Hour)
    else
      d.Hour=val(Time_Container1.Time_Hour)+12
    end if
  end if
  d.Minute=val(Time_Container1.Time_Minute)
  Return d
End Get
Set
  Calendar_Container1.Calendar1.SelectedDate=value
  if value.Hour<12 then
    Time_Container1.Time_AMPM="AM"
  else
    Time_Container1.Time_AMPM="PM"
  end if
  Time_Container1.Time_Minute=format(value.Minute,"00")
  if value.Hour=0 then
    Time_Container1.Time_Hour="12"
  elseif value.Hour>12 then
    Time_Container1.Time_Hour=str(value.Hour-12)
  else
    Time_Container1.Time_Hour=str(value.Hour)
  end if
End Set




Cal-Time Chooser Container Controls
Date_Time_Container
Controls
Calendar_Container1
Sub SelectedDate(inSelectedDate as Date)
  // THIS EVENT IS PASSED THE SELECTED DATE AS A DATE OBJECT
 
  // EXAMPLE RESULTS USAGE:
  //MsgBox "The selected date is: " + inSelectedDate.SQLDateTime
  //MsgBox "The selected date is: " + inSelectedDate.AbbreviatedDate
End Sub

[quote=190600:@Eli Ott]Put this line in the SelectedDate event of CalTimeChooser:

Self.Label3.Text = Str(Me.GoDate)

Doesn’t ‘self’ refer to the window that the property is linked to ?

In the case of the Chooser, it would be the window that contains the calendar and / or clock.

So we can not refer to Label3 being located on ‘self’ because Label3 is on the initial window where the Chooser Button Instance was created in the IDE.

Do you have a separate window for CalTimeChooser or is CalTimeChooser in the same window as Label3?

App loads ‘window1’ and window1 contains Label3 and also QS_PushButton1.

QS_PushButton1 is the IDE created instance of the QS_PushButton class, and this class contains the CalTimeChooser.

So if the Chooser window was a modal window, then Label3 is on the ‘owner’ window.

Hope that explains correctly.

Then I would create a constructor in the chooser window like that:

Class ChooserWindow Private Property mOwnerWindow As Window Sub Constructor(ownerWindow As Window) mOwnerWindow = ownerWindow End ...
and call it in the ‘owner’ window as follows:

Dim chooser As New ChooserWindow(Self)

Then you will have access to the caller and you can do:

mOwnerWindow.Label3.Text = ...

[quote=190687:@Eli Ott]Then I would create a constructor in the chooser window like that:
[/quote]

Thank Eli

So if I understand correctly, that code is going to :

  1. the Constructor is like a Class Instance Initialization / Creation event, that fires up when the instance is created.
  2. This Constructor will receive a handle of the window that created the instance, and save that in the property ownerWindow
  3. the ‘parent’ window creates a New instance of the class, and passes it’s own handle to the instance, to be received by the Constructor.
  4. the class instance uses that handle mOwnerWindow like an AbsolutePath to the window that created the instance ( and by extension is able to access the Label3.Text )

Yes
Yes
Yes
Yes

Thank You
Thank You
Thank You
Thank You

Now it makes sense :slight_smile: