What's I do wrong with TTimer() ?

User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

What's I do wrong with TTimer() ?

Post by dutch »

Dear all,

What did I do wrong with this code? Why TTimer() is not action anything?

oTimer:lActive is .T. but don't do anything.

Code: Select all

#include 'Fivewin.ch'
*----------------*
Function main
local oDlg, oTimer

DEFINE DIALOG oDlg FROM 0, 0 TO 300, 400 PIXEL

DEFINE TIMER oTimer OF oDlg INTERVAL 100 ACTION MsgInfo('Test')


ACTIVATE DIALOG oDlg ON PAINT (oTimer:Activate()) ;
	 VALID (oTimer:DeActivate())

return nil
Regards,
Dutch
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: What's I do wrong with TTimer() ?

Post by Enrico Maria Giordano »

This is a working sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oTmr

    DEFINE DIALOG oDlg

    DEFINE TIMER oTmr OF oDlg;
           INTERVAL 1000;
           ACTION MSGBEEP()

    ACTIVATE DIALOG oDlg;
             ON INIT ( oTmr:hWndOwner := oDlg:hWnd, oTmr:Activate() );
             CENTER

    RELEASE TIMER oTmr

    RETURN NIL
EMG
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Post by dutch »

Dear Enrico,

I have 2 TTimer() in one program. Is it possible to have 2 TTimer()? Because when I change the code as your recommend the Second TTimer() is working well but the First TTimer() is not active anymore. I mean as following sample.

Regards,
Dutch

Code: Select all

Function Main
TTimer()
   Function Sub()
return

Function Sub
TTimer()
return
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is a working sample using two timers:

Code: Select all

#include "Fivewin.ch"


REQUEST HB_GT_GUI_DEFAULT


FUNCTION MAIN()

    LOCAL oDlg, oTmr1, oTmr2

    DEFINE DIALOG oDlg

    DEFINE TIMER oTmr1 OF oDlg;
           INTERVAL 1000;
           ACTION TONE( 440, 1 )

    DEFINE TIMER oTmr2 OF oDlg;
           INTERVAL 1000;
           ACTION TONE( 880, 1 )

    ACTIVATE DIALOG oDlg;
             ON INIT ( oTmr1:hWndOwner := oDlg:hWnd,;
                       oTmr1:Activate(),;
                       oTmr2:hWndOwner := oDlg:hWnd,;
                       oTmr2:Activate() );
             CENTER

    RELEASE TIMER oTmr1
    RELEASE TIMER oTmr2

    RETURN NIL
EMG
User avatar
patrickmast
Posts: 39
Joined: Tue Jan 24, 2006 6:16 pm
Contact:

Post by patrickmast »

Hey Enrico,

Why do you have this REQUEST HB_GT_GUI_DEFAULT in your code?

Patrick
User avatar
patrickmast
Posts: 39
Joined: Tue Jan 24, 2006 6:16 pm
Contact:

Post by patrickmast »

Enrico Maria Giordano wrote:It is needed for Tone() to work.
EMG
Ok :-)
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Post by dutch »

Thanks Enrico,

It works well now.

Regards,
Dutch
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Hi Enrico and friends

I am trying to put 3 TIMERs in the Message Bar of main window.

They are working OK. But when I leave the application window,
one of the timers I have dedfined is still appearing on the desktop.
And when I refresh the desktop, it is getting disappeared.

Based on the signal strength, I am calling different bitmap resources
and painting on the Message bar.

Below is my code.

Can you please point out where I am making mistake.

This is the image obtained from the following code.

Image

Code: Select all

#include "FiveWin.ch"

STATIC oWnd, oFont, oTimer1, oTimer2, oTimer3
STATIC objSMS, oProvider, oNSignalStrength, oSignalStrength

//----------------------------------------------------------------------------//

FUNCTION Main()

* Serial Port Properties
oSMS                   := CreateObject("BulkSMS.Sender")
oSMS:BaudRate    := 9600
oSMS:COMPort     := "COM1"
oSMS:DataBits      := 8
oSMS:Parity          := "N"
oSMS:StopBits      := "1"
oSMS:FlowControl := 0

oSMS:OpenCOMPort()

DEFINE FONT oFont  NAME "Ms Sans Serif"           SIZE 0, -9
DEFINE WINDOW oWnd TITLE "Timer Testing"

SET MESSAGE OF oWnd TO "Signal Test"  ;
    KEYBOARD CLOCK DATE 2007

DEFINE TIMER oTimer1 OF oWnd INTERVAL 400 ACTION GetProvider(oFont,1)
DEFINE TIMER oTimer2 OF oWnd INTERVAL 400 ACTION GetProvider(oFont,2)
DEFINE TIMER oTimer3 OF oWnd INTERVAL 400 ACTION GetProvider(oFont,3)

