unit LastDateUnit;interfaceuses Base64Unit,System.Win.Registry,Vcl.Controls,Winapi.Windows,System.SysUtils;function GetLastDate(LastDate:TDate):Integer;implementation//==============================================================================// 将日期写入到注册表//作者:键盘记忆//日期:2021年5月2日11点49分//==============================================================================function GetLastDate(LastDate:TDate):Integer;var Reg:TRegistry; RegStr,TempStr:String; begin Reg := ''; TempStr := ''; try Reg := TRegistry.Create; Reg.RootKey := HKEY_CURRENT_USER; RegStr := 'SoftWare\Trial'; if Reg.OpenKey(RegStr,False) then begin TempStr := Reg.ReadString('TLastDate'); end; Reg.CloseKey; if TempStr = '' then begin if Reg.OpenKey(RegStr,False) then Reg.WriteString('TLastDate',Base64Encryption(DateToStr(Date))); Reg.CloseKey; Result := 0; end else begin // 当前系统日期<存储值,表明使用者调整过系统日期,提示使用者试用期已到。 if Date < StrToDate(Base64Decryption(TempStr)) then begin if reg.OpenKey(RegStr,False) then Reg.OpenKey('TLastDate',Base64Encryption(DateToStr(LastDate))); Reg.CloseKey; Result := 1; Exit; end; // if StrToDate(Base64Decryption(TempStr)) >= LastDate then begin Result := 1; Exit; end; if Date > LastDate then begin if Reg.OpenKey(RegStr,False) then begin Reg.WriteString('TLastDate',Base64Encryption(DateToStr(LastDate))); end; Reg.CloseKey; Result := 1; Exit; end; //当前系统日期=存储值,则表明当天是最后使用期限,可继续使用软件 if Date = StrToDate(Base64Decryption(TempStr)) then begin Result := 0; Exit; end; Result := 0; if Reg.OpenKey(RegStr,False) then Reg.WriteString('TLastDate',Base64Encryption(DateToStr(Date))); Reg.CloseKey; end; Reg.Destroy; except Result := -1; end; end;end.
(图片来源网络,侵删)
0 评论