dBASE Programming - Where to declare put the function ?

This is Interesting: Free IT Magazines  
Home > Archive > dBASE Programming > March 2005 > Where to declare put the function ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Where to declare put the function ?
Martin Lambert

2005-03-28, 6:10 pm

I made a form with a timer in it to make a text component flashing.

I did take the example in the OLH about the timer object. In it, there is a
timer on event wich is
a function call wich work great but I don't know where to declare that
function in my form.
When I close the form, I receive an error that my function or class doesn't
exist.

avantrans::update does not exist.

Any idea ?

--
________________________________________
_______
Messages sortants protégés des virus par Norton Antivirus /
Outgoing mail protected against virus by Norton Antivirus


Garry Christensen

2005-03-28, 6:10 pm

G'day Martin,
The timer object is a strange beast - it's scoped to the _app somehow even
though it is created in a form. Closing the form does not extinguish the
timer automatically so you need to do it manually. I put mine in the
form.canClose event: eg. {;form.oTimer.enabled = false; form.oTimer = null;
return true}
See Ya,
Garry

"Martin Lambert" <lambertmartin@videotron.ca> wrote in message
news:1TViLlZLFHA.432@news-server...
>I made a form with a timer in it to make a text component flashing.
>
> I did take the example in the OLH about the timer object. In it, there is
> a timer on event wich is
> a function call wich work great but I don't know where to declare that
> function in my form.
> When I close the form, I receive an error that my function or class
> doesn't exist.
>
> avantrans::update does not exist.
>
> Any idea ?
>
> --
> ________________________________________
_______
> Messages sortants protégés des virus par Norton Antivirus /
> Outgoing mail protected against virus by Norton Antivirus
>



Martin Lambert

2005-03-28, 6:10 pm

I know about to stop the timer. It's quite clear in the example. My problem
is just with the function declaration itself.
Do I have to declare it at the beginning of the form code in the header?

function form_onOpen
this.timer = new Timer( ) // Make timer a property of
the form
this.timer.parent = this // Assign form as timer's
parent
this.timer.onTimer = this.updateMess // Assign method in form to
timer
this.timer.interval = .5 // Fire timer every .5
seconds
this.timer.enabled = true // Activate timer
return

function updateMess() // Where do I have to declare this function ? I
have an error when the form close that updateMess::class does not exist
this.parent.text1.visible = .not. this.parent.text1.visible
return

function Form_onClose()
this.timer.enabled = false
return
--
________________________________________
_______
Messages sortants protégés des virus par Norton Antivirus /
Outgoing mail protected against virus by Norton Antivirus
"Garry Christensen" <junkchristensen@optusnet.com.au> a écrit dans le
message de news: XnU%23M%23ZLFHA.432@news-server...
> G'day Martin,
> The timer object is a strange beast - it's scoped to the _app somehow even
> though it is created in a form. Closing the form does not extinguish the
> timer automatically so you need to do it manually. I put mine in the
> form.canClose event: eg. {;form.oTimer.enabled = false; form.oTimer =
> null; return true}
> See Ya,
> Garry
>
> "Martin Lambert" <lambertmartin@videotron.ca> wrote in message
> news:1TViLlZLFHA.432@news-server...
>
>



Todd Kreuter [dBVIPS]

2005-03-28, 6:10 pm

"Martin Lambert" <lambertmartin@videotron.ca> wrote in message
news:1TViLlZLFHA.432@news-server...
>
> I did take the example in the OLH about the timer object. In it, there is

a
> timer on event wich is
> a function call wich work great but I don't know where to declare that
> function in my form.


function Form_onOpen
this.timer = new timer()
this.timer.parent = this
this.timer.interval = 0.50
this.timer.onTimer = class::timer_onTimer
this.timer.enabled = true

function Form_onClose
this.timer.enabled = false
this.timer.parent = null
// Be sure to include this otherwise your form will not release
naturally.

Todd Kreuter [dBVIPS]


*Lysander*

2005-03-28, 6:10 pm

In article <#zpAYkdLFHA.1404@news-server>, lambertmartin@videotron.ca=20
says...
> Ok and where do you put the function timer_onTimer ?
> In an external PRG file or in the form itself ?
> When I declare it in my form, after the timer stuff, I still
> get the error message (picture included)
>=20
>=20


have a look at the following example.
Mind that 'f' here is declared with public scope, because the OnTimer-
Event does not know any "form","this" or other context- or local-=20
variable.

~~~

public f
f =3D new testtimerForm()
f.Open()

class testtimerForm of FORM
with (this)
scaleFontBold =3D false
height =3D 16
left =3D 37.5714
top =3D 2.9091
width =3D 46.5714
text =3D ""

OnOpen =3D class::FormOnOpen
OnClose =3D class::FormOnClose
endwith

this.TEXT1 =3D new TEXT(this)
with (this.TEXT1)
height =3D 0.7727
left =3D 4.2857
top =3D 2.7273
width =3D 40
text =3D "This form uses a timer for a countdown"
endwith

this.TEXT2 =3D new TEXT(this)
with (this.TEXT2)
height =3D 1
left =3D 4.2857
top =3D 5.4545
width =3D 18.5714
text =3D "Form will close in:"
endwith

this.ENTRYFIELD1 =3D new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
height =3D 1
left =3D 22.8571
top =3D 5.4545
width =3D 8
value =3D "7"
validErrorMsg =3D "Ung=FCltige Eingabe "
endwith

