Subject |
Re: Form to Form |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Mon, 12 Jun 2023 12:50:40 +0200 |
Newsgroups |
dbase.getting-started |
Attachment(s) |
editor_example.wfm |
On 2023/06/11 17:36, Mervyn Bick wrote:
> More, perhaps later otherwise tomorrow.
>
> Mervyn.
Why didn't the Edit form open with the correct record selected? There
were two problems in the Edit form and one in the main form.
Firstly, in the Edit form
this.QUERY1 = new QUERY(this)
with (this.QUERY1)
left = 812.0
top = 11.0
width = 39.0
height = 37.0
database = form.database1
databaseName = "MYTEST"
sql = "select * from patientmervyn"
active = true
indexName = "pat_no" //******
endwith
Indexname is not a property of the query object. It is a property of
the rowset that the query creates in memory. What happens here is that
dBASE creates a user-defined property of the query. dBASE doesn't know
what to do with the contents of a user-defined property unless code is
written to access the property. Because the rowset does not have an
index set findkey() doesn't work.
The correct way (which would have been streamed out if you had used the
Inspector to set the index)
this.QUERY1 = new QUERY(this)
with (this.QUERY1)
left = 812.0
top = 11.0
width = 39.0
height = 37.0
database = form.database1
sql = "select * from patientmervyn"
active = true
endwith
with (this.QUERY1.rowset)
indexName = "PAT_NO"
endwith
Secondly in the Edit form
function form_onOpen()
form.query1.rowset.FINDKEY(cpat_no)
form.query1.requery()
return
This would negate any changes you made to the rowset in the instance of
the Edit form which is tucked away in a user-defined property of the
main form.
In the main form
function PBGOEDIT_onClick
.......
form.editpatMervyn.query1.rowset.findkey(cpat_no)
//form.editpatMervyn.query1.requery() ******* This was the culprit that
//always caused the Edit form to open with Harry Potter's details!!!!
......
return
I haven't dug too deep into the Edit form other than to make sure it
shows the details for the selected patient but bear in mind that
beginAppend() blanks ALL datalinked controls. This is fine for when you
need to add a new patient's details but we're in a catch22 situation
here. As things stand you can't open the Edit form unless the patient
is already in the patient table. You can, however, use beginEdit() if
you want to change a phone number or an address or enter the next
appointment date.
Perhaps a pushbutton on the main form to add a new patient? This could
add a new record to the patient table with a new pat_no before executing
PBGOEDIT_onClick(). As a record would exist in the patient table
beginEdit() would still be appropriate even though all the datalinked
controls are blank.
Something I did notice is that you've used a memofield datalinked to an
entryfield. Looking at the memo will be like looking through a keyhole.
:-( Rather use an editor control which you can increase in size when it
gets focus.
If you are going to use datalinked controls, drag them from the Field
Palette rather than setting datalinks by hand. If you had dragged the
field from the Field Palette dBASE would automatically have used an
editor control. :-) A little example is attached.
Long messages can be counter productive so enough for now. Stay tuned
for the next exciting episode. :-)
Mervyn.
| ** END HEADER -- do not remove this line
//
// Generated on 2023-06-12
//
parameter bModal
local f
f = new editor_exampleForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class editor_exampleForm of FORM
with (this)
onLeftMouseUp = class::FORM_ONLEFTMOUSEUP
doubleBuffered = false
height = 16.0
left = 27.7143
top = 2.6818
width = 47.1429
text = ""
endwith
this.PATIENTMERVYN1 = new QUERY(this)
with (this.PATIENTMERVYN1)
top = 13.0
width = 11.0
height = 1.0
sql = 'select * from "D:\Examples\Plus2019\Peter\patientMervyn.DBF"'
active = true
endwith
this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
height = 1.0
left = 7.5714
top = 3.6364
width = 8.0
value = "Entryfield1"
endwith
this.ENTRYFIELD2 = new ENTRYFIELD(this)
with (this.ENTRYFIELD2)
height = 1.0
left = 7.5714
top = 5.6818
width = 8.0
value = "Entryfield2"
endwith
this.EDITORPATMEMO1 = new EDITOR(this)
with (this.EDITORPATMEMO1)
onGotFocus = class::EDITORPATMEMO1_ONGOTFOCUS
onLostFocus = class::EDITORPATMEMO1_ONLOSTFOCUS
height = 1.0
left = 7.5714
top = 7.7273
width = 20.0
dataLink = form.patientmervyn1.rowset.fields["patmemo"]
endwith
this.ENTRYFIELD3 = new ENTRYFIELD(this)
with (this.ENTRYFIELD3)
height = 1.0
left = 7.5714
top = 9.8182
width = 8.0
value = "Entryfield3"
endwith
this.ENTRYFIELD4 = new ENTRYFIELD(this)
with (this.ENTRYFIELD4)
height = 1.0
left = 7.5714
top = 12.1818
width = 8.0
value = "Entryfield4"
endwith
this.TEXTLABEL1 = new TEXTLABEL(this)
with (this.TEXTLABEL1)
visible = false
height = 1.0
left = 2.4286
top = 0.7273
width = 40.1429
text = "TAB or left-click on form to close Editor control."
endwith
this.rowset = this.patientmervyn1.rowset
function EDITORPATMEMO1_onGotFocus()
form.textlabel1.visible = true
form.entryfield3.visible = false
form.entryfield4.visible = false
this.height = 13.0
this.left = 6.4286
this.top = 2
this.width = 30.0
return
function EDITORPATMEMO1_onLostFocus()
form.textlabel1.visible = false
form.entryfield3.visible = true
form.entryfield4.visible = true
//Must use form.EDITORPATMEMO1.height instead of this.height otherwise
//form properties are changed when the mouse is clicked on thr form.
form.EDITORPATMEMO1.height = 1.0
form.EDITORPATMEMO1.left = 6.4286
form.EDITORPATMEMO1.top = 7.6364
form.EDITORPATMEMO1.width = 20.0
form.entryfield3.setfocus()
return
function form_onLeftMouseUp(flags, col, row)
if form.EDITORPATMEMO1.height <>1 //i.e editor control is enlarged
form.EDITORPATMEMO1_onLostFocus()
endif
return
endclass
|
|