Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pb with multimedia timer in an object

Posted on 1997-06-14
4
Medium Priority
?
299 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
  • 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 300 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

916 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