Zitat von
jfheins:
Wie wäre es, wenn due es so in der Art machst:
Delphi-Quellcode:
uses Shutdown, ConfigForm;
procedure TMainForm.Beenden;
var
ShutdownObj: TShutdown;
begin
ShutdownObj := TShutdown.Create;
try
case config_frm.ShutdownSelect.ItemIndex of
0: Close;
1: ShutdownObj.Shutdown (...);
2: ...
end;
finally
FreeAndNil (ShutdownObj);
end;
end;
Das habe ich mal so umgesetzt, funktioniert und ist hoffentlich jetzt einwandfrei....lol
Delphi-Quellcode:
unit ShutDown;
interface
uses
Windows, Messages, SysUtils, Classes;
type
TShutDown =
class(TObject)
private
procedure GetPrivileges;
public
procedure Shutdown(PowerOff,Force :boolean);
procedure Ruhezustand(Force :boolean);
procedure Standby(Force :boolean);
procedure Logoff(Force : boolean);
procedure Restart(Force :boolean);
end;
implementation
procedure TShutDown.GetPrivileges;
//Rechte um runterzufahren holen.
...
...
eine globale Procedure in der Main_frm:
Delphi-Quellcode:
procedure TMain_frm.MMPlayer_beenden;
var
SShutDown: TShutDown;
begin
SShutDown := TShutDown.Create;
try
case config_frm.ShutdownSelect.ItemIndex of
0: begin
Close;
end;
1: begin
Close;
SShutDown.Shutdown(true,config_frm.ShutDown_force_select.Checked);
end;
2: begin
SShutDown.Ruhezustand(config_frm.ShutDown_force_select.Checked);
end;
3: begin
SShutDown.Standby(config_frm.ShutDown_force_select.Checked);
end;
4: begin
Close;
SShutDown.Restart(config_frm.ShutDown_force_select.Checked);
end;
end;
finally
FreeAndNil (SShutDown);
end;
end;
ein Beispielaufruf:
Delphi-Quellcode:
procedure Tmediaplayer_frm.Image14Click(Sender: TObject);
begin
Main_frm.MMPlayer_beenden;
end;