WndCenter(oWnd:hWnd)

ACTIVATE WINDOW oWnd ON INIT (oTimer1:hWndOwner := oWnd:oMsgBar:hWnd,         ;           
                              oTimer1:Activate(),                             ;  
                              oTimer2:hWndOwner := oWnd:oMsgBar:hWnd,         ;           
                              oTimer2:Activate(),                             ;  
                              oTimer3:hWndOwner := oWnd:oMsgBar:hWnd,         ;           
                              oTimer3:Activate())                             ;   
                     VALID    (DeleteObject( oSignalStrength:hBitmap1 ), .T.)

objSMS:CloseCOMPort()

RELEASE TIMER oTimer1
RELEASE TIMER oTimer2
RELEASE TIMER oTimer3

RETURN nil

**********

FUNCTION GetProvider(oFont, nOpt) 

LOCAL cNewResource

DO CASE
   CASE nOpt = 1
        IF oProvider = nil
           oProvider := TMsgItem():New( oWnd:oMsgBar, "SIM: "+objSMS:NetworkInfo,;
                                        MAX(LEN("SIM: "+objSMS:NetworkInfo)*6.53,100),,nRGB(128,0,128),;
                                       ,.t.,,,, "Service+CRLF+Provider" )
        ENDIF

   CASE nOpt = 2
        IF oNSignalStrength = nil
           oNSignalStrength := TMsgItem():New( oWnd:oMsgBar, "SIGNAL:"+LTRIM(STR(objSMS:SignalStrength))+;
        	                                    "%", 75, oFont,nRGB(0,111,0),,.t.,,,, "" )
           oNSignalStrength:bMsg   := {||"SIGNAL:"+LTRIM(STR(objSMS:SignalStrength))+"%"}
           oNSignalStrength:lTimer := .T.
        ENDIF   

   CASE nOpt = 3
         IF oSignalStrength = nil
            cNewResource           := "SIGNAL"+LTRIM(STR(ROUND(objSMS:SignalStrength /10,0)*10))  
            oSignalStrength        := TMsgItem():New( oWnd:oMsgBar,, 40, oFont,,,.t.,,cNewResource,, "" )
            oSignalStrength:bMsg   := {||GetSignalStrength()}
            oSignalStrength:lTimer := .T.
	 ENDIF
	 
ENDCASE

RETURN nil

**********

STATIC FUNCTION GetSignalStrength()

LOCAL cNewResource

IF VALTYPE(oSignalStrength) = "O"

   DeleteObject( oSignalStrength:hBitmap1 )
   cNewResource             := "SIGNAL"+LTRIM(STR(ROUND(objSMS:SignalStrength/10,0)*10))
   oSignalStrength:hBitmap1 := LoadBitmap( GetResources(), cNewResource ) 
   oSignalStrength:Paint() 

ENDIF

RETURN nil

**********
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

As a stub in the dark, try to put a call to SysRefresh() at the end of the function Main(), just before the return nil statement.

EMG
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Hi Mr.Enrico,

Thank you very much for your quick reply.

I have already tried it. But no sucess!.

By the way as a work around, I want to refresh to desktop as soon
as I quit my application. How to accomplish. Can you please guide
me.

Regards to you,

- Ramesh Babu P
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ramesh,

I don't know if this has anything to do with your problem, but it doesn't look like you are releasing the bitmaps.

James
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Mr.James

Yes as you have suspected, I did not find any logic to release the itmaps ::hBitmap1, ::hBitmap2 used in TMsgItem class by either in Ttimer class, TMsgItem class or TMsgBar Classes.

Mr.Antonio please guide me how to release the bitmap handles when bitmaps are used in the timer and when the Window/Dialog is closed.

Thanks

- Ramesh Babu P
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Ramesh,

I looked at your code again and I see you are releasing one bitmap using DeleteObject(). It is not clear if you have three bitmaps or just one. Which bitmap is still showing after the app is exited? The answer to that may help zero in on the problem.

James
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Post by RAMESHBABU »

Mr.James,

Thanks for your attention.

Actually I have 10 bitmaps each to display signal strength
like bmp10, bmp20, bmp30... bmp100.

Based on the actual signal strength, I am deleting the old
bitmap using

Code: Select all

DeleteObject( oSignalStrength:hBitmap1)
When there is no any change in the signal strength and when I quit
the application, no bitmap is left on the desk top. But when there is
a change in the signal that means when several bitmaps are called
one after another, the last bmp is left on the screen.

I suspect that the following code is not able to delete the bitmaps at all
and the handles of those bitmaps are still left in memory leading to a
leakage.

Code: Select all

DeleteObject( oSignalStrength:hBitmap1)
If you look at the TmsgBar Class you will not find anywhere a logic which
can release the bitmap handles when the object is ended.

- Ramesh Babu P
Post Reply