Okay Cal and Steve you have choosen for the once-all approach. Thank you for sharing.
As I had chosen for the skipping-approach I worked it out and added some lines in Ira's example.
I replaced the hardcoded return statements with a variable 'required' and added a Select... Case construction almost at the end just where the a_dlg_button is made empty.
As you can see the required fields are tested there and the variable 'required' contains the result. It also prevents the user to save/exit when a required field still is made empty.
For a quick view I marked additions with ' TS + comment.
All's well that ends well.
Before I started this thread I had the same construction and issues as Cal demonstrated. Events were playing ping-pong in an endless loop and I had no idea about what was going on as debugging was no option.
With the constuction here exposed with the variable 'required' it is solved.
Code:
'========================================================================= ' Copyright 2010 Computer Systems Design & Associates, All Rights Reserved ' http://www.csda1.com '========================================================================= 'DESCRIPTION: Displays XDialog event information dim dlgtit as c dlgtit="Test XDialog events" dim dlgbdy as c dlgbdy=<<%dlg% {startup=init} {can_exit=close} {region} Req Name:|[name!nameevt_*]; Req Number:|[number!numberevt_*]; Req Telephone:|[telephone!telephoneevt_*]; Not req Street:|[street!streetevt_*]; {endregion}; Event List; {text=40,20eventlist1}; Required:[required ]; {region}<OK> <Cancel> <Clear Events!clearevents>{endregion} %dlg% dim dlgevt as c dlgevt=<<%code% IF (UT(a_dlg_button)=="CLOSE").or.(UT(a_dlg_button)=="CANCEL") ui_modeless_dlg_close(dlgtit) ELSE IF (UT(a_dlg_button)=="OK") ui_modeless_dlg_close(dlgtit) ELSE IF (UT(a_dlg_button)=="CLEAREVENTS") eventlist="" ELSE IF (UT(a_dlg_button)=="INIT") ' Initialization code here eventlist="" ' Only show most recent 20 lines of events eventlist1=word(eventlist,max(1,line_count(eventlist)-20),crlf(),20) ' Show all events ' eventlist1=eventlist ELSE ' Add event for those we want to track to event list at top in reverse order eventlist=eventlist+a_dlg_button+Crlf() ' Only show most recent 20 lines of events eventlist1=word(eventlist,max(1,line_count(eventlist)-20),crlf(),20) ' Show all events ' eventlist1=eventlist ' Process events IF left(UT(a_dlg_button),8)=="NAMEEVT_" evt=substr(a_dlg_button,9) ' Do what you need here to process event ' This code will move focus back to field if trying to leave and field is blank IF ut(evt)=="KILLFOCUS" IF trim(name)=="" ui_dlg_ctl_goto(dlgtit,required ) 'TS changed return eventname into variabel 'required' END IF END if ELSE IF left(UT(a_dlg_button),10)=="NUMBEREVT_" evt=substr(a_dlg_button,11) ' Do what you need here to process event ' This code will move focus back to field if trying to leave and field is blank IF ut(evt)=="KILLFOCUS" IF trim(number)=="" ui_dlg_ctl_goto(dlgtit,required ) 'TS changed return eventname into variabel 'required' END IF END if ELSE IF left(UT(a_dlg_button),12)=="TELEPHONEEVT_" evt=substr(a_dlg_button,13) ' Do what you need here to process event ' This code will move focus back to field if trying to leave and field is blank IF ut(evt)=="KILLFOCUS" IF trim(telephone)=="" ui_dlg_ctl_goto(dlgtit,required ) 'TS changed return eventname into variabel 'required' END IF END if ELSE IF left(UT(a_dlg_button),10)=="STREETEVT_" evt=substr(a_dlg_button,11) IF ut(evt)=="SETFOCUS" IF trim(telephone) == "" 'TS added ; case not finished before ui_dlg_ctl_goto(dlgtit,required ) 'TS changed return eventname into variabel 'required' END IF ' Do what you need here to process event END IF END IF END IF a_dlg_button="" select 'TS added the next 11 lines case trim(name) = "" required = "name" case trim(number) = "" required = "number" case trim(telephone) = "" required = "telephone" case else 'for statements to exit with OK or SAVE required = "foo" save_ok = .T. end select END %code% dim eventlist as c dim eventlist1 as c dim evt as c dim required as C 'TS added line ' Display as modeless, as we can look at it and modify code while open ui_modeless_dlg_box(dlgtit,dlgbdy,dlgevt)
Ton
Leave a comment: