Einzelnen Beitrag anzeigen

BigAl

Registriert seit: 6. Sep 2008
Ort: Kehl
504 Beiträge
 
Delphi 12 Athens
 
#2

Re: Programm bei laufender IDE schneller - Warum?

  Alt 6. Sep 2008, 22:55
Nochmal ich... Habe zum Test mal schnell ein kleines Programm "hingesaut". Solange die IDE auf dem Rechner läuft macht die Thread knapp 100 Zyklen / Sekunde. Ist die IDE nicht gestartet, so kommt die Thread gerade mal auf ca. 63 Zyklen / Sekunde.

Der Quellcode:

Code:
unit Main;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    lblCount: TLabel;
    Label3: TLabel;
    lblCountsPerSec: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
    OldCount: Integer;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TTestThread = class(TThread)
  private
    procedure Execute; override;
  public
    Count: Integer;
  end;

var
  TT: TTestThread;

procedure TTestThread.Execute;
begin
  while not Terminated do
  begin
    Sleep(10);
    Inc(Count);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TT := TTestThread.Create(False);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  TT.Terminate;
  TT.WaitFor;
  TT.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  lblCount.Caption := IntToStr(TT.Count);
  lblCountsPerSec.Caption := IntToStr(TT.Count - OldCount);
  OldCount := TT.Count;
end;

end.
Und das Formular:
Code:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 148
  ClientWidth = 376
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 24
    Top = 24
    Width = 43
    Height = 13
    Caption = 'Counter:'
  end
  object lblCount: TLabel
    Left = 112
    Top = 24
    Width = 39
    Height = 13
    Caption = 'lblCount'
  end
  object Label3: TLabel
    Left = 24
    Top = 48
    Width = 77
    Height = 13
    Caption = 'Counts/Second:'
  end
  object lblCountsPerSec: TLabel
    Left = 112
    Top = 48
    Width = 77
    Height = 13
    Caption = 'lblCountsPerSec'
  end
  object Timer1: TTimer
    OnTimer = Timer1Timer
    Left = 276
    Top = 92
  end
end
Ich bin ratlos...

Hat wer 'ne Idee???

Alex
Man sollte nie so viel zu tun haben, dass man zum Nachdenken keine Zeit mehr hat. (G.C. Lichtenberg)
  Mit Zitat antworten Zitat