在Dll中创建了一个函数:function ModifyPass(Com:integer):Boolean;stdcall;
var
Mytime:TTimer;
begin
Mytime:=TTimer.Create(nil);
Mytime.Ontime:=// 时钟执行的任务
end;
问题是: 如何写创建的时钟Mytime其时钟运行时事件。
procedure TForm1.Timer1Timer(Sender: TObject)
var
Mytime:TTimer;
begin
Mytime:=TTimer.Create(nil);
Mytime.Ontime:=// 时钟执行的任务
end;
问题是: 如何写创建的时钟Mytime其时钟运行时事件。
procedure TForm1.Timer1Timer(Sender: TObject)
這樣是不能得到timer觸發的消息,事件的!!看看<<delphi 深度歷險>>
现在就是移到DLL中,无法传递其参数。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
abc: TTimer;
Panel1: TPanel;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
procedure SetPanle(Sender: TObject); // 创建事件
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
time:TTimer;
begin
time:=TTimer.Create(Application);
time.Interval:=10;
time.Enabled:=True;
time.OnTimer:=SetPanle; // time.free;
end;procedure TForm1.SetPanle(Sender: TObject);
begin
Panel1.Caption:=Formatdatetime('yyyy/mm/dd hh:nn:ss',now);
end;end.
下面做个简单的例子,你自己改一下:
library Project2;uses
windows,
SysUtils,
Classes,
ExtCtrls,
Unit1 in 'Unit1.pas' {Form1};
type
aa=class
procedure Timer1Timer(Sender: TObject);
end;
{$R *.res}{ aa }procedure aa.Timer1Timer(Sender: TObject);
begin
{
你的代码
}
end;function ModifyPass(Com:integer):Boolean;stdcall;
var
Mytime:TTimer;
a:aa;
begin
Mytime:=TTimer.Create(nil);
a:=aa.Create ;
Mytime.Ontimer:=a.Timer1Timer// 时钟执行的任务
end;begin
end.
没有创建time,而是使用一个Form上面的time
function ModifyPass(Com:integer):Boolean;stdcall;
begin
ModifyPass_Frm:=TModifyPass_Frm.Create(application);
// Dll中使用的一个ModifyPass_Frm,上面放入控件Timer1; with ModifyPass_Frm do
begin
Checkok:=False;
password_O:=Pass_old;
password_N:=Pass_new;
oper_no:=operno;(以上为ModifyPass_Frm全局变量传入参数)
Timer1.Enabled:=True;
end;//现在可以使用timer,但是在调用完Dll后程序报错啊!
end;
不明白你为什么要在Dll中创建Timer。如果非要如此的话,你可以使用API(SetTimer以及KillTimer)以及你主程序里窗口的Handle来创建一个Timer句柄,这样一来参数都是整数,不会出问题。