读书人

delphi中list的运用有关问题

发布时间: 2012-09-08 10:48:07 作者: rapoo

delphi中list的运用问题
我的需求是。
有两个事件的触发时间,每个事件都可能不停的触发,没触发一次,则取一次时间
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

请各位高手帮忙

[解决办法]
既然你还在关注此帖的,我修正和补充一下吧:

Delphi(Pascal) code
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. 

读书人网 >.NET

热点推荐