Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

DateTimePicker change available in EditFocusChange? 18 Oct 2022 02:13 #24198

  • jonhn
  • jonhn's Avatar
  • Topic Author


  • Posts: 84
  • Greetings!

    Is it possible to get a DTP focus change in the EditFocusChange? Or is it available via the DateTimeSelectionChanged function? Or maybe there is another function I haven't found yet?

    I simply want the user to set two dates and when leaving the second date field to "do somestuff".

    When using DateTimeSelectionChanged I can get the changed contents, but every time a different date is selected this method fires... I only want it after losing focus on that control.

    There is no GotFocus property for oControl if I try this below, but maybe it is a syntax error? Or maybe I'm declaring it as the wrong type?

    LOCAL oControl AS OBJECT
    oControl := oDateTimeSelectionEvent:Control
    lGotFocus := IIf(oDateTimeSelectionEvent == NULL_OBJECT, FALSE, oControl:GotFocus)

    After trying for a while I think it is why I originally used Willies DateSLE for this function, but maybe it is different with X#... hopefully.

    Thank you.
    Jonathan

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 18 Oct 2022 13:32 #24204

    • ic2
    • ic2's Avatar


  • Posts: 1667
  • Hello Jonathan,

    I think this is about what you want, this sets the second date (to) to the first date if it's before the first date
    METHOD DateTimeSelectionChanged(oDateTimeSelectionEvent) CLASS MyWindow
    //#s After selecting start date, adapts end date
    
    	SUPER:DateTimeSelectionChanged(oDateTimeSelectionEvent)
    	IF  oDateTimeSelectionEvent:Control:NameSym==#DateFrom
    		IF SELF:oDCDateTo:SelectedDate<SELF:oDCDateFrom:SelectedDate
    			SELF:oDCDateTo:SelectedDate:= SELF:oDCDateFrom:SelectedDate
    		ENDIF
           ENDIF
    RETURN NIL

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    DateTimePicker change available in EditFocusChange? 18 Oct 2022 14:02 #24206

    • robert
    • robert's Avatar


  • Posts: 3599
  • Jonathan,
    The DateTimeSelectionChanged event is created when the control sends DTN_DATETIMECHANGE.
    learn.microsoft.com/en-us/windows/win32/...s/dtn-datetimechange
    A quick search online shows that the following messages are sent when the control gets / loses focus:
    NM_SETFOCUS and NM_KILLFOCUS.
    In the VO GUI classes these events are not yet captured.
    You can overwrite the ControlNotify() method of the Window class to handle these and maybe delegate these messages to the ControlFocusChange event handler

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 19 Oct 2022 03:33 #24212

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Thank you Robert (and Dick for the suggestion)

    Robert - Is this below close to what you meant? There was no existing method so I created one and it does intercept the event, but of course my Textboxes mess with the focus and I end up with a problem. haha.

    If I'm on the right track, the next step is to notify the ControlFocusChange of the Window that this control lost focus, right?

    To do this, what message do I put in the call to SELF:ControlFocusChange('VO.ControlFocusChangeEvent')
    (This is where I am currently stuck trying to figure out how to form the VO.ControlFocusChangeEvent)

    THIS IS THE CONTROLNOTIFY I CAME UP WITH

    VIRTUAL METHOD ControlNotify(oControlNotifyEvent) AS USUAL CLIPPER
    LOCAL oControl AS Control

    oControl := IIf(oControlNotifyEvent == NULL_OBJECT, NULL_OBJECT, oControlNotifyEvent:Control)

    SUPER:ControlNotify(oControlNotifyEvent)

    IF oControl != NULL_OBJECT .and. oControl:NameSym =#DTPInv_Date .and. oControlNotifyEvent:NotifyCode == NM_KILLFOCUS
    textbox{SELF:owner ,"You messed with Date# 1",oControl:Name }:show()
    // Send notification message to ControlFocuschange that the DTP was used and no longer has focus.
    ENDIF

    IF oControl != NULL_OBJECT .and. oControl:NameSym =#DTPRet_Date .and. oControlNotifyEvent:NotifyCode == NM_KILLFOCUS
    textbox{,"You messed with Date# 2",oControl:Name }:show()
    // Send notification message TO ControlFocuschange that the DTP was used and no longer has focus.
    ENDIF
    RETURN NIL

    Many thanks!
    Jonathan

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 19 Oct 2022 12:17 #24216

    • robert
    • robert's Avatar


  • Posts: 3599
  • Jonathan,
    I would not create a controlFocusChangeEvent at all .
    Why not create a new method that has the parameters oControl and lGotFocus and call that method from here and from the controlFocusChangeEvent on the window.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 20 Oct 2022 10:24 #24221

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Thank you Robert,
    I thought that would be too simple! After some experimenting it now seems to be working very nicely.
    Thank you for the pointers!
    Regards,
    Jonathan

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 20 Oct 2022 20:07 #24226

    • robert
    • robert's Avatar


  • Posts: 3599
  • Jonathan,
    The simplest solution is often the best !

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 21 Oct 2022 02:14 #24228

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Sorry - I'm back. Wasn't quite so simple... or maybe.
    I'm getting a stack overflow (I assume) after selecting a few different dates - the DateThing method is being called again (and again) by ControlNotify.

    How should I let ControlNotify know that we have dealt with the DateSelectionChange and to forget about it?


    METHOD DateThing(oControl AS Control)
    LOCAL oControlCurrent AS Control

    //check if user is still in the date field or if they've moved away.
    oControlCurrent := GetFocusedObject() // What control now has focus? If not the date field the...

    IF oControlCurrent != NULL_OBJECT .and. ((oControl:NameSym ==#DTPRet_Date .and. oControlCurrent:NameSym != #DTPRet_Date) .or. oControl:NameSym ==#DTPInv_Date .and. oControlCurrent:NameSym != #DTPInv_Date )

    IF SELF:OldInv_date <> SELF:odcDTPInv_date:Value
    SELF:DatesChanged()
    ELSEIF SELF:OldRet_date <> SELF:odcDTPRet_date:Value
    SELF:DatesChanged()
    ENDIF
    ENDIF
    RETURN NIL


    VIRTUAL METHOD ControlNotify(oControlNotifyEvent) AS USUAL CLIPPER
    LOCAL oControl AS Control

    oControl := IIf(oControlNotifyEvent == NULL_OBJECT, NULL_OBJECT, oControlNotifyEvent:Control)

    SUPER:ControlNotify(oControlNotifyEvent)

    IF oControl != NULL_OBJECT .and. oControl:NameSym =#DTPInv_Date .and. oControlNotifyEvent:NotifyCode == NM_KILLFOCUS //.and. !lGotFocus
    SELF:DateThing(oControl )
    // Send notification message to DateThing that the DTP was used and no longer has focus.
    ENDIF
    IF oControl != NULL_OBJECT .and. oControl:NameSym =#DTPRet_Date .and. oControlNotifyEvent:NotifyCode == NM_KILLFOCUS // .and. !lGotFocus
    SELF:DateThing(oControl )
    // Send notification message TO DateThing that the DTP was used and no longer has focus.
    ENDIF
    RETURN NIL

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 21 Oct 2022 08:08 #24229

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Robert & Jonathan,

    i think there is no need to overwrite ControlNotify(). The Dispatch() in the control.prg handles WM_SETFOCUS / WM_KILLFOCUS and calls SELF:FocusChange(), which finally triggers oParent:ControlFocusChange().
    METHOD Dispatch(oEvent) CLASS Control
    [...]
           
            //PP-040421 Improved focus handling
        CASE msg == WM_SETFOCUS .OR. msg == WM_KILLFOCUS
            //uRet := SELF:FocusChange(__ObjectCastClassPtr(oEvt, __pCFocusChangeEvent))
            uRet := SELF:FocusChange(FocusChangeEvent{oEvt})
    [...]

    METHOD FocusChange(oFocusChangeEvent) CLASS Control
        //PP-040518 Update from S Ebert
      
        IF IsInstanceOf(oParent,#DataWindow) .OR. IsInstanceOf(oParent,#DialogWindow)
            //RETURN oParent:ControlFocusChange(__ObjectCastClassPtr(oFocusChangeEvent, __pCControlFocusChangeEvent))
            RETURN oParent:ControlFocusChange(ControlFocusChangeEvent{oFocusChangeEvent})
        ELSEIF IsInstanceOf(oParent, #__FormWindow) //It's a browser of a DataWindow
            IF oFocusChangeEvent:GotFocus
                oParent:DataWindow:LastFocus := SELF
            ENDIF
        ENDIF
        
        RETURN NIL

    i added two DTPs to a Dialog and the event properties show the expected results.
    METHOD ControlFocusChange(oControlFocusChangeEvent)  CLASS  MainDialog 
    
    	SUPER:ControlFocusChange(oControlFocusChangeEvent)
    
    	
    	? oControlFocusChangeEvent:Control:Namesym , oControlFocusChangeEvent:GotFocus 
    
    	IF IsInstanceOf ( oControlFocusChangeEvent:Control , #DATETIMEPICKER )
    		?? "", oControlFocusChangeEvent:Control:SelectedDate		
    		
    	ENDIF 	
    
    	RETURN NIL

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 21 Oct 2022 18:18 #24238

    • Jamal
    • Jamal's Avatar


  • Posts: 309
  • A small contribution in addition to Karl's solution if you are using VO 2.8 (sp2838).

    Since the ControlFocusChange event is not visible in the Window properties dialog, the following can be made to the CAVOWED.INF and CAVOWED.TPL located in the C:\CAVO28\BIN folder. The advantage of this modification that you have access to this event from the Window Editor and applies to all window types.

    Please backup the above files before making any modifications!

    In CAVOWED.TPL:
    Below the
    [ClassDeclaration]
    class %FORM:NAME% inherit %FORM:CLASSNAME%

    Add:
    [ControlFocusChange]
    method ControlFocusChange(oControlFocusChangeEvent) class %FORM:NAME%
    \tlocal oControl as Control
    \toControl := IIf(oControlFocusChangeEvent == NULL_OBJECT, NULL_OBJECT, oControlFocusChangeEvent:Control)
    \tsuper:ControlFocusChange(oControlFocusChangeEvent)
    \t//Put your changes here
    \treturn NIL


    In CAVOWED.INF

    Add:
    Method93=ControlFocusChange,ControlFocusChange(CODE:ControlFocusChange)


    In the section:
    ;**** Association between Tabs and methods/assigns/styles

    Update the Control Events line to:

    Control Events=(Window Control Events)ControlFocusChange,ButtonClick,ButtonDoubleClick,EditChange,EditFocusChange,EditScroll,Keydown,Keyup,ListBoxClick,ListBoxSelect,HorizontalScroll,VerticalScroll,HorizontalSlide,VerticalSlide,HorizontalSpin,VerticalSpin




    Generated code:
    method ControlFocusChange(oControlFocusChangeEvent) class DragDropDlg
    	local oControl as Control
    	oControl := IIf(oControlFocusChangeEvent == NULL_OBJECT, NULL_OBJECT, oControlFocusChangeEvent:Control)
    	super:ControlFocusChange(oControlFocusChangeEvent)
    	//Put your changes here   
    	return NIL

    HTH,
    Jamal
    Attachments:

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    DateTimePicker change available in EditFocusChange? 25 Oct 2022 05:23 #24255

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Thanks Karl,
    I made a small app to try your suggestion, but am not sure about a couple of things. I've copied your code almost literally, and it compiles and runs, but... I don't think it is ever calling the dispatch in my case.

    1) oParent - where should this value come from? I have tried declaring it in the method below and taking _GetInst(), but I don't think it is right.
    2) Where do I look for the results of these? - with the "?" ? oControlFocusChangeEvent:Control:Namesym , oControlFocusChangeEvent:GotFocus
    Are these visible in the debugger?

    Here's what I did...
    METHOD Dispatch(oEvent) CLASS Control
    LOCAL uRet AS USUAL

    //PP-040421 Improved focus handling
    IF oEvent:msg == WM_SETFOCUS .OR. oEvent:msg == WM_KILLFOCUS
    //uRet := SELF:FocusChange(__ObjectCastClassPtr(oEvt, __pCFocusChangeEvent))
    uRet := SELF:FocusChange(FocusChangeEvent{oEvent})
    ENDIF

    RETURN SUPER:Dispatch(oEvent)

    METHOD FocusChange(oFocusChangeEvent) CLASS Control
    //PP-040518 Update from S Ebert
    LOCAL oParent AS OBJECT
    oParent := _GetInst()

    IF IsInstanceOf(oParent,#DataWindow) .OR. IsInstanceOf(oParent,#DialogWindow)
    //RETURN oParent:ControlFocusChange(__ObjectCastClassPtr(oFocusChangeEvent, __pCControlFocusChangeEvent))
    RETURN oParent:ControlFocusChange(ControlFocusChangeEvent{oFocusChangeEvent})
    ELSEIF IsInstanceOf(oParent, #__FormWindow) //It's a browser of a DataWindow
    IF oFocusChangeEvent:GotFocus
    oParent:DataWindow:LastFocus := SELF
    ENDIF
    ENDIF

    RETURN NIL
    METHOD ControlFocusChange(oControlFocusChangeEvent) CLASS DATAWINDOW1

    SUPER:ControlFocusChange(oControlFocusChangeEvent)

    ? oControlFocusChangeEvent:Control:Namesym , oControlFocusChangeEvent:GotFocus

    IF IsInstanceOf ( oControlFocusChangeEvent:Control , #DATETIMEPICKER ) .and. oControlFocusChangeEvent:Control:NameSym == #DATETIMEPICKER2 .and. oControlFocusChangeEvent:GotFocus
    ?? "", oControlFocusChangeEvent:Control:SelectedDate

    ENDIF

    RETURN NIL

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 25 Oct 2022 09:01 #24256

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Thanks Jamal,
    Can this also be use in X# for VO dialect?

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 25 Oct 2022 09:47 #24258

    • Chris
    • Chris's Avatar


  • Posts: 3981
  • Hi John,

    Thanks Jamal,
    Can this also be use in X# for VO dialect?

    Yes, the same should work in X# as well, you will just need to update the (same named) files in your XIDE folder.
    If it's not working as intended, please let us know!
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 25 Oct 2022 10:33 #24259

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Jonathan,

    you may not add my posted "Class control" snippets to your app! I only posted this code, which is part of the VO Gui source code, to describe the message flow. All you need is your already created method:
    METHOD ControlFocusChange(oControlFocusChangeEvent) CLASS DATAWINDOW1
    
    SUPER:ControlFocusChange(oControlFocusChangeEvent)
    
    ? oControlFocusChangeEvent:Control:Namesym , oControlFocusChangeEvent:GotFocus
    
    IF IsInstanceOf ( oControlFocusChangeEvent:Control , #DATETIMEPICKER ) .and. oControlFocusChangeEvent:Control:NameSym == #DATETIMEPICKER2 .and. oControlFocusChangeEvent:GotFocus
    ?? "", oControlFocusChangeEvent:Control:SelectedDate
    
    ENDIF
    
    RETURN NIL

    btw. ? or ?? sends the output to a console window. To make it work:

    - If you use VO add the "TerminalLight" Lib.
    - if you use X# change the Target from "Windows" to "Console"

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    DateTimePicker change available in EditFocusChange? 25 Oct 2022 11:03 #24260

    • jonhn
    • jonhn's Avatar
    • Topic Author


  • Posts: 84
  • Ahhhh, yes... thank you.
    Now that you explained it slowly enough (and in a large font) for me, I've finally got it, and indeed it seems to be working at my end.
    Thank you for the suggestion and clarification!

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1