Solved

Pb with multimedia timer in an object

Posted on 1997-06-14
4
280 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

Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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