this.timer1 =3D new timer()
this.timer1.parent =3D this
this.timer1.interval =3D 1
this.timer1.ontimer =3D class::countdown
this.timer1.enabled =3D .F.

Function FormOnOpen

Form.Timer1.Enabled =3D .T.

Return

Function CountDown

Local NV01

NV01 =3D 0

NV01 =3D val(ltrim(rtrim(f.entryfield1.value)))-1
f.entryfield1.value =3D str(NV01)
do case
case NV01 <=3D 0
f.close()
endcase

release NV01

return

function FormOnClose

form.timer1.ontimer =3D {;}
form.timer1.enabled =3D .F.
release Object form.timer1
form.timer1 =3D null

f =3D null

release f

Return

endclass
*Lysander*

2005-03-28, 6:10 pm

In article <MPG.1ca8a5899725f8299896ef@news.dbase.com>,=20
nobody@nowhere.com says...

Uchtli!

2 lines are in wrong order

> f =3D null
>=20
> release f


Must be:

release f
f =3D null

~~~

does not matter too much in this case, but nevertheless got mixed up


ciao,
Andr=E9
Howard Mintzer

2005-03-28, 6:10 pm

Here is my timer which makes my text blink. It is declared in the forms
onopen event

this.BlinktextTimer=new timer()
*-- Add a custom array property to store the blinking
controls
this.BlinktextTimer.aBlinkobjects=new array()
*-- Change this interval if you want slower/faster blinking
this.BlinktextTimer.interval=.5
*-- use a single visible property to assure
synchronisation of
*-- blinking
this.BlinktextTimer.visible=.t.
*--Create a reference to FORM since timer()s do not
recognize it
this.BlinktextTimer.parent=form
this.BlinkTextTimer.color="White/Red"
this.BlinkTextTimer.onTimer=;

{;this.color=iif(this.color="White/Red","Red/Red","White/Red");
;for n=1 to this.aBlinkObjects.size;
;this.aBlinkObjects[n].colorNormal=this.color;next}

as you see the onTimer event is actually declared as a codeblock along
with the timer object. In the form's onClose event I have the following:
this.BlinkTextTimer.enabled:=false
this.BlinktextTimer.parent:=null
this.BlinkTextTimer:=null

It works fine for me

Howie


Martin Lambert wrote:

>I made a form with a timer in it to make a text component flashing.
>
>I did take the example in the OLH about the timer object. In it, there is a
>timer on event wich is
>a function call wich work great but I don't know where to declare that
>function in my form.
>When I close the form, I receive an error that my function or class doesn't
>exist.
>
>avantrans::update does not exist.
>
>Any idea ?
>
>
>

Garry Christensen

2005-03-28, 6:10 pm

G'day Martin,
I think you have the updateMess() function in the right place but you should
disable and destroy the timer in the form canClose event rather than the
onClose event. onClose fires after the form has closed and references to
its methods are lost. Any timer events that have occurred while the form is
closing will be queued and will be fired, even though you've disabled the
timer. Disabling the timer only stops new events occurring, it doesn't stop
the queued events from being activated. So the aim is to stop the timer and
destroy it before the form closes (in the canClose), then close the form.
I hope I haven't confused you. See Ya,
Garry


"Martin Lambert" <lambertmartin@videotron.ca> wrote in message
news:5JAKIYbLFHA.1188@news-server...
>I know about to stop the timer. It's quite clear in the example. My problem
>is just with the function declaration itself.
> Do I have to declare it at the beginning of the form code in the header?
>
> function form_onOpen
> this.timer = new Timer( ) // Make timer a property of
> the form
> this.timer.parent = this // Assign form as timer's
> parent
> this.timer.onTimer = this.updateMess // Assign method in form to
> timer
> this.timer.interval = .5 // Fire timer every .5
> seconds
> this.timer.enabled = true // Activate timer
> return
>
> function updateMess() // Where do I have to declare this function ? I
> have an error when the form close that updateMess::class does not exist
> this.parent.text1.visible = .not. this.parent.text1.visible
> return
>
> function Form_onClose()
> this.timer.enabled = false
> return
> --
> ________________________________________
_______
> Messages sortants protégés des virus par Norton Antivirus /
> Outgoing mail protected against virus by Norton Antivirus
> "Garry Christensen" <junkchristensen@optusnet.com.au> a écrit dans le
> message de news: XnU%23M%23ZLFHA.432@news-server...
>
>



Martin Lambert

2005-03-28, 6:10 pm

Thanks all for your replies. Gary's solution did the trick.

Have a good day.

--
________________________________________
_______
Messages sortants protégés des virus par Norton Antivirus /
Outgoing mail protected against virus by Norton Antivirus
"Garry Christensen" <junkchristensen@optusnet.com.au> a écrit dans le
message de news: FylCrjhLFHA.320@news-server...
> G'day Martin,
> I think you have the updateMess() function in the right place but you
> should disable and destroy the timer in the form canClose event rather
> than the onClose event. onClose fires after the form has closed and
> references to its methods are lost. Any timer events that have occurred
> while the form is closing will be queued and will be fired, even though
> you've disabled the timer. Disabling the timer only stops new events
> occurring, it doesn't stop the queued events from being activated. So the
> aim is to stop the timer and destroy it before the form closes (in the
> canClose), then close the form.
> I hope I haven't confused you. See Ya,
> Garry
>
>
> "Martin Lambert" <lambertmartin@videotron.ca> wrote in message
> news:5JAKIYbLFHA.1188@news-server...
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com