unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure ExitWindowsNT(uFlags : integer);
var
  hToken : THANDLE;
  tkp, tkDumb : TTokenPrivileges;
  DumbInt : DWORD;
begin
  FillChar(tkp, sizeof(tkp), 0);
  if not (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES
or TOKEN_QUERY, hToken)) then
  raise Exception.create('OpenProcessToken failed with code '+ inttostr(GetLastError));  LookupPrivilegeValue(nil, pchar('SeShutdownPrivilege'),
  tkp.Privileges[0].Luid);  tkp.PrivilegeCount := 1;
  tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;  AdjustTokenPrivileges(hToken, false, tkp, sizeof(tkDumb), tkDumb, DumbInt);  if GetLastError <> ERROR_SUCCESS then
  Raise Exception.create('AdjustTokenPrivileges failed with code '+ inttostr(GetLastError));  if not ExitWindowsEx(uFlags, 0) then
  Raise Exception.create('ExitWindowsEx failed with code '+ inttostr(GetLastError));end;procedure TForm1.Button1Click(Sender: TObject);
begin
     ExitWindowsNT(EWX_SHUTDOWN OR EWX_POWEROFF);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ExitWindowsNT(EWX_SHUTDOWN OR EWX_REBOOT);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
ExitWindowsEX(EWX_SHUTDOWN OR EWX_LOGOFF,0);
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
     if strtodate(edit1.Text)=date then button1.OnClick(sender);
end;end.
上面是我做的小关机程序,想让时间器响应EDIT的时间作出动作。
谢谢

解决方案 »

  1.   

    不知道楼主的Edit当中的时间格式是什么样的?
    不包含日期的procedure TForm1.Timer1Timer(Sender: TObject);
    begin
         if Now()>=StrToTime(Edit1.Text) then button1.OnClick(sender);
    end;包含日期
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
         if Now()>=StrToDateTime(Edit1.Text) then button1.OnClick(sender);
    end;
      

  2.   

    在DELPHI8中,运行不了,真郁闷
      

  3.   

    在uses中是不是少了单元没有到?
      

  4.   

    还有,我想问一下,跳转语句跳多次怎么写,每次跳转都会用到IF..THEN..
      

  5.   

    var 
      i:word;i:=20;
    case i of
      1://
    2://
    3..8://end
      

  6.   

    这个可能不合适用,以下是代码:procedure TForm1.Button1Click(Sender: TObject);
    var
      i: integer;
    begin
      for i:=0 to ComponentCount-1 do //枚举
      begin
         if Components[i] is TRadioButton then //检查
      begin
         if ((Edit1.Text=('')) or (TRadioButton(Components[i]).Checked=False)) then
                showmessage('没有选定对象或时间有误')
      else
      begin
         if  (TRadioButton(Components[i]).Checked=True) then
              TRadioButton(Components[i]).OnClick(sender);
              button1.Enabled := False;
              button1.Caption :='已开始执行任务';
    end;
    end;
    end;
    end;因我已经定义了 i  我的意思是如果EDIT框为空和RadioButton未被选中成立就弹出消息。并停止跳出语句
    如果两者不成立就执行下一行语言。我很菜的刚学,不要怪我。
      

  7.   

    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up
    up