How could we show a define window into a top level form, where-in screen visible is set to FALSE Because I try it, and it doesn't show-up, maybe i got wrong in coding.
But how about when you are already at the cursor myCursor, with for example it has 15 or more records in it then you are at the no. 5 record of myCursor, then you want to close that temporary table and get those data of that selected record and paste it into that field of your FORM textboxes how will you do that Like in defining window, when you are at a certain record on it & at the press of ENTER Key.. there you are, you get your selected record data pasted in the textboxes of your form.
I try that way but I do not know how to manipulate a certain record on it, myCursor will not disappear when I press the ENTER Key.
can you give me a code using cursor instead of window to manipulate a certain record, I will appreciate that very much.
Ok...this is how it works, I select a group of records using define window (ex. address that begins with letter 'A' so I have Afghanistan, America, Angola, & Asia) then the brows field will show-up over my form with records stated above, then when I select a single record on it by pressing down arrow key to highlight 'America', Once America is highlighted I will press the ENTER Key on it, releasing the defined window, All the data regarding america will be transfered at the form's textboxes.
How could we do that in a cursor and what is the code to release the cursor after you select a certain record on it Because I try to use the cursor like example SELECT mytable.address FROM myaddress WHERE address = lcaddress order by address INTO cursor mycursor then brows....what next, i can only brows the records.
What I want is to select a record on it then press enter then release the cursor, then all the data pertaining the record selected will be transfered at my form's control.
You don't want to close myCursor just yet as it will dissappear forever. Remember a cursor is not a real table (DBF) so it will not have persistence on disk to be reopened later.
What you do to show that record in a form's control (textboxes, etc) is assign the record field to control.value.
Madix, Start thinking how you do that with a browse. If you can browse then there is either a cursor or table open in current workarea. With a browse or programmatically moving record pointer ( say with skip, locate, seek etc ) you can go on any record.
"Transfer to your form" - it depends. If you call a form that uses the same datasession as calling form does all you need is to position the record pointer ( by any means, it might be a browse, grid, listbox, combobox .... ). Your form then simply uses CursorName.FieldName to bind or refer to fileds of that cursor/table.
Here is a sample.
[code] public oForm oForm = createobject("CustomerSampleForm") oForm.Show
define class CustomerSampleForm as Form ShowWindow = 2 && As top level Add object txtCustID as TextBox with controlsource = 'Customer.Cust_id' Add object cmdGetCust as CommandButton with caption = 'Get Customer'
procedure load use customer endproc
procedure cmdGetCust.Click * Create a modal form with a grid on it to locate a customer text to memvar m.lcMyScript noshow local loLocatorForm loLocatorForm = createobject('LocatorForm') loLocatorForm.Show
define class LocatorForm as form ShowWindow = 1 && In top level WindowType = 1 && Modal
add object myGrid as Grid with ReadOnly=.t., RecordSource = 'customer'
endtext
* Show the form with grid on it ExecScript(m.lcMyScript) thisform.refresh endproc
enddefine [/code]
If the called form needed to close cursor/table or in a different datasession then you simply return something so caller could locate the record itself. ie: Called form might return: -The primary key of record -Record number of record -Scatter to name oRecord and return it
Called form -Directly get caller form as a reference and locate record in caller, set values, refresh it etc
You might download Foxyclasses sample from www.foxyclasses.com and check LocatorGrid samples. One of them almost exactly does what you describe and uses a grid on a form.
Here's a runnable example that should give you the basic idea. The optional clause for the DEFINE WINDOW command that is important to remember is IN WINDOW. Cut-N-Paste the code below into a prg and execute it.
Local oForm
oForm =
CREATEOBJECT("TopForm")
oForm.
show()
_screen
.Visible = .F. && Hide Screen
*!* we're going to define our window as being "IN WINDOW TopLevelForm"
DEFINE WINDOW
DefinedWindow AT 1, 15 SIZE 15, 25 IN WINDOW TopLevelForm TITLE "Defined Window" CLOSE FLOAT GROW ZOOM
*!* If we hadn't defined our window as being "IN WINDOW TopLevelForm", we could
*!* still put it in the Top Level Form by using "IN WINDOW TopLevelForm" clause in our
Hmm it might be a few milliseconds faster than creating form with grid on it ( I don't have an idea how you could time that difference ). Then you might also want to regain more milliseconds removing the unnecessary and unoptimizable "go top", moving define and release in "if...endif" block. I don't see anything particular that'd make it faster for MSSQL in this code. If you're seeking you already have those thousands of records in cursor. Maybe you should instead use SPT or parametric views. ie:
[code] lcDescript = alltrim(m.lcDescript)+"%" lnHandle = SQLStringConnect("Driver=SQL server;server=(local);"+; "Trusted_connection=Yes") SQLExec(m.lnHandle,"select * from myDatabase..myTable"+; " where Descript like m.lcDescript","myCursor") SQLDisconnect(m.lnHandle) [/code]
Is there a particular reason you want to use define window Forms are also windows and with VFP it's easier to work with forms. You could do this at runtime:
[code] text to m.myScript noshow oForm = createobject('myForm') oForm.Show
define class myForm as Form AlwaysOnTop = .t. ShowWindow = 1 && In Top level enddefine endtext
Yeah there's a particular reason behind it, For me, define window is easier to use when accessing a record or a group of records in a table, and for my experience it much fastier to look a single record in a hundred thousand records in MSSQL server table if used. Here's my simple example how I use this in accessing record in SQL server. I put that window in LOSTFOCUS property of a textbox when I am seeking a particular record, I try an SQL in a combo box, list box, & etc. clicking a mouse, all is time consuming. seeking a record using a window is unbeatable in speed.
define window mywindow from 18,8 to 30,94 title 'My File' FLOAT SET EXACT OFF SELECT myTable SET ORDER TO TAG Descript GO TOP IF SEEK(alltrim(lcdescription)) activate window mywindow on key label enter RELEASE window mywindow BROWS FIELD Id=myTable.rec_numb, Particular=myTable.Description key ALLTRIM(lcdescription) NOED NOAPP NODEL in window myWindow endif RELEASE wind mywindow
define window
twang
I try that way but I do not know how to manipulate a certain record on it, myCursor will not disappear when I press the ENTER Key.
can you give me a code using cursor instead of window to manipulate a certain record, I will appreciate that very much.
dnilepharaoh
How could we do that in a cursor and what is the code to release the cursor after you select a certain record on it Because I try to use the cursor like example SELECT mytable.address FROM myaddress WHERE address = lcaddress order by address INTO cursor mycursor then brows....what next, i can only brows the records.
What I want is to select a record on it then press enter then release the cursor, then all the data pertaining the record selected will be transfered at my form's control.
Thank you and more power.
Davaren
What you do to show that record in a form's control (textboxes, etc) is assign the record field to control.value.
Ex:
ThisForm.txtCustomerName.Value = MyCursor.CustomerName
ThisForm.txtCity.Value = MyCursor.City
ThisForm.Refresh()
bhaskar karanth
Start thinking how you do that with a browse. If you can browse then there is either a cursor or table open in current workarea. With a browse or programmatically moving record pointer ( say with skip, locate, seek etc ) you can go on any record.
"Transfer to your form" - it depends. If you call a form that uses the same datasession as calling form does all you need is to position the record pointer ( by any means, it might be a browse, grid, listbox, combobox .... ). Your form then simply uses CursorName.FieldName to bind or refer to fileds of that cursor/table.
Here is a sample.
[code]
public oForm
oForm = createobject("CustomerSampleForm")
oForm.Show
define class CustomerSampleForm as Form
ShowWindow = 2 && As top level
Add object txtCustID as TextBox with controlsource = 'Customer.Cust_id'
Add object cmdGetCust as CommandButton with caption = 'Get Customer'
procedure load
use customer
endproc
procedure cmdGetCust.Click
* Create a modal form with a grid on it to locate a customer
text to memvar m.lcMyScript noshow
local loLocatorForm
loLocatorForm = createobject('LocatorForm')
loLocatorForm.Show
define class LocatorForm as form
ShowWindow = 1 && In top level
WindowType = 1 && Modal
add object myGrid as Grid with ReadOnly=.t., RecordSource = 'customer'
endtext
* Show the form with grid on it
ExecScript(m.lcMyScript)
thisform.refresh
endproc
enddefine
[/code]
If the called form needed to close cursor/table or in a different datasession then you simply return something so caller could locate the record itself. ie:
Called form might return:
-The primary key of record
-Record number of record
-Scatter to name oRecord and return it
Called form
-Directly get caller form as a reference and locate record in caller, set values, refresh it etc
You might download Foxyclasses sample from www.foxyclasses.com and check LocatorGrid samples. One of them almost exactly does what you describe and uses a grid on a form.
mcline700
RHTCJohn
Local oForm
oForm =
CREATEOBJECT("TopForm")oForm.
show()_screen
.Visible = .F. && Hide Screen*!* we're going to define our window as being "IN WINDOW TopLevelForm"
DEFINE WINDOW
DefinedWindow AT 1, 15 SIZE 15, 25 IN WINDOW TopLevelForm TITLE "Defined Window" CLOSE FLOAT GROW ZOOM*!* If we hadn't defined our window as being "IN WINDOW TopLevelForm", we could
*!* still put it in the Top Level Form by using "IN WINDOW TopLevelForm" clause in our
*!* activate command below
ACTIVATE WINDOW
DefinedWindow && IN Window TopLevelFormREAD EVENTS
_screen
.Visible = .T. && Show ScreenDEFINE CLASS
TopForm as FormShowWindow
= 2 Name = "TopLevelForm" Caption = "Top Level Form" PROCEDURE DestroyCLEAR EVENTS
ENDPROC
ENDDEFINE
dianascherff
Thank you for the sample of yours, and thank you for giving me that foxy website. It's a nice website too.
nishu
I don't see anything particular that'd make it faster for MSSQL in this code. If you're seeking you already have those thousands of records in cursor. Maybe you should instead use SPT or parametric views. ie:
[code]
lcDescript = alltrim(m.lcDescript)+"%"
lnHandle = SQLStringConnect("Driver=SQL server;server=(local);"+;
"Trusted_connection=Yes")
SQLExec(m.lnHandle,"select * from myDatabase..myTable"+;
" where Descript like m.lcDescript","myCursor")
SQLDisconnect(m.lnHandle)
[/code]
Vahid Nourbin
Is there a particular reason you want to use define window Forms are also windows and with VFP it's easier to work with forms. You could do this at runtime:
[code]
text to m.myScript noshow
oForm = createobject('myForm')
oForm.Show
define class myForm as Form
AlwaysOnTop = .t.
ShowWindow = 1 && In Top level
enddefine
endtext
ExecScript(m.myScript)
[/code]
Leonardo Cantelmo
Here's my simple example how I use this in accessing record
I put that window in LOSTFOCUS property of a textbox when I am seeking a particular record, I try an SQL in a combo box, list box, & etc. clicking a mouse, all is time consuming. seeking a record using a window is unbeatable in speed.
define window mywindow from 18,8 to 30,94 title 'My File' FLOAT
SET EXACT OFF
SELECT myTable
SET ORDER TO TAG Descript
GO TOP
IF SEEK(alltrim(lcdescription))
activate window mywindow
on key label enter RELEASE window mywindow
BROWS FIELD Id=myTable.rec_numb, Particular=myTable.Description key ALLTRIM(lcdescription) NOED NOAPP NODEL in window myWindow
endif
RELEASE wind mywindow