unitmain.~pas
来自「智能监控delphi源码, 操作说明 1. 在两台微机上分别运行文件夹中的可」· ~PAS 代码 · 共 1,203 行 · 第 1/3 页
~PAS
1,203 行
Shape2.Brush.Color := clBtnFace;
Image2.Visible:=False;
end;
procedure TFormMain.btnStartGet1Click(Sender: TObject);
begin
//让btnStartGet1按一下显示‘停止录像 ’,再按一下显示‘开始录像’;
SSRec1 := not SSRec1; //停止-开始 标志改变;
if SSRec1 then
begin
rec1 := True; //置录像标志为1,表示正在录像;
btnStartGet1.Caption := '停止录像';
NStartGet1.Enabled := not NStartGet1.Enabled; //让菜单的NStartGet1 和 NStopGet1显示与窗口显示同步;
NStopGet1.Enabled := not NStopGet1.Enabled;
end
else
begin
rec1 := False; //清录像标志为0,表示等待录像;
btnStartGet1.Caption := '开始录像';
NStartGet1.Enabled := True; //让菜单的NStartGet1 和 NStopGet1显示与窗口显示同步;
NStopGet1.Enabled := False;
end;
if (MoniterNo1.Checked) then //让子窗体的按钮也和主窗体的同步;
begin
FormNo1.btnStartGet1.Caption := btnStartGet1.Caption;
end;
//以下处理录制avi文件的程序;
if rec1 then
begin
pnlShowRecoderMessageA.Caption := '摄像头A正在录像'; //在主窗口上显示系统目前的状态;
nn1 := nn1 + 1; //文件存盘编号自动加1;
strn1 := IntToStr(nn1); //将文件存盘编号变成字符串;
AssignFile(f1, '.\Inf\n1.txt'); //在Inf文件夹中创建n1.txt,记录n1值;
Rewrite(f1);
Writeln(f1, IntToStr(nn1));
CloseFile(f1);
VideoCap1.CapTimeLimit := 0;
VideoCap1.VideoFileName := GetAviDir(1) + '\' + FIntToStr(Strn1) + '.avi';
VideoCap1.StartCapture; //开始录像
VideoCap1.DlgVCompression;
WriteDB(Date + Time, VideoCap1.VideoFileName, '1#摄像头出现异常情况'); //将有关的信息写入数据库;
FormRec.tmrRefresh.Enabled := True; //每录完一次刷新一下数据库,使数据库中的信息保持最新
tmrDelayMan1.Enabled := True; //启动自动分段计时器,
tmrFlash1.Enabled := True; //报警信号开始闪烁
end;
if not rec1 then
begin
pnlShowRecoderMessageA.Caption := '摄像头A停止录像'; //在主窗口上显示系统目前的状态;
tmrFlash1.Enabled := False; //报警信号停止闪烁
tmrDelayMan1.Enabled := False;
Shape1.Brush.Color := clBtnFace;
VideoCap1.StopCapture; //停止录像
end;
end;
procedure TFormMain.btnStartGet2Click(Sender: TObject);
begin
//让btnStartGet2按一下显示‘停止录像 ’,再按一下显示‘开始录像’;
SSRec2 := not SSRec2; //修改按扭标志;
if SSRec2 then
begin
rec2 := True; //置录像标志为1,表示正在录像;
btnStartGet2.Caption := '停止录像';
NStartGet2.Enabled := not NStartGet2.Enabled; //让菜单的NStartGet2 和 NStopGet2显示与窗口显示同步;
NStopGet2.Enabled := not NStopGet2.Enabled;
end
else
begin
rec2 := False; //清录像标志为0,表示等待录像;
btnStartGet2.Caption := '开始录像';
NStartGet2.Enabled := True;
NStopGet2.Enabled := False;
end;
if (MoniterNo2.Checked) then //让子窗体的按钮也和主窗体的同步;
begin
FormNo2.btnStartGet2.Caption := btnStartGet2.Caption;
end;
//以下处理录制avi文件的程序;
if rec2 then
begin
pnlShowRecoderMessageB.Caption := '摄像头B正在录像';
nn2 := nn2 + 1; //文件存盘编号自动加1;
strn2 := IntToStr(nn2); //将文件存盘编号变成字符串;
AssignFile(f2, '.\Inf\n2.txt'); //在Inf文件夹中创建n1.txt,记录n1值;
Rewrite(f2);
Writeln(f2, IntToStr(nn2));
CloseFile(f2);
VideoCap2.CapTimeLimit := 0;
VideoCap2.VideoFileName := GetAviDir(2) + '\' + FIntToStr(Strn2) + '.avi';
VideoCap2.StartCapture; //开始录像
VideoCap2.DlgVCompression;
WriteDB(Date + Time, VideoCap2.VideoFileName, '2#摄像头出现异常情况'); //将有关的信息写入数据库;
FormRec.tmrRefresh.Enabled := True; //每录完一次刷新一下数据库
tmrDelayMan2.Enabled := True;
tmrFlash2.Enabled := True;
end;
if not rec2 then
begin
pnlShowRecoderMessageB.Caption := '摄像头B停止录像';
tmrFlash2.Enabled := False;
tmrDelayMan2.Enabled := False;
Shape2.Brush.Color := clBtnFace;
VideoCap2.StopCapture; //停止录像
end;
end;
//状态栏显示系统时间,监控模式,报警方式等信息;
procedure TFormMain.SysTimeTimer(Sender: TObject);
var days: array[1..7] of string;
begin
days[1] := '星期日';
days[2] := '星期一';
days[3] := '星期二';
days[4] := '星期三';
days[5] := '星期四';
days[6] := '星期五';
days[7] := '星期六';
stat1.Panels[3].Text :=
TimeToStr(Time) + ' ' + DateToStr(Date) + '(' + days[DayOfWeek(Date)] + ')';
if ManMode.Checked then stat1.Panels[2].Text := '您现在选择的是:人工模式'
else stat1.Panels[2].Text := '您现在选择的是:智能模式';
if AlarmOn.Checked then stat1.Panels[1].Text := AlarmOn.Caption
else stat1.Panels[1].Text := AlarmOff.Caption;
end;
//退出系统;
procedure TFormMain.NExit1Click(Sender: TObject);
begin
Close;
end;
//人工模式和自动模式的选择
//选择人工模式,使一些按钮处于可操作状态;
procedure TFormMain.ManModeClick(Sender: TObject);
begin
ManMode.Checked := True; //保证人工模式和智能模式有一个被选中
ComputerMode.Checked := False;
btnStopMoniter1.Enabled := True; //人工模式下的按钮和菜单保证可操作
btnStopMoniter2.Enabled := True;
btnStartGet1.Visible := True;
btnStartGet2.Visible := True;
btnStartGet1.enabled := True;
btnStartGet2.enabled := True;
NStartGet1.enabled := True;
NStartGet2.enabled := True;
NStartGet1.Visible := True;
NStartGet2.Visible := True;
NStopGet1.Visible := True;
NStopGet2.Visible := True;
NStartMoniter1.Visible := True;
NStartMoniter2.Visible := True;
NStopMoniter1.Visible := True;
NStopMoniter2.Visible := True;
BtnAM.Caption := '改为智能监控'; //主窗体上的按钮和系统的运行模式一致
tmrRevStr.Enabled := False; //智能模式下的控件为不响应状态
StopRecordA;
StopRecordB;
end;
//选择智能模式的时候,让与人工模式有关的按钮都处于不可操作状态;
procedure TFormMain.ComputerModeClick(Sender: TObject);
begin //只有当2个摄像头同时处于实时监控时,并且监控设备打开的情况下,才可以选择人工模式;
if (MoniterAll.Checked and OCMon1 and OCMon2) then
begin
ComputerMode.Checked := True;
ManMode.Checked := False; // 人工模式下的按钮和菜单保证不可操作
btnStopMoniter1.Enabled := False;
btnStopMoniter2.Enabled := False;
btnStartGet1.Visible := False;
btnStartGet2.Visible := False;
NStartGet1.Visible := False;
NStartGet2.Visible := False;
NStopGet1.Visible := False;
NStopGet2.Visible := False;
NStartMoniter1.Visible := False;
NStartMoniter2.Visible := False;
NStopMoniter1.Visible := False;
NStopMoniter2.Visible := False;
BtnAM.Caption := '改为人工监控';
tmrRevStr.Enabled := True; //定时器使能;
end
else
Application.MessageBox('必须先打开摄像头才能选择“智能监控”方式!', '警告',
MB_OK + MB_ICONWARNING);
end;
//启动报警和取消报警的选择
procedure TFormMain.AlarmOnClick(Sender: TObject);
begin
AlarmOn.Checked := True;
AlarmOff.Checked := False;
end;
procedure TFormMain.AlarmOffClick(Sender: TObject);
begin
AlarmOff.Checked := True;
AlarmOn.Checked := False;
end;
//点击菜单项中开始录象,要与窗口保持一直
//对1#开始录象菜单的处理
procedure TFormMain.NStartGet1Click(Sender: TObject);
begin
btnStartGet1.Click;
end;
//对1#结束录象菜单的处理;此时应该清录像标志rec1,使rec1:=0;
procedure TFormMain.NStopGet1Click(Sender: TObject);
begin
btnStartGet1.Click;
end;
//对2#开始录象菜单的处理,与前面类似;
procedure TFormMain.NStartGet2Click(Sender: TObject);
begin
btnStartGet2.Click;
end;
//对2#结束录象菜单的处理,与前面类似;
procedure TFormMain.NStopGet2Click(Sender: TObject);
begin
btnStartGet2.Click;
end;
//开始运行系统时,系统处于2个摄像头同时监控模式;
procedure TFormMain.MoniterAllClick(Sender: TObject);
begin
if FormNo1.VideoCap1.DriverOpen then FormNo1.btnStopMoniter1.Click;
if FormNo2.VideoCap2.DriverOpen then FormNo2.btnStopMoniter2.Click;
Delay(200); //若1\2单独窗口已打开,则先关闭.下同
if MoniterNo1.Checked then FormNo1.Visible := False //保证每次只可以监视一个摄像头窗口;
else if MoniterNo2.Checked then FormNo2.Visible := False;
MoniterAll.Checked := True;
MoniterNo1.Checked := False;
MoniterNo2.Checked := False;
end;
//当选择启动1#摄像头监控方式的情况;此时弹出1#摄像头监控窗体,并且监控已打开;
procedure TFormMain.MoniterNo1Click(Sender: TObject);
begin
if FormNo2.VideoCap2.DriverOpen then FormNo2.btnStopMoniter2.Click;
Delay(200);
VideoCap1.DriverOpen := False; //关闭主窗口相对应的实时监控;
VideoCap1.VideoPreview := False;
VideoCap1.visible := False;
OCMon1 := False; //改变按钮标志
SSRec1 := False;
btnStopMoniter1.Caption := '打开监控';
btnStartGet1.Enabled := False;
btnStopMoniter1.Enabled := False;
if MoniterNo2.Checked then FormNo2.Visible := False; //保证每次只可以显示一个摄像头窗口;
MoniterNo1.Checked := True; //保证每次只有一个菜单项被选中;
MoniterAll.Checked := False;
MoniterNo2.Checked := False;
NStartGet1.Enabled := False;
NStopGet1.Enabled := False;
NStartMoniter1.Enabled := False;
NStopMoniter1.Enabled := False;
FormNo1.show; //显示1#摄像头的监控窗口;
//以下程序是处理监控部分;
FormNo1.VideoCap1.DriverIndex := 0; //直接打开1#摄像头监控窗体;并同时启动实时监控
FormNo1.VideoCap1.visible := True;
FormNo1.VideoCap1.VideoPreview := True;
FormNo1.VideoCap1.DriverOpen := True;
FormNo1.btnStartGet1.Enabled := True;
FormNo1.btnStopMoniter1.Caption := '关闭监控';
FormNo1.btnStartGet1.Caption := '开始录像';
end;
//当选择2#摄像头监控模式的情况,处理方法和前面相同;
procedure TFormMain.MoniterNo2Click(Sender: TObject);
begin
if FormNo1.VideoCap1.DriverOpen then FormNo1.btnStopMoniter1.Click;
Delay(200);
VideoCap2.DriverOpen := False; //关闭主窗口相对应的实时监控;
VideoCap2.VideoPreview := False;
VideoCap2.visible := False;
OCMon2 := False; //改变按钮标志
SSRec2 := False;
btnStopMoniter2.Caption := '打开监控';
btnStartGet2.Enabled := False;
btnStopMoniter2.Enabled := False;
if MoniterNo1.Checked then FormNo1.Visible := False; //保证每次只可以监视一个摄像头窗口;
MoniterNo2.Checked := True; //保证每次只有一个菜单项被选中;
MoniterAll.Checked := False;
MoniterNo1.Checked := False;
NStartGet2.Enabled := False;
NStopGet2.Enabled := False;
NStartMoniter2.Enabled := False;
NStopMoniter2.Enabled := False;
FormNo2.Show; //显示2#摄像头的监控窗口;
//以下程序是处理监控部分;
FormNo2.VideoCap2.DriverIndex := 0; //直接打开2#摄像头监控窗体;并同时启动实时监控
FormNo2.VideoCap2.visible := True;
FormNo2.VideoCap2.VideoPreview := True;
FormNo2.VideoCap2.DriverOpen := True;
FormNo2.btnStartGet2.Enabled := True;
FormNo2.btnStopMoniter2.Caption := '关闭监控';
FormNo2.btnStartGet2.Caption := '开始录像';
end;
//系统开始运行的时候 显示2个摄像头同时监控的窗口,并对现场的情况进行实时监控
//同时创建Avi1,Avi2和Inf文件夹,并检查是否存在n.txt,如果存在则读取其内容
//还要对一些按钮及标志等进行初始化;程序的具体代码如下:
procedure TFormMain.FormCreate(Sender: TObject);
begin //创建Avi1 , Avi2 和Inf 文件夹
if not DirectoryExists('Avi1') then MkDir('Avi1');
if not DirectoryExists('Avi2') then MkDir('Avi2');
if not DirectoryExists('Inf') then MkDir('Inf');
if FileExists('.\Inf\n1.txt') then
begin //读取文本文件n1.txt的内容
AssignFile(F1, '.\Inf\n1.txt');
Reset(F1);
Readln(F1, str1);
nn1 := StrToInt(str1);
CloseFile(F1);
end;
if FileExists('.\Inf\n2.txt') then //读取文本文件n2.txt的内容
begin
AssignFile(F2, '.\Inf\n2.txt');
Reset(F2);
Readln(F2, str2);
nn2 := StrToInt(str2);
CloseFile(F2);
end;
FormMain.Height := 600; //设置主窗口的大小
FormMain.Width := 800;
CommRevStr := '0101';
Comm1.StopComm;
Comm1.StartComm;
SSRec1 := False; //对按钮标志进行初始化
SSRec2 := False;
OCMon1 := False;
OCMon2 := False;
pnlShowRecoderMessageA.Caption := '摄像头A已关闭'; //对系统运行状态进行初始化
pnlShowRecoderMessageB.Caption := '摄像头B已关闭';
FlashN1 := '0'; //报警闪烁的初始化
FlashN2 := '0';
Shape1.Brush.Color := clBtnFace;
Shape2.Brush.Color := clBtnFace;
AOrM := 1;
end;
//btnStopMoniter1按下时,打开/关闭1#摄像头,对现场开始/停止实时监控
procedure TFormMain.btnStopMoniter1Click(Sender: TObject);
begin
OCMon1 := not OCMon1; //改变按钮标志;
if OCMon1 then
begin
btnStartGet1.Enabled := True; //打开监控设备时,便可以随时开始录像;
btnStopMoniter1.Caption := '关闭监控'; //按钮显示内容的修改
videocap1.DriverIndex := 0; //打开1#摄像头,开始监控;
VideoCap1.DriverOpen := True;
VideoCap1.VideoPreview := True;
VideoCap1.visible := True;
NStartGet1.Enabled := True; //菜单的操作应和按钮的操作配合起来;
NStartMoniter1.Enabled := False;
NStopMoniter1.Enabled := True;
pnlShowRecoderMessageA.Caption := '摄像头A已打开'; //在主窗体上显示系统目前的状态
end
else
begin //停止监控的处理;
btnStartGet1.Enabled := False;
btnStartGet1.Caption := '开始录像';
SSRec1 := False; //开始/停止录像的按钮标志清零
btnStopMoniter1.Caption := '打开监控'; //按钮显示内容的修改
VideoCap1.DriverOpen := False; //关闭1#摄像头,停止监控
VideoCap1.VideoPreview := False;
VideoCap1.visible := False;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?