📄 pentime.pas
字号:
unit pentime;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls,gvas,recethr, Buttons;
type
frametype=record
add:char;
command:char;
len:char;
databuff:array[0..7] of char;
crc:char
end;
type
TtimeForm = class(TForm)
CommSB: TStatusBar;
Timer1: TTimer;
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
CommBtn: TBitBtn;
ExitBtn: TBitBtn;
procedure ExitBtnClick(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure CommBtnClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
private
procedure threaddone(SENDER:TOBJECT);
procedure echomess(var x1:tmessage); message WM_MESSAGE1;
function int2strpad0(n:longint;len:integer):string;
{ Private declarations }
public
{ Public declarations }
end;
var
timeForm: TtimeForm;
flag1,flag:boolean;
txpentime:frametype;
TRYTIMES:INTEGER;
echolen:integer;
implementation
uses menu;
{$R *.DFM}
procedure TtimeForm.ExitBtnClick(Sender: TObject);
begin
close;
end;
procedure TtimeForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9']) and (ord(key)<>8) then
key:=#0;
end;
procedure TtimeForm.FormCreate(Sender: TObject);
var
y,m,d,hour,min,sec,msec:word;
year,week:string;
begin
decodedate(date,y,m,d);
decodetime(time, hour,min,sec,msec);
year:=int2strpad0(Y,4);
delete(year,1,2);
edit1.text:=year;
edit2.text:=int2strpad0(m,2);
edit3.text:=int2strpad0(d,2);
edit4.text:=int2strpad0(hour,2);
edit5.text:=int2strpad0(min,2);
edit6.text:=int2strpad0(sec,2);
week:=int2strpad0(dayofweek(date)-1,2);
flag1:=true;
flag:=false;
end;
function TtimeForm.int2strpad0(n:longint;len:integer):string;
begin
fmtstr(result,'%d',[n]);
while length(result)<len do
result:='0'+result;
end;
procedure TtimeForm.CommBtnClick(Sender: TObject);
var
p1:pchar;
comname,INIFile:string;
wasconnect:boolean;
testb:byte;
DATE1,TIME1:TDATETIME;
begin
CommSB.panels[0].text:='';
CommSB.panels[1].text:='';
CommSB.panels[2].text:='';
try
getmem(p1,16);
comname:='';
inifile:=ExtractFiledir(APPLICATION.EXENAME)+'\'+ExtractFilename(APPLICATION.EXENAME);//+'\hdxgxt.ini';
if not fileexists(inifile) then
inifile:=ExtractFileDir(APPLICATION.EXENAME)+'hdxgxt.ini'
else inifile:=extractfiledir(application.exename)+'\hdxgxt.ini';
if not fileexists(INIFile) then
begin
Application.MessageBox('需要设定串行通讯口','消息',MB_ICONINFORMATION);
exit;
end else
begin
getprivateprofilestring('comports','comportsnumber','01',p1,16,pchar(INIFile));
comname:=p1;
if strtoint(comname)<0 then
begin
Application.MessageBox('串口设置信息丢失,请重新设置串行口','消息',MB_ICONINFORMATION);
exit;
end;
testb:=0;
try
DATE1:=ENCODEDATE(2000+STRTOINT(EDIT1.TEXT),STRTOINT(EDIT2.TEXT),STRTOINT(EDIT3.TEXT));
TIME1:=ENCODETIME(STRTOINT(EDIT4.TEXT),STRTOINT(EDIT5.TEXT),STRTOINT(EDIT6.TEXT),0);
with TWritePenClock.Create(self.handle,strtoint(comname)+1,commsb,DATE1,TIME1) do
BEGIN
OnTerminate := ThreadDone;
END;
CommBtn.enabled:=FALSE;
EXITBtn.Enabled:=FALSE;
except
Application.MessageBox('非法时间格式!','消息',MB_ICONINFORMATION);
end;
end;
finally
freemem(p1,16);
end;
end;
procedure TtimeForm.FormShow(Sender: TObject);
begin
{ scaled:=true;
height:=round(height*longint(screen.height)*96 / 600/screen.pixelsperinch);
width :=round( width *longint(screen.width)*96 / 800/screen.pixelsperinch);
ScaleControls(screen.width, 800);
ScaleControls(96,screen.pixelsperinch);
}
end;
procedure TtimeFORM.threaddone(SENDER:TOBJECT);
BEGIN
CommBtn.enabled:=true;
EXITBtn.Enabled:=true;
END;
procedure TTimeFORM.echomess(var x1:tmessage);
BEGIN
case ord(x1.WParam) of
Msg_Comm:
begin
case ord(x1.lparam) of
Msg_Comm_InitSuccess:CommSB.Panels[0].TEXT:='串口初始化成功';
Msg_Comm_InitFale:Application.MessageBox('串口初始化出错','消息',MB_ICONINFORMATION);
Msg_Comm_DeviceErr:Application.MessageBox('通讯设备不正常,请检查通讯器、连接线和电源','消息',MB_ICONINFORMATION);
Msg_Comm_comerror:Application.MessageBox('通讯失败!可能是您没有正确地选择串行口,请检查!','消息',MB_ICONINFORMATION);
end;
end;
Msg_Pen:
begin
case ord(x1.lparam) of
Msg_Pen_detecting:CommSB.Panels[1].text:='正在联接巡更笔..';
Msg_Pen_present:CommSB.Panels[1].text:='联接到巡更笔';
Msg_Pen_absent:CommSB.Panels[1].text:='联接巡更笔失败!';
Msg_Pen_SetTime:CommSB.Panels[2].text:='正在设置时间...';
Msg_Pen_SetTimeSucc:CommSB.Panels[2].text:='设置时间正确';
Msg_Pen_SetTimefale:CommSB.Panels[2].text:='设置时间错误';
end;
end;
Msg_PCode:
begin
CommSB.Panels[1].Text:='笔号:'+IntTohex(x1.lparam,2);
end;
else ;
end;
END;
procedure TtimeForm.FormActivate(Sender: TObject);
begin
self.Height:=212;
self.Width:=319;
self.Top:=90;
self.Left:=round((mainform.Width-self.Width)/2);
end;
procedure TtimeForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
timeForm :=nil ;
end;
procedure TtimeForm.Timer1Timer(Sender: TObject);
var
y,m,d,hour,min,sec,msec:word;
year,week:string;
begin
Timer1.Interval:=1000;
decodedate(date,y,m,d);
decodetime(time, hour,min,sec,msec);
year:=int2strpad0(Y,4);
delete(year,1,2);
edit1.text:=year;
edit2.text:=int2strpad0(m,2);
edit3.text:=int2strpad0(d,2);
edit4.text:=int2strpad0(hour,2);
edit5.text:=int2strpad0(min,2);
edit6.text:=int2strpad0(sec,2);
end;
procedure TtimeForm.FormPaint(Sender: TObject);
begin
self.Height:=212;
self.Width:=319;
self.Top:=90;
self.Left:=round((mainform.Width-self.Width)/2);
end;
procedure TtimeForm.FormResize(Sender: TObject);
begin
self.Height:=212;
self.Width:=319;
self.Top:=90;
self.Left:=round((mainform.Width-self.Width)/2);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -