Solved

Pb with multimedia timer in an object

Posted on 1997-06-14
4
291 Views
Last Modified: 2010-04-04
What is wrong with this source code ?
I want to use a multimedia timer in an object (TCanal).

At the first event, instead of calling one time the function, TCanal.Lecture is called two time by the timer and cause access violation error : access violation at 0xa8fee0 read of adress 0xffffffff


//*******************************************************************************************
//TCANAL OBJECT
//*******************************************************************************************

TCanal = class(TPanel)
  private
    timer : MMRESULT;
    procedure Lecture(uID : UINT; uMsg : UINT; dwUser : DWORD; dw1 :
DWORD; dw2 : DWORD); pascal;
    procedure StartMesure;
    procedure StopMesure;
  public
  constructor Create(Owner: TComponent); override;
  end;

constructor TCanal.Create(Owner: TComponent);
begin
  inherited Create(Owner);              { Initialisation des parties héritées }
  Parent := TWinControl(Owner);
  StartMesure;
end;

//*******************************************************************************************
// Multimedia timer
//*******************************************************************************************


procedure TCanal.Lecture(uID : UINT; uMsg : UINT; dwUser : DWORD; dw1 :
DWORD; dw2 : DWORD);
begin
     beep;
end;

procedure TCanal.StartMesure;
begin
     timeBeginPeriod(1);
     timer := timeSetEvent(100, 0, @TCanal.Lecture, 0, TIME_PERIODIC );
end;

procedure TCanal.StopMesure;
begin
     timeKillEvent(timer);
     timeEndPeriod(1);
end;

//******************************************************************************************

Thanks in advance.

0
Comment
Question by:turnar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:sleach
ID: 1337029
I can find nothing wrong with Canal.Lecture.  However, you should place the suspect code inside a try/except block and see if that fixes the problem.  
example:

procedure TCanal.Lecture(uID : UINT; uMsg : UINT; dwUser : DWORD; dw1 :
DWORD; dw2 : DWORD);
begin
try
beep;
except
{Do nothing}
end;
end;
0
 

Author Comment

by:turnar
ID: 1337030
It cause access violation error, even with the try/except block.
I get this answer in comp.lang.pascal.delphi.misc :

>>>>>>>>>>>>>>>>>>>>>

Lecture() cannot be an object method, for starters. The timer
procedure is used by the Win32 API, which knows nothing about
the Self-pointer passed to all methods.

Secondly, being a Win32 API, you have to use the 'stdcall' calling
convention instead of 'pascal'.

Thirdly (and least seriously), there is a problem with the
definitions in Windows.pas:

type
  TFNTimeCallBack = procedure(uTimerID, uMessage: UINT; dwUser, dw1,
dw2: DWORD) stdcall;

function timeSetEvent(uDelay, uResolution: UINT;
                      lpFunction: TFNTimeCallBack;
                      dwUser: DWORD; uFlags: UINT): MMRESULT stdcall;

(Basically, Delphi forgets the 'stdcall' in TFNTimeCallback. This
isn't fatal because you can work around it using '@')

>>>>>>>>>>>>>>>>>>>

So, how can I do it ? I need a multimedia timer every time a TCanal instance is created.
Thanks in advance.

Christophe.
0
 
LVL 1

Expert Comment

by:sleach
ID: 1337031
I thought that a try/except block might do the trick.  Im not sure what else might help, so grade me an F, and let others have a try.  Wish I could be of more help. ;)
0
 
LVL 3

Accepted Solution

by:
sperling earned 100 total points
ID: 1337032
Go to my homepage, http://www.info-pro.no/sperling and then download my TimerPool units (with source ofcourse). These implement a THiResTimer class, using a single multimedia timer to distribute timer events to multiple THiResTimer instances. The code should get you started if you won't use it directly.


Regards,

Erik.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question