⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nameunit.pas

📁 delphi LED 显示屏用,带串口发送,内容编辑,演示功能
💻 PAS
字号:
unit nameunit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls,registry, mycomm;

type
  TFormname = class(TForm)
    Panel1: TPanel;
    disptime: TLabel;
    Timer1: TTimer;
    Label4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label5: TLabel;
    Button1: TButton;
    Button2: TButton;
    mycomm1: Tmycomm;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Label1DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
     timedot:boolean;
     com:integer;
     Year, Month, Day: Word;
     calyear,calmonth,calday,startyear,startmonth,startday:word;
     workshopday:array[0..2] of integer;
     FIniFile: TRegIniFile;
     procedure Read_Registry;
     procedure Write_Registry;
     function  readday(year1,month1,day1:word):longint;
     procedure sendsafedata;
  public
    { Public declarations }
  end;

const
     SECTION = 'Default';
     HKEYPATH ='LCXLEDSAFEPARA';

var
  Formname: TFormname;

implementation

uses frmtp;


{$R *.DFM}

procedure TFormname.Read_Registry;
var
    i:integer;
    str:string;
begin
     FIniFile := TRegIniFile.Create(HKEYPATH);
     decodedate(now,year,month,day);

     startyear := FIniFile.Readinteger(SECTION, 'LCXsyear',year);
     startmonth:= FIniFile.Readinteger(SECTION, 'LCXsmonth',month);
     startday := FIniFile.Readinteger(SECTION, 'LCXsday',day);

     calyear := FIniFile.Readinteger(SECTION, 'LCXcyear',year);
     calmonth:= FIniFile.Readinteger(SECTION, 'LCXcmonth',month);
     calday := FIniFile.Readinteger(SECTION, 'LCXcday',day);
     for i:=0 to 2 do
     begin
        str:='LCXworkshopday'+inttostr(i);
        workshopday[i]:=FIniFile.Readinteger(SECTION, str,0);
        if workshopday[i]<0 then workshopday[i]:=0;
     end;
end;

procedure TFormname.Write_Registry;
var
    i:integer;
    str:string;
begin
     FIniFile := TRegIniFile.Create(HKEYPATH);
     FIniFile.Writeinteger(SECTION, 'LCXsyear',startyear);
     FIniFile.Writeinteger(SECTION, 'LCXsmonth',startmonth);
     FIniFile.Writeinteger(SECTION, 'LCXsday', startday);
     FIniFile.Writeinteger(SECTION, 'LCXcyear',calyear);
     FIniFile.Writeinteger(SECTION, 'LCXcmonth',calmonth);
     FIniFile.Writeinteger(SECTION, 'LCXcday', calday);
     for i:=0 to 2 do
     begin
        str:='LCXworkshopday'+inttostr(i);
        FIniFile.writeinteger(SECTION, str,workshopday[i]);
     end;
     FIniFile.Free;
end;

procedure TFormname.Timer1Timer(Sender: TObject);
var
    i:integer;
    klen1,klen2:longint;
begin
    if timedot then  disptime.Caption:=formatdatetime('mm"月"dd"日 "hh":"nn',now)
    else disptime.Caption:=formatdatetime('mm"月"dd"日 "hh" "nn',now);
    timedot:=not timedot;
    decodedate(now,year,month,day);
    if (calyear<>year) or (calmonth<>month) or (calday<>day) then
    begin
        klen1:=readday(year,month,day);
        klen2:=readday(calyear,calmonth,calday);
        for i:=0 to 2 do
        begin
            workshopday[i]:=workshopday[i]+klen1-klen2;
        end;
        calyear:=year;
        calmonth:=month;
        calday:=day;
        edit1.Text:=inttostr(workshopday[0]);
        edit2.Text:=inttostr(workshopday[1]);
        edit3.Text:=inttostr(workshopday[2]);
        Write_Registry;
    end;
end;

