Page 1 of 2
Tab Order
Posted: Sat Sep 19, 2009 8:27 am
by sajith
Hello,can any one help me
How can i Set the tab order of control by code.iam not using Resource for designing .
Regards,
sajith
Re: Tab Order
Posted: Sat Sep 19, 2009 8:52 am
by Antonio Linares
Sajith,
The focus will be set by the order that you use to create the controls, i.e.:
Code: Select all
#include "FiveWin.ch"
function Main()
local oDlg, cFirst := Space( 20 ), cLast := Space( 20 )
DEFINE DIALOG oDlg TITLE "Test"
@ 1, 1 GET cFirst
@ 2, 1 GET cLast
ACTIVATE DIALOG oDlg CENTERED
return nil
Now, to reverse that focus sequence, we first create the second GET:
Code: Select all
#include "FiveWin.ch"
function Main()
local oDlg, cFirst := Space( 20 ), cLast := Space( 20 )
DEFINE DIALOG oDlg TITLE "Test"
@ 2, 1 GET cLast
@ 1, 1 GET cFirst
ACTIVATE DIALOG oDlg CENTERED
return nil
Re: Tab Order
Posted: Sat Sep 19, 2009 9:20 am
by sajith
many many thanks for ur support,
My pblm is for example :
Code: Select all
#include "FiveWin.ch"
function Main()
local oDlg, cFirst := Space( 20 ), cLast := Space( 20 )
DEFINE DIALOG oDlg TITLE "Test"
@ 1, 1 GET cLast
@ 2, 1 GET cFirst
@ 4, 1 GET cFirst
@ 5, 1 GET cFirst
@ 6, 1 GET cFirst
@ 7, 1 GET cFirst
@ 8, 1 GET cFirst
@ 3, 1 GET cFirst //3 rd control
ACTIVATE DIALOG oDlg CENTERED
return nil
in the above code i added 3rd contol in the last line i want to set the Tab position of that control to 3. how it is possible
Regards,
sajith
Re: Tab Order
Posted: Sat Sep 19, 2009 9:25 am
by anserkk
Dear Mr.Sajith,
in the above code i added 3rd contol in the last line i want to set the Tab position of that control to 3 . how it is possible
That is what Mr.Antonio has explained. TAB order will work as per the order in which the control is defined/created in your PRG. While coding you have to decide and then write the code accordingly.
Code: Select all
#include "FiveWin.ch"
function Main()
local oDlg, cFirst := Space( 20 ), cLast := Space( 20 )
Local oGet1, oGet2, oGet3, oGet4, oGet5, oGet6, oGet7, oGet8
Local cVar1, cVar2, cVar3, cVar4, cVar5, cVar6, cVar7, cVar8
DEFINE DIALOG oDlg TITLE "Test"
@ 1, 1 GET oGet1 VAR cGet1
@ 2, 1 GET oGet2 VAR cGet2
@ 3, 1 GET oGet3 VAR cGet3 //3 rd control , moved from last line
@ 4, 1 GET oGet4 VAR cGet4
@ 5, 1 GET oGet5 VAR cGet5
@ 6, 1 GET oGet6 VAR cGet6
@ 7, 1 GET oGet7 VAR cGet7
@ 8, 1 GET oGet8 VAR cGet8
ACTIVATE DIALOG oDlg CENTERED
return nil
If you want oGet6 to receive the first focus then you should define oGet6 first, then oGet1, oGet2, oGet3 etc.
Code: Select all
@ 6, 1 GET oGet6 VAR cGet6
@ 1, 1 GET oGet1 VAR cGet1
@ 2, 1 GET oGet2 VAR cGet2
Hope it is clear to you.
Regards
Anser
Re: Tab Order
Posted: Sat Sep 19, 2009 9:32 am
by sajith
many thanks for ur reply,
TAB order will work as per the order in which the control is defined/created in your PRG. While coding you have to decide and then write the code accordingly.
it will be very difficult and time consuming if we need to alter the structure of Design after all coding is finished .
Regards,
sajith
Re: Tab Order
Posted: Sat Sep 19, 2009 9:39 am
by anserkk
Dear Mr.Sajith,
it will be very difficult and time consuming if we need to alter the structure after all coding is finished
It is just a matter of moving the Get declaration statement in the prg 1 or 2 line above or below. I don't think it is that difficult.
For eg. see how I changed the tab order based on the example which I posted earlier. The Get objects TAB order changed from 6,1,2 to 2,6, 1
Code: Select all
@ 2, 1 GET oGet2 VAR cGet2
@ 6, 1 GET oGet6 VAR cGet6
@ 1, 1 GET oGet1 VAR cGet1
Regards
Anser
Re: Tab Order
Posted: Sat Sep 19, 2009 9:49 am
by sajith
Many thanks for ur support,
It is just a matter of moving the Get declaration statement in the prg 1 or 2 line above or below. I don't think it is that difficult.
Pls view the below Function ::
Suppose if i add a new control in 24 th position i need to alter position of all control.
Hope u got me
Code: Select all
//------------------------------------------------------------------------------
FUNCTION ClearTextEmpPaySlipData(oDlg) //For Clearing All the Controls In the Dialog
//------------------------------------------------------------------------------
LOCAL oTxtTotalSalary,oTxtPfAmt,oTxtTaxAmt,oTxtLOPAmt,;
oTxtInsAmt,oTxtOtherDeduction, oTxtTAAmt,;
oTxtOtherAdditions,oTxtName ,oTxtBranch,;
oTxtDepartment,oTxtBasicSalary,;
oTxtDAAmt,oTxtHRAAmt,;
oCboMonth ,oTxtSalaryAdvance,oTxtMobRecov,;
oTxtPFArrers,oTxtIncentives,oTxtNoOfLeaves ,;
oTxtMobBill, oTxtPayDate,oBtnsave;
oTxtName :=oDlg:aControls[23]
oTxtBranch:=oDlg:aControls[24]
oTxtDepartment:=oDlg:aControls[25]
oCboMonth:=oDlg:aControls[26]
oTxtPayDate:=oDlg:aControls[27]
oTxtBasicSalary:=oDlg:aControls[28]
oTxtTotalSalary:=oDlg:aControls[44]
oTxtPfAmt:=oDlg:aControls[29]
oTxtTaxAmt:=oDlg:aControls[30]
oTxtNoOfLeaves:=oDlg:aControls[31]
oTxtLOPAmt:=oDlg:aControls[32]
oTxtInsAmt:=oDlg:aControls[33]
oTxtOtherDeduction:=oDlg:aControls[38]
oTxtDAAmt:=oDlg:aControls[39]
oTxtHRAAmt:=oDlg:aControls[40]
oTxtTAAmt:=oDlg:aControls[41]
oTxtOtherAdditions:=oDlg:aControls[43]
oTxtSalaryAdvance:=oDlg:aControls[34]
oTxtMobRecov:=oDlg:aControls[37]
oTxtPFArrers:=oDlg:aControls[35]
oTxtIncentives:=oDlg:aControls[42]
oTxtMobBill :=oDlg:aControls[36]
oBtnsave:=oDlg:aControls[45]
oTxtName:Varput(padr("",40))
oTxtBranch:Varput(padr("",40))
oTxtDepartment:Varput(padr("",40))
oTxtBasicSalary:Varput(Int(0))
oTxtTotalSalary:Varput(Int(0))
oTxtPfAmt:Varput(Int(0))
oTxtTaxAmt:Varput(Int(0))
oTxtLOPAmt:Varput(Int(0))
oTxtInsAmt:Varput(Int(0))
oTxtSalaryAdvance:Varput(Int(0))
oTxtOtherDeduction:Varput(Int(0))
oTxtDAAmt:Varput(Int(0))
oTxtHRAAmt:Varput(Int(0))
oTxtTAAmt:Varput(Int(0))
oTxtOtherAdditions:Varput(Int(0))
oTxtTotalSalary:Varput(Int(0))
oTxtMobRecov:Varput(Int(0))
oTxtPFArrers:Varput(Int(0))
oTxtIncentives:Varput(Int(0))
oTxtNoOfLeaves:Varput(Int(0))
oTxtMobBill:Varput(Int(0))
oCboMonth:Varput(Str(0))
oTxtPayDate:Varput(CToD(""))
oBtnsave:SetFile( "Icons\Save.bmp",)
oDlg:update()
RETURN Nil
Regards,
sajith
Re: Tab Order
Posted: Sat Sep 19, 2009 10:02 am
by anserkk
Dear Sajith,
It all depends on the style of the coding which you adopt. Since you have hard coded the oDlg:aControls[nNo] it may be confusing to you to change the order. If I were to write the code, I would not have used that technique and would have opted some other way, so that editing of the TAB order does not cause too much of complications and does not force me to re-check/alter the whole code in my PRG.
While coding, I always keep in my mind that my client's requirements may change on a later date and I may have to alter the code, and a small change in a code should not create a havoc and should not invite unwanted problems into my app.
Regards
Anser
Re: Tab Order
Posted: Sat Sep 19, 2009 10:26 am
by sajith
Many Many thanks for ur Wise suggestion ,
Since you have hard coded the oDlg:aControls[nNo] it may be confusing to you to change the order. If I were to write the code, I would not have used that technique and would have opted some other way.
can u Pls help me to find a better way to extract the Specific controls(Object) from a Dialog so that it will be really help full for me .
Code: Select all
oTxtName :=oDlg:aControls[23]//My coding style
Regards,
sajith
Re: Tab Order
Posted: Sat Sep 19, 2009 12:23 pm
by Enrico Maria Giordano
Re: Tab Order
Posted: Sat Sep 19, 2009 12:29 pm
by anserkk
Dear Sajith,
I understand that you are passing the Dialog as parameter to the function and using aControls to extract the values from the controls. In your code you are using oDlg:aControls[] referenced by the array subscript no., the subscript no. of the controls changes when you change the order of the controls creation (ie when you wish to change the TAB order etc).
There are different ways to achieve this and one method is that you can use an array to hold the GET controls and then you could have passed the array as parameter to function. Here other well experienced gurus are available in this forum who may be able to give you much better ideas.
Code: Select all
Local aMyControls:={nil,nil,nil,nil,nil,nil,nil}
...
...
@02.3,10 getaMyControls[1] VAR cVar1
@03.4,10 get aMyControls[2] VAR cVar2
@04.5,10 get aMyControls[3] VAR cVar3
@05.6,10 get aMyControls[4] VAR cVar4
@06.7,10 get aMyControls[5] VAR cVar5
@07.8,10 get aMyControls[6] VAR cVar6
@08.9,10 get aMyControls[7] VAR cVar7
DEFINE BUTTON aMyControl[9] .....
.....
ClearTextEmpPaySlipData(oDlg,aMyControl)
//------------------------------------------------------------------------------
FUNCTION ClearTextEmpPaySlipData(oDlg,aMyControl) //For Clearing All the Controls In the Dialog
//------------------------------------------------------------------------------
LOCAL oTxtTotalSalary,oTxtPfAmt,oTxtTaxAmt,oTxtLOPAmt,;
oTxtInsAmt,oTxtOtherDeduction, oTxtTAAmt,;
oTxtOtherAdditions,oTxtName ,oTxtBranch,;
oTxtDepartment,oTxtBasicSalary,;
oTxtDAAmt,oTxtHRAAmt,;
oCboMonth ,oTxtSalaryAdvance,oTxtMobRecov,;
oTxtPFArrers,oTxtIncentives,oTxtNoOfLeaves ,;
oTxtMobBill, oTxtPayDate,oBtnsave;
oTxtName :=aMyControl[1]
oTxtBranch:=aMyControl[2]
oTxtDepartment:=aMyControl[3]
oCboMonth:=aMyControl[4]
oTxtPayDate:=aMyControl[5]
oTxtBasicSalary:=aMyControl[6]
oTxtTotalSalary:=aMyControl[7]
...
....
oBtnsave:=aMyControl[8]
oTxtName:Varput(padr("",40))
oTxtBranch:Varput(padr("",40))
oTxtDepartment:Varput(padr("",40))
oTxtBasicSalary:Varput(Int(0))
oTxtTotalSalary:Varput(Int(0))
oTxtPfAmt:Varput(Int(0))
oTxtTaxAmt:Varput(Int(0))
oTxtLOPAmt:Varput(Int(0))
oTxtMobBill:Varput(Int(0))
oCboMonth:Varput(Str(0))
oTxtPayDate:Varput(CToD(""))
oBtnsave:SetFile( "Icons\Save.bmp",)
oDlg:update()
RETURN Nil
There are other user class named TPublic etc available which can be used instead of using array to hold the controls. If you use the TPublic class, you will be able to refer to the controls in a much meaningful way.
For. eg.
Code: Select all
oMyControl:=TPublic():New(.T.)
oMyControl:cUserName1:=Space(30) // Used to hold data while Adding New User
oMyControl:cPassword1:=Space(10) // Used to hold data while Adding New User
oMyControl:nStatus1 :=1 // Used to hold data while Adding New User
oMyControl:oUserName1:=NIL // Used to hold Objects while Adding New User
oMyControl:oPassword1:=NIL // Used to hold Objects while Adding New User
oMyControl:oStatus1 :=NIL // Used to hold Objects while Adding New User
@01.1,05 get oMyControl:oUserName1 VAR oMyControl:cUserName1 of ..
@02.3,05 get oMyControl:oPassword1 VAR oMyControl:cPassword1 of ...
@03.4,05 RADIO oMyControl:oStatus1 VAR oMyControl:nStatus1 of oFolder:aDialogs[1] ;
ITEMS "Enabled","Disabled" Update
.....
ClearTextEmpPaySlipData(oDlg,oMyControl)
Hope you understand what I am trying to explain to you.
Regards
Anser
Re: Tab Order
Posted: Sat Sep 19, 2009 1:43 pm
by James Bott
Sajith,
If you are using a DBF to store this data, then it is simple to use a database object. To clear all the fields you simply do:
oPaySlip:blank()
oDlg:refresh()
This is much simpler than your approach. All the data is held in an array and calling the blank() method refills the array with blank data.
You can read more about using database objects in some articles that I wrote which are available on my website at
http://www.gointellitech.com.
Regards,
James
Re: Tab Order
Posted: Sat Sep 19, 2009 1:51 pm
by Horizon
Hi anserkk,
Where can I find the TPublic class?
Thanks
Re: Tab Order
Posted: Sat Sep 19, 2009 1:55 pm
by James Bott
I suggest rather than using TPublic either using a database class or creating your own class for the object. The database class will automatically create data for all the fieldnames.
James
Re: Tab Order
Posted: Sat Sep 19, 2009 4:40 pm
by Antonio Linares
Sajith,
If you need to give the focus to a specific control then you can do it this way:
Code: Select all
#include "FiveWin.ch"
function Main()
local oDlg, cFirst := Space( 20 ), cLast := Space( 20 )
DEFINE DIALOG oDlg TITLE "Test"
@ 1, 1 GET cFirst
@ 2, 1 GET cLast
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( oDlg:aControls[ 2 ]:SetFocus(), .F. )
return nil
Please notice that .F. must be returned from the ON INIT clause to tell Windows that we are changing the focus sequence order using Method SetFocus()