我的需求是。
有两个事件的触发时间,每个事件都可能不停的触发,没触发一次,则取一次时间
A事件 触发时间1 1有N个值
B事件 触发时间2 2有N个值 如果A事件触发后一直没有触发B事件,则取A事件的第一次触发值做判断标准,跳转到其他事件去 并清空触发时间1.时间2
如果B事件在A事件触发后一分钟内触发了,则清空时间1,然后时间2的最后一个值等一分钟,有新的事件2触发事件,则循环做此步骤,如果一分钟内没有事件2触发,则清空时间1和时间2 跳到其他地方。我大概整理了下应该是:
0<时间2-时间1<60 则清零时间1时间2 与下一个时间2做比较 如果间隔大于零
开始下一次存取 这是我整理后的需求 看明白这个逻辑就OK请各位高手帮忙
有两个事件的触发时间,每个事件都可能不停的触发,没触发一次,则取一次时间
A事件 触发时间1 1有N个值
B事件 触发时间2 2有N个值 如果A事件触发后一直没有触发B事件,则取A事件的第一次触发值做判断标准,跳转到其他事件去 并清空触发时间1.时间2
如果B事件在A事件触发后一分钟内触发了,则清空时间1,然后时间2的最后一个值等一分钟,有新的事件2触发事件,则循环做此步骤,如果一分钟内没有事件2触发,则清空时间1和时间2 跳到其他地方。我大概整理了下应该是:
0<时间2-时间1<60 则清零时间1时间2 与下一个时间2做比较 如果间隔大于零
开始下一次存取 这是我整理后的需求 看明白这个逻辑就OK请各位高手帮忙
解决方案 »
- idhttp难道有问题吗????简单的get就出错啊,高手进,在线急等!!
- DBGrid如何修改行的值而影响数据库
- 关于打包的问题,急呀!请高手指点!
- 菜鸟问题:怎么判断Tedit中为非空?
- 我使用spcomm控件,如果要设置流控制(通讯协议)为以下几个该怎样对应设置spcomm的属性
- 多线程访问数据库,最好有源码!分不够可以再加!!!!
- 很急!!哪位大虾帮帮小弟,问题解决马上给分!!
- 内存总量,请各位大虾帮忙!!
- 如何写一个SQL语句,实现对日期型数据的查询?
- TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);居然不能打开正在执行的文件
- 比较两个文本大小
- delphi 里面的时间计算问题
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Interrupt(const Interruptsource: integer=1);//中断事件,参数对应中断源编号
procedure response_A;//A事件响应处理
procedure response_B;//B事件响应处理 end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=false;
Timer1.Interval:=60000;
Timer2.Enabled:=false;
Timer1.Interval:=60000;
end;procedure TForm1.Interrupt(const Interruptsource: integer=1);
begin
case Interruptsource of
1: begin //中断源为 A事件 的中断源
Timer1.Enabled:=not Timer2.Enabled;//如果B事件不在进行中,打开定时器1
end;
2:begin //中断源为 B事件 的中断源
if Timer1.Enabled then
memo1.Lines.Append('A事件已被B事件屏蔽');
Timer1.Enabled:=false;//屏蔽A事件处理
Timer2.Enabled:=false;//复位定时器2
Timer2.Enabled:=true;//打开定时器2,进行B事件计时
end;
end;
end;procedure TForm1.response_A;//A事件响应处理
begin
//......
memo1.Lines.Append('A事件已响应');
end;procedure TForm1.response_B;//B事件响应处理
begin
//......
memo1.Lines.Append('B事件已响应');
end;procedure TForm1.Timer1Timer(Sender: TObject);//A事件计时1分钟时间到
begin
Timer1.Enabled:=false;//停止计时
response_A;//A事件响应处理
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
Timer2.Enabled:=false;//停止计时
response_B;//B事件响应处理
end;procedure TForm1.Button1Click(Sender: TObject);//模拟引发 A 事件
begin
Interrupt;//或 Interrupt(1); 由于中断过程默认参数为 1 ,所以,可省略参数
memo1.Lines.Append('A 事件中断发生');
end;procedure TForm1.Button2Click(Sender: TObject);//模拟引发 B 事件
begin
Interrupt(2);
memo1.Lines.Append('B 事件中断发生');
end;end.
begin
Timer1.Enabled:=false;
Timer1.Interval:=60000;
Timer2.Enabled:=false;
Timer2.Interval:=60000;//此处原误为Timer1.Interval:=60000;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Interrupt(const Interruptsource: integer=1);//中断事件,参数对应中断源编号
procedure response_A;//A事件响应处理
procedure response_B;//B事件响应处理 end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);//初始化两个定时器
begin
Timer1.Enabled:=false; //停止计时
Timer1.Interval:=60000;//1 分钟计时
Timer2.Enabled:=false; //停止计时
Timer2.Interval:=60000;//1 分钟计时
end;procedure TForm1.Interrupt(const Interruptsource: integer=1);//中断事件
begin
case Interruptsource of //判断中断来源
1: begin //中断源为 A事件 的中断源
Timer1.Enabled:=not Timer2.Enabled;//如果B事件不在进行中,打开定时器1
end;
2:begin //中断源为 B事件 的中断源
if Timer1.Enabled then //如果A事件已发生
memo1.Lines.Append('A事件已被B事件屏蔽');
Timer1.Enabled:=false;//屏蔽A事件处理
Timer2.Enabled:=false;//复位定时器2
Timer2.Enabled:=true;//打开定时器2,进行B事件计时
end;
end;
end;procedure TForm1.response_A;//A事件响应处理
begin
//......
memo1.Lines.Append('1 分钟事件到,A事件已响应');
end;procedure TForm1.response_B;//B事件响应处理
begin
//......
memo1.Lines.Append('1 分钟事件到,B事件已响应');
end;procedure TForm1.Timer1Timer(Sender: TObject);//A事件计时1分钟时间到
begin
Timer1.Enabled:=false;//停止计时
response_A;//A事件响应处理
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
Timer2.Enabled:=false;//停止计时
response_B;//B事件响应处理
end;procedure TForm1.Button1Click(Sender: TObject);//模拟引发 A 事件
begin
Interrupt;//A中断事件。 或 Interrupt(1); 由于中断过程默认参数为 1 ,所以,A 事件可省略参数
if Timer2.Enabled then
memo1.Lines.Append('A 事件中断发生(由于B事件在进行中,A事件不会被响应)')
else
memo1.Lines.Append('A 事件中断发生);
end;procedure TForm1.Button2Click(Sender: TObject);//模拟引发 B 事件
begin
Interrupt(2);//B中断事件
if Timer2.Enabled then //如果 B 事件正在计时
memo1.Lines.Append('B 事件中断再次发生,重新计时')
else
memo1.Lines.Append('B 事件中断发生');
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Value_A, Value_B: integer;
procedure Interrupt(Value_Interrupt: integer; const Interruptsource: integer=1);//中断事件,参数对应中断源编号
procedure response_A;//A事件响应处理
procedure response_B;//B事件响应处理
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);//初始化两个定时器
begin
Timer1.Enabled:=false; //停止计时
Timer1.Interval:=60000;//1 分钟计时
Timer2.Enabled:=false; //停止计时
Timer2.Interval:=60000;//1 分钟计时
Value_A := -1;
end;procedure TForm1.Interrupt(Value_Interrupt: integer; const Interruptsource: integer=1);//中断事件
begin
case Interruptsource of //判断中断来源
1: begin //中断源为 A事件 的中断源
Timer1.Enabled:=not Timer2.Enabled;//如果B事件不在进行中,打开定时器1
if (Value_A = -1)and(not Timer2.Enabled) then Value_A := Value_Interrupt;
end;
2:begin //中断源为 B事件 的中断源
if Timer1.Enabled then begin //如果A事件已发生
Value_A := -1;
memo1.Lines.Append('A事件已被B事件屏蔽');
end;
Timer1.Enabled:=false;//屏蔽A事件处理
Timer2.Enabled:=false;//复位定时器2
Timer2.Enabled:=true;//打开定时器2,进行B事件计时
Value_B := Value_Interrupt;
end;
end;
end;procedure TForm1.response_A;//A事件响应处理
begin
//......
memo1.Lines.Append('满 1 分钟计时,A事件已响应,值为:'+inttostr(Value_A));
Value_A := -1;
end;procedure TForm1.response_B;//B事件响应处理
begin
//......
memo1.Lines.Append('满 1 分钟计时,B事件已响应,值为:'+inttostr(Value_B));
end;procedure TForm1.Timer1Timer(Sender: TObject);//A事件计时1分钟时间到
begin
Timer1.Enabled:=false;//停止计时
response_A;//A事件响应处理
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
Timer2.Enabled:=false;//停止计时
response_B;//B事件响应处理
end;procedure TForm1.Button1Click(Sender: TObject);//模拟引发 A 事件
var i:integer;
begin
Randomize;//初始化
i:=random(100);
if Timer2.Enabled then
memo1.Lines.Append('A 事件中断发生(由于B事件在进行中,A事件不会被响应),中断值为:'
+inttostr(i))
else if Timer1.Enabled then
memo1.Lines.Append('A 事件中断再次发生,中断值为:'+inttostr(i))
else
memo1.Lines.Append('A 事件中断发生,中断值为:'+inttostr(i));
Interrupt(i,1);//A中断事件
end;procedure TForm1.Button2Click(Sender: TObject);//模拟引发 B 事件
var i:integer;
begin
Randomize;//初始化
i:=random(100);
if Timer2.Enabled then //如果 B 事件正在计时
memo1.Lines.Append('B 事件中断再次发生,重新计时,中断值为:'+inttostr(i))
else
memo1.Lines.Append('B 事件中断发生,中断值为:'+inttostr(i));
Interrupt(i,2);//B中断事件
end;end.