FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour What's I do wrong with TTimer() ?
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
What's I do wrong with TTimer() ?
Posted: Mon Apr 21, 2008 05:48 AM
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.

#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
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: What's I do wrong with TTimer() ?
Posted: Mon Apr 21, 2008 07:29 AM
This is a working sample:

#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
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 08:36 AM
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
Function Main
TTimer()
   Function Sub()
return

Function Sub
TTimer()
return
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 08:41 AM
This is a working sample using two timers:

#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
Posts: 39
Joined: Tue Jan 24, 2006 06:16 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 09:41 AM

Hey Enrico,

Why do you have this REQUEST HB_GT_GUI_DEFAULT in your code?

Patrick

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 09:49 AM

It is needed for Tone() to work.

EMG

Posts: 39
Joined: Tue Jan 24, 2006 06:16 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 11:11 AM
Enrico Maria Giordano wrote:It is needed for Tone() to work.
EMG

Ok :-)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
What's I do wrong with TTimer() ?
Posted: Tue Apr 22, 2008 12:43 PM

Thanks Enrico,

It works well now.

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
What's I do wrong with TTimer() ?
Posted: Wed Oct 15, 2008 01:12 PM
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.




#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

**********
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
What's I do wrong with TTimer() ?
Posted: Wed Oct 15, 2008 01:53 PM

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

Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
What's I do wrong with TTimer() ?
Posted: Wed Oct 15, 2008 02:27 PM

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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
What's I do wrong with TTimer() ?
Posted: Wed Oct 15, 2008 05:15 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
What's I do wrong with TTimer() ?
Posted: Thu Oct 16, 2008 08:50 AM

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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
What's I do wrong with TTimer() ?
Posted: Thu Oct 16, 2008 05:07 PM

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
What's I do wrong with TTimer() ?
Posted: Fri Oct 17, 2008 11:16 AM
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

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.

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