分享
 
 
 

模拟进程调度(delphi写的)

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ComCtrls, StdCtrls, ExtCtrls, Grids, Calendar, Gauges, jpeg;

type

TForm1 = class(TForm)

Shape1: TShape;

Shape2: TShape;

Shape3: TShape;

Shape4: TShape;

Shape5: TShape;

Shape6: TShape;

Shape7: TShape;

Shape8: TShape;

Shape9: TShape;

Shape10: TShape;

Shape11: TShape;

Shape12: TShape;

StaticText1: TStaticText;

StaticText2: TStaticText;

StaticText3: TStaticText;

StaticText4: TStaticText;

StaticText5: TStaticText;

StaticText6: TStaticText;

StaticText7: TStaticText;

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

Edit5: TEdit;

Edit6: TEdit;

Edit7: TEdit;

Edit8: TEdit;

Edit9: TEdit;

Edit10: TEdit;

Edit11: TEdit;

Edit12: TEdit;

Edit13: TEdit;

Edit14: TEdit;

Edit15: TEdit;

Edit16: TEdit;

Edit17: TEdit;

Edit18: TEdit;

Edit19: TEdit;

Edit20: TEdit;

Edit21: TEdit;

Edit22: TEdit;

Edit23: TEdit;

Edit24: TEdit;

Edit25: TEdit;

Edit26: TEdit;

Edit27: TEdit;

Edit28: TEdit;

Button1: TButton;

Edit29: TEdit;

Timer1: TTimer;

Timer2: TTimer;

ListBox1: TListBox;

Gauge1: TGauge;

Gauge2: TGauge;

Gauge3: TGauge;

Gauge4: TGauge;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Label4: TLabel;

Edit30: TEdit;

Image1: TImage;

Label5: TLabel;

Button2: TButton;

Timer3: TTimer;

Button4: TButton;

Button5: TButton;

Button3: TButton;

Label6: TLabel;

Button6: TButton;

Timer4: TTimer;

