Delphi-PRAXiS
Seite 2 von 4     12 34      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Process Priorität setzen - als Variable... (https://www.delphipraxis.net/18163-process-prioritaet-setzen-als-variable.html)

Christian Seehase 19. Mär 2004 20:43

Re: Process Priorität setzen - als Variable...
 
Moin DRPEnc,

also kurz von Vorne:

Delphi-Quellcode:
// Einträge hinzufügen, z.B.
ComboBox1.Items.AddObject('Normale Priorität',TObject(NORMAL_PRIORITY_CLASS));
Aufruf von RunProcess

Delphi-Quellcode:
RunProcess('C:\DRPEncPrediction.bat', SW_SHOW, TRUE, @ProcID,Cardinal(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
Du musst natürlich die Funktion RunProcess auch intern dahingehend erweitern, dass sie die Priorität entsprechend berücksichtigt.

DRPEnc 19. Mär 2004 20:57

Re: Process Priorität setzen - als Variable...
 
Man ich steh mal wieder sehr stark auf dem Schlauch...

So siehts bei mir grad aus:

ComboBox17 mit

ItemIndex0 Idle
ItemIndex1 Normal
ItemIndex2 High

Edit153



Delphi-Quellcode:
var ProcID: Cardinal;
    P: TCaption;
begin

//RunBatch
if form1.ComboBox17.ItemIndex=0 then form1.Edit153.Text:='IDLE_PRIORITY_CLASS';
if form1.ComboBox17.ItemIndex=1 then form1.Edit153.Text:='NORMAL_PRIORITY_CLASS';
if form1.ComboBox17.ItemIndex=2 then form1.Edit153.Text:='HIGH_PRIORITY_CLASS';
ProcID := 0;
P := Edit153.text;
RunProcess('C:\DRPEncPrediction.bat', SW_SHOW, TRUE, @ProcID {, Hier muss Priorität rein});
Kann aber nicht mal ne Variable in den RunProcess setzen.
Kommt immer diese Fehlermeldung:
To many actual parameters.

Irgendeine Idee. Deine Idee kann ich irgendwie nicht umsetzen.

Hier nochmal die Funktion von Luckie:

Delphi-Quellcode:
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD): Longword;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb         := SizeOf(StartupInfo);
  StartupInfo.dwFlags    := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := ShowCmd;
  if not CreateProcess(nil,
    @Filename[1],
    nil,
    nil,
    False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInfo)
    then
      Result := WAIT_FAILED
  else
  begin
    if wait = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
      exit;
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
  end;
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;

Christian Seehase 19. Mär 2004 21:12

Re: Process Priorität setzen - als Variable...
 
Moin DRPEnc,

woher hast Du denn RunProcess, wenn Du es nicht selber geschrieben hast?

Schau Dich hier doch mal nach Hier im Forum suchenCreateProcess oder Hier im Forum suchenShellExecuteEx um.
Eines von beiden wird mit Sicherheit in der Funktion benutzt.

[EDIT]

Ach so, die Funktion ist das.
Dann könnte es so gehen:
(Ausschnitt)

Code:
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD;[color=red]const AdwProcessPriority : DWORD[/color]): Longword;  
    //...
    [color=red]SetPriorityClass(ProcessInfo.hProcess,AdwProcessPriority);[/color]
    if wait = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
      exit;
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
  end;
[EDIT2: Korrektur]
Natürlich vor die Abfrage ob gewartet werden soll oder nicht
[/EDIT]
[/EDIT]

DRPEnc 19. Mär 2004 21:43

Re: Process Priorität setzen - als Variable...
 
Liste der Anhänge anzeigen (Anzahl: 1)
HMM, K jetzt ist es um die Funktion erweitert. Wie aber nun ausführen.
Hab mal ein Beispielproject als Attachment hinzugefügt.

Christian Seehase 19. Mär 2004 21:57

Re: Process Priorität setzen - als Variable...
 
Moin DRPEnc,

Zitat:

Zitat von DRPEnc
Wie aber nun ausführen

so wie vorher, nur dass Du jetzt noch die PriorityClass mit übergeben kannst.

BTW: Nur der Source würde i.d.R. auch genügen.

DRPEnc 19. Mär 2004 22:03

Re: Process Priorität setzen - als Variable...
 
Delphi-Quellcode:
ComboBox1.Items.AddObject('Normale Priorität',TObject(NORMAL_PRIORITY_CLASS));
Wie soll ich das denn verstehen? Habs vorher immer mit TStrings gemacht und dann in ne Edit geschrieben.
AddObject kenn ich noch nicht. :wiejetzt:

DRPEnc 19. Mär 2004 22:08

Re: Process Priorität setzen - als Variable...
 
Delphi-Quellcode:
unit Priority;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD;const AdwProcessPriority : DWORD): Longword;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb         := SizeOf(StartupInfo);
  StartupInfo.dwFlags    := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := ShowCmd;
  if not CreateProcess(nil,
    @Filename[1],
    nil,
    nil,
    False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInfo)
    then
      Result := WAIT_FAILED
  else
  begin
    SetPriorityClass(ProcessInfo.hProcess,AdwProcessPriority);
    if wait = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
      exit;
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
  end;
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.AddObject('Idle Priorität',TObject(IDLE_PRIORITY_CLASS));
ComboBox1.Items.AddObject('Normale Priorität',TObject(NORMAL_PRIORITY_CLASS));
ComboBox1.Items.AddObject('High Priorität',TObject(HIGH_PRIORITY_CLASS));
end;

procedure TForm1.Button1Click(Sender: TObject);
var ProcID, SetPriorityClass: Cardinal;
P: TCaption ;
    begin
//RunBatch

ProcID := 0;
P := Edit1.text;
//SetPriorityClass := 'NORMAL_PRIORITY_CLASS' ;
RunProcess('Test.bat', SW_SHOW, True, @ProcID, Cardinal(ComboBox1.Items.Objects[ComboBox1.ItemIndex]) );
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if form1.ComboBox1.ItemIndex=0 then form1.Edit1.Text:='IDLE_PRIORITY_CLASS';
if form1.ComboBox1.ItemIndex=1 then form1.Edit1.Text:='NORMAL_PRIORITY_CLASS';
if form1.ComboBox1.ItemIndex=2 then form1.Edit1.Text:='HIGH_PRIORITY_CLASS';
end;

end.
Da ist noch fett der Wurm drin...

Christian Seehase 19. Mär 2004 22:25

Re: Process Priorität setzen - als Variable...
 
Moin DRPEnc,

könntest Du den Wurm vielleicht mal näher erläutern?

DRPEnc 19. Mär 2004 22:28

Re: Process Priorität setzen - als Variable...
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich bekomm einfach die ADDOBJECT nicht in die combobox...

Nur das was ich als String drinstehen hab wird angezeigt.

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.AddObject('Idle Priorität',TObject(IDLE_PRIORITY_CLASS));
ComboBox1.Items.AddObject('Normale Priorität',TObject(NORMAL_PRIORITY_CLASS));
ComboBox1.Items.AddObject('High Priorität',TObject(HIGH_PRIORITY_CLASS));
end;
Irgendwas hab ich da noch vergessen.

Wie gesagt: AddObject ist mir noch fremd.

Es ist nun immer nur NORMAL.

Hab mal die Strings aus der Source entfernt...

Christian Seehase 19. Mär 2004 22:33

Re: Process Priorität setzen - als Variable...
 
Moin DRPEnc,

mit AddObject wird intern zu dem jeweiligen String der der ComboBox hinzugefügt wird noch ein Objekt hinzugefügt.
Das ist allerdings nichts weiter als die Adresse einer Objektinstanz, und somit ein simpler 32 Bit Wert, so dass man hier auch einfach beliebige 32 Bit Zahlen hinzufügen kann.
Dadurch musst Du keine zusätzliche Tabelle verwenden, deren Einträge mit denen der Einträge in der ComboBox korrespondieren, um die zu den Strings gehörigen Werte zuordnen zu können.

Hilft Dir das erstmal weiter?


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:42 Uhr.
Seite 2 von 4     12 34      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz