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

📄 列表5.26.txt

📁 klinux书籍的配套光盘。可以学习学习。
💻 TXT
字号:
【列表5.26】 来自frmRunScheduled.pas的原代码片段。
{
 frmRunScheduled-A demo visual interface to the crontab scheduling daemon
}
unit frmRunScheduled;
{...}

const
 NumDOW = 7;
 NumMonths = 12;
{...}
procedure TRunSchedul edMainForm.WriteCron File;
const
IOMode = 'r'; { read mode from pipe (not used) }
var
 Command : array[0. .128] of char;
 CronFIte : TextFile;
 CronFileName : array[0. .128] of char;
 CronSpec : String;
 F : PIOFile;
 ErrNum : Integer;
begin
 CronSpec := ' ';
 if CreateCronSpec(CronSpec)
  then begin
         tmpnam (CronFileName);
         StrCopy(Cornmand, 'crontab ');
         StrCat(Command, CronFileName);

         AssignFile (CronFile, CronFileName);
         Rewrite (CronFile) ;
         Writeln(CronFile, CronSpec);
         CloseFile(CronFile);

         F := popen(Command, lOMode);
         ErrNum := pclose(F);
         if ErrNum <> -1
          then MessageDIgCSuccess', 'Your schedule has been '
           +'implemented', mtinformation, [mbOK], 0)
          else ErrorMessage(‘Error encountered while trying to '
           + 'close pipe to cron utility');
         DeleteFiIe(CronFileName) ;
        end
   else ErrorMessage('Unable to create the Cron specification file.’);
end;
procedure TRunSchedul edMainForm.Kil ICronFile;
const
  lOMode ='r'; { read mode from pipe (not used) }
var
 Command : array[0. .128] of char;
  F : PIOFile;
  ErrNum : Integer;
begin
 StrCopy(Command, 'crontab -r');
 F := popen(Comtnand, IOMode);
 ErrNum = pclose(F);
 if ErrNum <> -1
 then MessageDIg(‘Success', 'All scheduled events have been killed',
           mtInformation, [mbOK], 0)
 else ErrorMessage( 'Error encountered while trying to ‘
           + 'close pipe to cron utility');
end;

function TRunSchedu1edMainForm.CreateCronSpec(var Spec : String) : Boolean;
var
 s : String;
 i : Integer;
 AIIChecked : Boolean;
begin
 Result := False;
 Spec := ";
 { Do the minutes }
 if MinsListBox.Items.Count = 0
  then begin
        ErrorMessage(‘No minute times specified');
        Exit;
       end;
 for i := 0 to MinsListBox. Items.Count -1 do 
         Spec:= Spec + MinsListBox.ltems[i] + ',';
 if Spec[Length(Spec)]=',' then Delete(Spec, Length(Spec), 1);
 Spec := Spec + ' ';
 { Do the hours }
 if HoursListBox. Items.Count=0
  then begin
        ErrorMessage(‘No hourly times specified');
        Exit:
       end;
 for i := 0 to HoursListBox.Items.Count - 1 do
  Spec := Spec + HoursListBox. Items[i] + '.';
 if Spec[Length(Spec)] = ',' then Delete(Spec, Length(Spec), 1):
 Spec := Spec + ' ';  
{Do the Days}
if AllDaysSelected
  then Spec:=Spec+’*’
else if DOWMlistBox.Items.Count=0
     then begin   
            ErrorMessage(‘No days selected’);
            Exit
         end
     else begin
           for i:=0 to DOWListBox.Items.Count -1 do
          spec:=Spec+DOWListBox.Items[i]+’,’;
if Spec[Length]spec)]=’,’
          then Delete(Spec,Length(Spec),1);
Spec := Spec + ' ';
end
{Do the months}
UpdateMonthsArray;
AllChecked:=True;
for  i:=1 to NumMonths do
    AllChecked :=AllChecked and MonthsBoolArray[i];
If AllChecked
   then  spec:=spec+’*’
else begin 
      for i:=1 to NumMonths do
      If MonthsBool?Array[i] then Spec:=Spec+IntToStr(i)+’,’;
      If  Spec[Length(Spec)]=’,’
        Then  Delete(Spec,Length(Spec),1);
      end;
Spec:=Spec+’,’;

{Do the DOW}
UpdateDOWArray;
AllChecked:=True;
for  i:=0 to NumDOW -1 do
    AllChecked :=AllChecked and DOWBoolArray[i];
If AllChecked
   then  Spec:=Spec+’*’
else begin 
      for i:=1 to NumDOW -1 do
      If DOWBoolArray[i] then Spec:=Spec+IntToStr(i)+’,’;
      If  Spec[Length(Spec)]=’,’
       Then  Delete(Spec,Length(Spec),1);
      end;
Spec:=Spec+’,’;

{Do the command}
s := AppNameEdit. Text;
 Spec := Spec + s;
 if not FileExists(s)
  then begin
           ErrorMessage('Invalid application name');
           Exit;
          end;
 { Add any parameters }
 if Length(ParamEdit.Text) > 0
  then s := s + ' ' + ParamEdit,Text;
 Result := True;
end;
end.

⌨️ 快捷键说明

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