![]() |
|
#1
|
|||
|
|||
|
Hi All,
I've got the following requirement; I am busy writing a Winamp Plugin. All Winamp plugins need to be a DLL. The plugin that I am writing has the need for a TTimer component. I need to create the TTimer at runtime. Also I do not want to use a ttimer in a form as I I only access/create the form when it is need. I've tried the following but without "housing" the ttimer component in a form and I would get an error at this line: Timer1.OnTimer := someproc; Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
private
procedure someproc(sender: tobject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.OnTimer := someproc;
end;
procedure TForm1.someproc(sender: tobject);
begin
end;
end.
|
|
#2
|
|||
|
|||
|
You should do it like this :
Code:
library Project1;
uses
Windows,
SysUtils,
Classes,
ExtCtrls;
{$R *.res}
type
TMyTimer = class(TTimer)
private
Procedure DoTimer(Sender: TObject);
end;
var
Timer1: TMyTimer;
procedure EntryPoint(Event: DWord);
begin
// Create an instance of TMyTimer
case Event of
DLL_PROCESS_ATTACH:
begin
Timer1 := TMyTimer.Create(nil);
Timer1.OnTimer := Timer1.DoTimer;
end;
// Free timer on deattach DLL
DLL_PROCESS_DETACH:
Timer1.Free;
end;
end;
{ Timer }
procedure TMyTimer.DoTimer(Sender: TObject);
begin
// Insert your timer code here
end;
begin
Dllproc := @EntryPoint;
EntryPoint(DLL_PROCESS_ATTACH);
end.
|
|
#3
|
|||
|
|||
|
SilverBoy... you ROCK!!!
Your sample code helped me 100%. Just a bit of a question; you do this: EntryPoint(DLL_PROCESS_ATTACH); But I see you never do this: EntryPoint(DLL_PROCESS_DETACH); This there any reason why that is? Many thx!!! |
|
#4
|
|||
|
|||
|
We change the entry point of dll to own event and call it when dll attach to process , it is not possible to do it when dll deattach from process , windows do it automatically , you can test it , change your entry point event code like below :
Code:
procedure EntryPoint(Event: DWord);
begin
// Create an instance of TMyTimer
case Event of
DLL_PROCESS_ATTACH:
begin
Timer1 := TMyTimer.Create(nil);
Timer1.OnTimer := Timer1.DoTimer;
end;
// Free timer on deattach DLL
DLL_PROCESS_DETACH:
begin
ShowMessage('Ok ?');
Timer1.Free;
end;
end;
end;
|
|
#5
|
|||
|
|||
|
Thank you SilverBoy.
I'll try this tonight. You've really helped me out.
|
![]() |
| Tags |
| dll, runtime, ttimer |
| Thread Tools | |
| Display Modes | |
|
|