procedure Timer1Timer(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Timer2Timer(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Timer3Timer(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button6Click(Sender: TObject);

procedure Timer4Timer(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

type

pcb=record

name:string;

arv:integer;

svt:integer;

stt:integer;

fnt:integer;

zzsj:integer;

dqsj:real;

fnhflg:bool;

sttflg:bool;

end;

pcbx=array[1..4]of pcb;

var

nullflag:bool=false;

forword:bool=false;

subtemp:integer=0;

j:integer=1;

openflg:bool=true;

tempid:integer=1;

fnhnum:integer=0;

pcbnum:integer=0;

ntp:bool=false;

tempok:bool=false;

flag:bool=false;

Form1: TForm1;

showt:tdatetime;

count:integer=-1;

pro:integer=0;

//pcbnum:integer=1;

writeflg:integer=0;

pcbs:pcbx;

ho,min,sec,msec:word;

method:integer=1;

implementation

uses Unit3;

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);

var

w:integer;

f:integer;

begin

if flag=true and nullflag=false then // 改 false 远为 true

begin

count:=count+1;

listbox1.Items.Add(inttostr(count));

for w:=1 to 4 do

begin

if pcbs[w].arv=count then

begin

timer2.Enabled:=false;

pcbnum:=pcbnum+1;

timer2.Enabled:=true;

end;

end;

if openflg=false then

begin

if (count=pcbs[tempid].stt+pcbs[tempid].svt) then

begin

pcbs[tempid].fnhflg:=true;

fnhnum:=fnhnum+1;

if fnhnum=4 then

begin

flag:=false;

pcbs[1].fnt:=pcbs[1].stt+pcbs[1].svt;

pcbs[1].zzsj:=pcbs[1].fnt-pcbs[1].arv;

pcbs[1].dqsj:=pcbs[1].zzsj/(pcbs[1].fnt-pcbs[1].stt);

pcbs[2].fnt:=pcbs[2].stt+pcbs[2].svt;

pcbs[2].zzsj:=pcbs[2].fnt-pcbs[2].arv;

pcbs[2].dqsj:=pcbs[2].zzsj/(pcbs[2].fnt-pcbs[2].stt);

pcbs[3].fnt:=pcbs[3].stt+pcbs[3].svt;

pcbs[3].zzsj:=pcbs[3].fnt-pcbs[3].arv;

pcbs[3].dqsj:=pcbs[3].zzsj/(pcbs[3].fnt-pcbs[3].stt);

pcbs[4].fnt:=pcbs[4].stt+pcbs[4].svt;

pcbs[4].zzsj:=pcbs[4].fnt-pcbs[4].arv;

pcbs[4].dqsj:=pcbs[4].zzsj/(pcbs[4].fnt-pcbs[4].stt);

edit13.Text:=inttostr(pcbs[1].stt);

edit14.Text:=inttostr(pcbs[1].stt+pcbs[1].svt);

edit15.Text:=inttostr(pcbs[1].zzsj);

edit16.Text:=floattostr(pcbs[1].dqsj);

edit17.Text:=inttostr(pcbs[2].stt);

edit18.Text:=inttostr(pcbs[2].stt+pcbs[2].svt);

edit19.Text:=inttostr(pcbs[2].zzsj);

edit20.Text:=floattostr(pcbs[2].dqsj);

edit21.Text:=inttostr(pcbs[3].stt);

edit22.Text:=inttostr(pcbs[3].stt+pcbs[3].svt);

edit23.Text:=inttostr(pcbs[3].zzsj);

edit24.Text:=floattostr(pcbs[3].dqsj);

edit25.Text:=inttostr(pcbs[4].stt);

edit26.Text:=inttostr(pcbs[4].stt+pcbs[4].svt);

edit27.Text:=inttostr(pcbs[4].zzsj);

edit28.Text:=floattostr(pcbs[4].dqsj);

end;

openflg:=true; //改!!!!!true 应为 false

tempok:=false;

end;

end;

for f:=1 to 4 do

begin

if ((count=pcbs[f].stt+pcbs[f].svt) and pcbs[f].fnhflg=true) then

listbox1.Items.Add(pcbs[f].Name+'完成!!!');

end; //for

end;//flag=ture

if openflg=false then

begin

case tempid of

1:begin

if pcbs[1].svt=1 then

begin

gauge1.MaxValue:=2;

gauge1.Progress:=2;

end

else

begin

gauge1.MaxValue:=pcbs[1].svt;

gauge1.Progress:=count-pcbs[1].stt;

end;

end;//1;

2:begin

gauge2.MaxValue:=pcbs[2].svt;

gauge2.Progress:=count-pcbs[2].stt;

end;//2;

3:begin

gauge3.MaxValue:=pcbs[3].svt;

gauge3.Progress:=count-pcbs[3].stt;

end;//3;

4:begin

gauge4.MaxValue:=pcbs[4].svt;

gauge4.Progress:=count-pcbs[4].stt;

end; //4;

end;//case of over

end;// if openflg=false then over

if pcbs[1].fnhflg=true then

gauge1.Progress:=pcbs[1].svt;

if pcbs[2].fnhflg=true then

gauge2.Progress:=pcbs[2].svt;

if pcbs[3].fnhflg=true then

gauge3.Progress:=pcbs[3].svt;

if pcbs[4].fnhflg=true then

gauge4.Progress:=pcbs[4].svt;

end;//procedure over

procedure TForm1.Button1Click(Sender: TObject);

begin

button2.Enabled:=false;

timer3.Enabled:=false;

timer2.Enabled:=true;

timer1.Enabled:=true;

timer4.Enabled:=false;

try

flag:=true;

pcbs[1].name:=edit1.text;

pcbs[1].arv:=strtoint(edit2.text );

pcbs[1].svt:=strtoint(edit3.text );

pcbs[1].sttflg:=false;

pcbs[1].fnhflg:=false;

pcbs[2].name:=edit4.text;

pcbs[2].arv:=strtoint(edit5.text );

pcbs[2].svt:=strtoint(edit6.text );

pcbs[2].sttflg:=false;

pcbs[2].fnhflg:=false;

pcbs[3].name:=edit7.text;

pcbs[3].arv:=strtoint(edit8.text );

pcbs[3].svt:=strtoint(edit9.text );

pcbs[3].sttflg:=false;

pcbs[3].fnhflg:=false;

pcbs[4].name:=edit10.text;

pcbs[4].arv:=strtoint(edit11.text );

pcbs[4].svt:=strtoint(edit12.text );

pcbs[4].sttflg:=false;

pcbs[4].fnhflg:=false;

nullflag:=false;

except

nullflag:=true;

showmessage('请将数据填完整');

end;

end;

procedure TForm1.Timer2Timer(Sender: TObject);

var

i:integer;

begin

if fnhnum<pcbnum then

begin

if ((openflg=true) and (pcbnum>0)) then

begin

for i:=1 to pcbnum do

begin

if pcbs[i].fnhflg=false then

begin

if tempok=false then

begin

subtemp:=tempid;

tempid:=i;

tempok:=true;

end;

if pcbs[i].svt<pcbs[tempid].svt then

begin

//timer1.Enabled:=false;

tempid:=i;

//timer1.Enabled:=true;

end;//if pcbs[i].svt<pcbs[tempid].svt then

end;//for

end;

openflg:=false;

pcbs[tempid].stt:=count;

pcbs[tempid].sttflg:=true;

//listbox1.Items.Add('进程'+pcbs[subtemp].name+'fnh');

listbox1.Items.Add('进程'+pcbs[tempid].name+'被调度');

end;//if(openflg=true and pcbnum>0)then

end;//if fnhnum<pcbnum then

end; //procedure

procedure TForm1.Button2Click(Sender: TObject);

begin

button1.Enabled:=false;

timer1.Enabled:=false;

timer2.Enabled:=false;

timer3.Enabled:=true;

timer4.Enabled:=true;

try

flag:=true;

pcbs[1].name:=edit1.text;

pcbs[1].arv:=strtoint(edit2.text );

pcbs[1].svt:=strtoint(edit3.text );

pcbs[1].sttflg:=true;

pcbs[1].fnhflg:=false;

pcbs[2].name:=edit4.text;

pcbs[2].arv:=strtoint(edit5.text );

pcbs[2].svt:=strtoint(edit6.text );

pcbs[2].sttflg:=false;

pcbs[2].fnhflg:=false;

pcbs[3].name:=edit7.text;

pcbs[3].arv:=strtoint(edit8.text );

pcbs[3].svt:=strtoint(edit9.text );

pcbs[3].sttflg:=false;

pcbs[3].fnhflg:=false;

pcbs[4].name:=edit10.text;

pcbs[4].arv:=strtoint(edit11.text );

pcbs[4].svt:=strtoint(edit12.text );

pcbs[4].sttflg:=false;

pcbs[4].fnhflg:=false;

nullflag:=false;

except

nullflag:=true;

showmessage('请将数据填完整');

end;

end;

procedure TForm1.Timer3Timer(Sender: TObject);

var

m:integer;

begin

if ((flag=true )and (ntp=false)and (nullflag=false)) then

begin//if falg=true then

count:=count+1;

listbox1.Items.Add(inttostr(count));

for m:=1 to 4do

begin //for m:=1 to 5 do

if((pcbs[m].sttflg=true) and (pcbs[m].fnhflg=false))then

begin//if(pcb[m].sttflg=true and pcb[m].fnhflg=false)

if count=pcbs[m].stt+pcbs[m].svt then

begin//if (count=pcbs[m].stt+pcbs[m].svt)then

pcbs[m].fnhflg:=true;

//timer4.Enabled:=false;

pro:=0;

//timer4.Enabled:=true;

listbox1.Items.Add('进程:'+pcbs[m].name+'完成!!');

if m<4 then

begin//if m<4 then

//pcbs[m+1].sttflg:=true;

//pcbs[m+1].stt:=count;

forword:=true;

end;//if m<4 then

pcbs[m].fnt:=count;

pcbs[m].zzsj:=pcbs[m].fnt-pcbs[m].arv;

pcbs[m].dqsj:=pcbs[m].zzsj/(pcbs[m].fnt-pcbs[m].stt);

end;//if (count=pcbs[m].stt+pcbs[m].svt)then

end;//if(pcb[m].sttflg=true and pcb[m].fnhflg=false)

end;//for m:=1 to 5 do

if pcbs[4].fnhflg=true then

begin

ntp:=true;

edit13.Text:=inttostr(pcbs[1].stt);

edit14.Text:=inttostr(pcbs[1].stt+pcbs[1].svt);

edit15.Text:=inttostr(pcbs[1].zzsj);

edit16.Text:=floattostr(pcbs[1].dqsj);

edit17.Text:=inttostr(pcbs[2].stt);

edit18.Text:=inttostr(pcbs[2].stt+pcbs[2].svt);

edit19.Text:=inttostr(pcbs[2].zzsj);

edit20.Text:=floattostr(pcbs[2].dqsj);

edit21.Text:=inttostr(pcbs[3].stt);

edit22.Text:=inttostr(pcbs[3].stt+pcbs[3].svt);

edit23.Text:=inttostr(pcbs[3].zzsj);

edit24.Text:=floattostr(pcbs[3].dqsj);

edit25.Text:=inttostr(pcbs[4].stt);

edit26.Text:=inttostr(pcbs[4].stt+pcbs[4].svt);

edit27.Text:=inttostr(pcbs[4].zzsj);

edit28.Text:=floattostr(pcbs[4].dqsj);

end;

for m:=1 to 4 do

begin

if ((count>=pcbs[m].arv) and (pcbs[m].sttflg=false)) then

if forword=true then

begin

pcbs[m].sttflg:=true;

pcbs[m].stt:=count;

forword:=false;

end;//3and

end;// for m:=1 to 4 do

gauge1.MaxValue:=pcbs[1].svt;

gauge2.MaxValue:=pcbs[2].svt;

gauge3.MaxValue:=pcbs[3].svt;

gauge4.MaxValue:=pcbs[4].svt;

if pcbs[1].sttflg=true and pcbs[1].fnhflg=false then

begin

//gauge1.Progress:=gauge1.MaxValue:=pcbs[1].svt;

gauge1.Progress:=count-pcbs[1].stt;

end// if pcbs[1].sttflg=true and pcbs[1].fnhflg=false then

else if pcbs[1].fnhflg=true then

gauge1.Progress:=pcbs[1].svt;

if pcbs[2].sttflg=true and pcbs[2].fnhflg=false then

begin

gauge2.Progress:=count-pcbs[2].stt;

end// if pcbs[1].sttflg=true and pcbs[1].fnhflg=false then

else if pcbs[2].fnhflg=true then

gauge2.Progress:=pcbs[2].svt;

if pcbs[3].sttflg=true and pcbs[3].fnhflg=false then

begin

gauge3.Progress:=count-pcbs[3].stt;

end// if pcbs[1].sttflg=true and pcbs[1].fnhflg=false then

else if pcbs[3].fnhflg=true then

gauge3.Progress:=pcbs[3].svt;

if pcbs[4].sttflg=true and pcbs[4].fnhflg=false then

begin

gauge4.Progress:=count-pcbs[4].stt;

end// if pcbs[1].sttflg=true and pcbs[1].fnhflg=false then

else if pcbs[4].fnhflg=true then

gauge4.Progress:=pcbs[4].svt;

end; //if falg=true then

end;//procedure over

procedure TForm1.Button3Click(Sender: TObject);

begin

form1.Close;

//end.//do over

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

forword:=false;

subtemp:=0;

j:=1;

openflg:=true;

tempid:=1;

fnhnum:=0;

pcbnum:=0;

ntp:=false;

tempok:=false;

flag:=false;

gauge1.Progress:=0;

gauge2.Progress:=0;

gauge3.Progress:=0;

gauge4.Progress:=0;

button2.Enabled:=true;

button1.Enabled:=true;

count:=-1;

pro:=0;

//pcbnum:integer=1;

writeflg:=0;

flag:=false;

nullflag:=false;

edit1.Text:='';

edit2.Text:='';

edit3.Text:='';

edit4.Text:='';

edit5.Text:='';

edit6.Text:='';

edit7.Text:='';

edit8.Text:='';

edit9.Text:='';

edit10.Text:='';

edit11.Text:='';

edit12.Text:='';

edit13.Text:='系统填写';

edit14.Text:='系统填写';

edit15.Text:='系统填写';

edit16.Text:='系统填写';

edit17.Text:='系统填写';

edit18.Text:='系统填写';

edit19.Text:='系统填写';

edit20.Text:='系统填写';

edit21.Text:='系统填写';

edit22.Text:='系统填写';

edit23.Text:='系统填写';

edit24.Text:='系统填写';

edit25.Text:='系统填写';

edit26.Text:='系统填写';

edit27.Text:='系统填写';

edit28.Text:='系统填写';

pcbs[1].fnhflg:=false;

pcbs[1].sttflg:=false;

pcbs[2].fnhflg:=false;

pcbs[2].sttflg:=false;

pcbs[3].fnhflg:=false;

pcbs[3].sttflg:=false;

pcbs[4].fnhflg:=false;

pcbs[4].sttflg:=false;

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

form3.show;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

form1.FormStyle:=fsstayontop;

animatewindow(handle,2000,AW_center);

form1.FormStyle:=fsnormal;

end;

procedure TForm1.Button6Click(Sender: TObject);

begin

edit1.Text:='A';

edit2.Text:='0';

edit3.Text:='3';

edit4.Text:='B';

edit5.Text:='5';

edit6.Text:='2';

edit7.Text:='C';

edit8.Text:='5';

edit9.Text:='3';

edit10.Text:='D';

edit11.Text:='5';

edit12.Text:='2';

end;

procedure TForm1.Timer4Timer(Sender: TObject);

begin

if ((pcbs[1].arv=count) and (pcbs[1].sttflg=false)) then

begin

forword:=true;

end;

end;

end.

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, jpeg, ExtCtrls, StdCtrls;

type

TForm2 = class(TForm)

Image1: TImage;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

private

{ Private declarations }

public

{ Public declarations }

end;

type

pcb=record

name:string;

arv:integer;

svt:integer;

stt:integer;

fnt:integer;

zzsj:integer;

dqsj:real;

fnhflg:bool;

sttflg:bool;

end;

pcbx=array[1..4]of pcb;

var

Form2: TForm2;

pcbs:pcbx;

implementation

uses Unit1;

{$R *.dfm}

end.

unit Unit3;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ComCtrls, jpeg, ExtCtrls;

type

TForm3 = class(TForm)

RichEdit1: TRichEdit;

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form3: TForm3;

implementation

{$R *.dfm}

end.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有