procedure TFormname.FormCreate(Sender: TObject);
var
    i:integer;
    klen1,klen2:longint;
begin
    if timedot then  disptime.Caption:=formatdatetime('mm"月"dd"日 "hh":"nn',now)
    else disptime.Caption:=formatdatetime('mm"月"dd"日 "hh" "nn',now);
    timedot:=not timedot;
    Read_Registry;
    decodedate(now,year,month,day);
    klen1:=readday(year,month,day);
    klen2:=readday(calyear,calmonth,calday);
    for i:=0 to 2 do
    begin
        workshopday[i]:=workshopday[i]+klen1-klen2;
    end;
    calyear:=year;
    calmonth:=month;
    calday:=day;
    edit1.Text:=inttostr(workshopday[0]);
    edit2.Text:=inttostr(workshopday[1]);
    edit3.Text:=inttostr(workshopday[2]);
    Write_Registry;
end;

function TFormname.readday(year1,month1,day1:word):longint;
var
   i:integer;
   k:longint;
begin
    k:=365*(year1-1)+(year1-1) div 4+(year1-1) div 400-(year1-1) div 100;
    k:=k+30*(month1-1)+day1;
    for i:=1 to month1-1 do
    begin
         case i of
          1,3,5,7,8,10: k:=k+1;
          2: k:=k-2;
          end;
    end;
    if((year1 mod 4)=0) then
    begin
       if((year1 mod 100)<>0) or ((year1 mod 400)=0) then
             if(month1>2) then k:=k+1;
    end;
    result:=k;
end;

procedure TFormname.Label1DblClick(Sender: TObject);
begin
    timer1.Enabled:=false;
    formname.Hide;
    frmtpsend.ShowModal;
    formname.show;
    timer1.Enabled:=true;
end;

procedure TFormname.Button1Click(Sender: TObject);
begin
    com:=1;
    sendsafedata;
end;

procedure TFormname.Button2Click(Sender: TObject);
begin
    com:=2;
    sendsafedata;
end;

procedure TFormname.sendsafedata;
var
    i,k:integer;
    str1:string;
begin
    if  com=1 then mycomm1.DeviceName:='COM1'
    else   mycomm1.DeviceName:='COM2';
    mycomm1.initcom('9600,N,8,1');
    mycomm1.Opencom;
    mycomm1.sendbyte($55);
    mycomm1.sendbyte($bb);
    mycomm1.senddatetime;
    str1:=edit1.text;
    k:=length(str1);
    while (k<5) do
    begin
        mycomm1.sendbyte($0);
        k:=k+1;
    end;
    k:=length(str1);
    for i:=1 to k do mycomm1.sendbyte(byte(str1[i])-$30);
    str1:=edit2.text;
    k:=length(str1);
    while (k<5) do
    begin
        mycomm1.sendbyte($0);
        k:=k+1;
    end;
    k:=length(str1);
    for i:=1 to k do  mycomm1.sendbyte(byte(str1[i])-$30);
    str1:=edit3.text;
    k:=length(str1);
    while (k<5) do
    begin
        mycomm1.sendbyte($0);
        k:=k+1;
    end;
    k:=length(str1);
    for i:=1 to k do  mycomm1.sendbyte(byte(str1[i])-$30);
    val(edit1.Text,workshopday[0],i);
    val(edit2.Text,workshopday[1],i);
    val(edit3.Text,workshopday[2],i);
    calyear:=year;
    calmonth:=month;
    calday:=day;
    Write_Registry;
    mycomm1.closecom;
end;

procedure TFormname.FormClose(Sender: TObject; var Action: TCloseAction);
var
    i:integer;
begin
    val(edit1.Text,workshopday[0],i);
    val(edit2.Text,workshopday[1],i);
    val(edit3.Text,workshopday[2],i);
    calyear:=year;
    calmonth:=month;
    calday:=day;
    Write_Registry;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -