![]() |
Timerproblem
Hi
ich habe vor längerer Zeit mal eine Sidebar programmiert. Die funktioniert auch super als ich aber jetzt die Unit adCPUUsage eingebaut habe und diese wie im readme.txt in die onTimer-Prozedur eingebunden habe aktualisiert diese den Wert nicht mehr,während die anderen Befehle bearbeitet werden. Zur Überprüfung habe ich die Unit in einem anderen Programm separat getestet wo sie auch einwandfrei funktioniert
Delphi-Quellcode:
procedure TForm5.Timer3Timer(Sender: TObject);
var w:integer; begin for w:=0 to GetCPUCount-1 do // Show data for each processor begin label7.caption:=Format('%5.2f %%',[GetCPUUsage(w)*100]); progressbar3.Position:=round(strtofloat(copy(label7.caption,0,pos('%',label7.caption)-1))); end; end; |
AW: Timerproblem
Du wirst so auch nicht sehen, da die Werte ja gleich wieder überschrieben werden
|
AW: Timerproblem
Genau, Du wirst schon je CPU ein Anzeige-Control brauchen.
BTW: Nette Namensgebung, hoffentlich steigst wenigstens Du da später noch durch. |
AW: Timerproblem
Da fehlt was WICHTIGES!
Delphi-Quellcode:
Nicht getestet - aber so könnte es funktionieren...
procedure TTestForm.TimerTimer(Sender: TObject);
var i: Integer; begin CollectCPUData; // MUSS IMMER AUFGERUFEN WERDEN !!! for i:=0 to GetCPUCount-1 do begin if GetCPUCount=2 then BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); END; if GetCPUCount=3 then BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); END; if GetCPUCount=4 then BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); Label3.Caption := Format('CPU #%d - %5.2f%%',[2,GetCPUUsage(2)*100]); END; if GetCPUCount=5 then BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); Label3.Caption := Format('CPU #%d - %5.2f%%',[2,GetCPUUsage(2)*100]); Label4.Caption := Format('CPU #%d - %5.2f%%',[3,GetCPUUsage(3)*100]); END; end; end; ÄNDERE BITTE DIE ÜBERSCHRIFT - die ist total falsch und beschreibt nicht das Problem! Vorschlag: adCPUUsage - wie im Timer anwenden? |
AW: Timerproblem
danke für die Antworten
das Problem lag an der Verwendung des Labels muss natürlich ne mehrzeilige Komponente sein ich dacht ich bräuchte das nicht da ich ja nur nen Singlecore hab bis mir aufgefallen ist, dass der virtuelle da auch aufgeführt wird |
AW: Timerproblem
Wie mkinzler schon richtig schrieb:
Zitat:
Da beginnt die Routine bereits, nicht zu funktionieren. Ich schlage vor, pro CPU ein TLabel dynamisch zu erzeugen (wenn es TLabels sein müssen - meine Wahl wäre ein TreeView und pro CPU ein Knoten, da kann man schön alle Zusatzinfos unter die CPUs hängen). |
AW: Timerproblem
@Hator:
Nette Schleife ... i wird nie benutzt, also ist diese doch her "nutzlos" und sorgt nur dafür, daß der Code unnötiger Weise mehrfach ausgeführt wird.
Delphi-Quellcode:
Oder doch die For-Schleife und dann das i für die Auswahl des Labels und den Index in GetCPUUsage nutzen.
procedure TTestForm.TimerTimer(Sender: TObject);
var i: Integer; begin CollectCPUData; // MUSS IMMER AUFGERUFEN WERDEN !!! Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); if GetCPUCount >= 2 then Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); if GetCPUCount >= 3 then Label3.Caption := Format('CPU #%d - %5.2f%%',[2,GetCPUUsage(2)*100]); if GetCPUCount >= 4 then Label4.Caption := Format('CPU #%d - %5.2f%%',[3,GetCPUUsage(3)*100]); // wobei man GetCPUCount vielleicht nur einmal aufrufen sollte/könnte end; |
AW: Timerproblem
Stimmt - ich hatte die Werte erst in ein Memo geschrieben und dann in Labels geändert...
Hat aber lange gedauert, bis es jemand auffiel! Dann besser so:
Delphi-Quellcode:
procedure TTestForm.TimerTimer(Sender: TObject);
begin CollectCPUData; // MUSS IMMER AUFGERUFEN WERDEN !!! case GetCPUCount of 2: Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); 3: BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); END; 4: BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); Label3.Caption := Format('CPU #%d - %5.2f%%',[2,GetCPUUsage(2)*100]); END; 5: BEGIN Label1.Caption := Format('CPU #%d - %5.2f%%',[0,GetCPUUsage(0)*100]); Label2.Caption := Format('CPU #%d - %5.2f%%',[1,GetCPUUsage(1)*100]); Label3.Caption := Format('CPU #%d - %5.2f%%',[2,GetCPUUsage(2)*100]); Label4.Caption := Format('CPU #%d - %5.2f%%',[3,GetCPUUsage(3)*100]); END; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:21 Uhr. |
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