?
Solved

Calling procedures from within timerproc gives violation exception

Posted on 2003-02-19
4
Medium Priority
?
259 Views
Last Modified: 2010-04-04
procedure TfrmVoiceTextAPI.Button1Click(Sender: TObject);
begin
  OleCheck(Voice.Speak(PChar(memText.Text), 0, nil));
end;

the above works and i get text to speech

******************

procedure TfrmVoiceTextAPI.Button1Click(Sender: TObject);
begin
  settimer(application.Handle, 2, 1000, @TfrmVoiceTextAPI.myTimerProc);
end;

procedure TfrmVoiceTextAPI.myTimerProc(hwnd : HWND; uMsg, idEvent : UINT;
                          dwTime :DWORD);
begin
  killtimer(application.Handle, 2);
  OleCheck(Voice.Speak(PChar(memText.Text), 0, nil));
end;

this fails with violation exception

I have defined timerproc with no calling convention and with stdcall but both fail.
0
Comment
Question by:bigpeta
[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 34

Accepted Solution

by:
Slick812 earned 150 total points
ID: 7984747
hello bigeta, This is a common misteak, the windows system need a fuction address in SetTimer, not a Method address, the @TfrmVoiceTextAPI.myTimerProc is a Method Address, you need to use a procedure that id NOT in a Class, you might try something like this -



procedure TimerProc(Wnd, Mesg, TimerID, SysTime: Integer); stdcall;
begin
 killtimer(Handle, 2);
 OleCheck(frmVoiceTextAPI.Voice.Speak(PChar(memText.Text), 0, nil));
end;


procedure TfrmVoiceTextAPI.Button1Click(Sender: TObject);
begin
 settimer(Handle, 2, 1000, @TimerProc);
end;


- - - - - - - - -  - - - - - - - - - -  --

be sure the TimerProc is above the ButtonClick

ask questions if you need more info
0
 
LVL 34

Expert Comment

by:Slick812
ID: 7984752
should be

procedure TimerProc(Wnd, Mesg, TimerID, SysTime: Integer); stdcall;
begin
killtimer(frmVoiceTextAPI.Handle, 2);
OleCheck(frmVoiceTextAPI.Voice.Speak(PChar(memText.Text), 0, nil));
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 7989382
Slick is right. If you want to use a method, please use TTimer instead of the pure win32 APIs.
0
 

Author Comment

by:bigpeta
ID: 7992392
I had to make one more adjustment - having taken timerproc outside the scope of the form owner I had to fully qualify the memo text access with
frmVoiceTextAPI.memText.Text
thank you slick for a prompt reply.
0

Featured Post

Technology Partners: 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

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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