Задать вопрос
  • Delphi7 - ошибка variable required при использовании CreateThread - как исправить?

    ZIK1337
    @ZIK1337 Автор вопроса
    Вот так?
    spoiler
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        TrackBar1: TTrackBar;
        TrackBar2: TTrackBar;
        Timer1: TTimer;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        Edit1: TEdit;
        Edit2: TEdit;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure TrackBar1Change(Sender: TObject);
        procedure TrackBar2Change(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure Button3Click(Sender: TObject);
    
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      Count1,Count2: integer;       {÷èñëî âû÷èñëåíèé â ñåêóíäó â ïîòîêå}
      ThreadId1,ThreadId2: dword;   {èäåíòèôèêàòîð ïîòîêà}
      HThread1, HThread2: THandle;  {óêàçàòåëü íà ïîòîê}
          
    implementation
    {$R *.dfm}
        procedure Execute1;
          var
            I, Total, Avg: integer;
          begin
            while True do
              begin
                Total:=0;
                for i:=1 to 10 do inc(Total, Random(Maxint));
                Avg:=Avg Div 10; inc(Count1);
              end;
          end;
    
        procedure Execute2;
          var
            I, Total, Avg: integer;
          begin
            while True do
              begin
                Total:=0;
                for i:=1 to 10 do inc(Total, Random(Maxint));
                Avg:=Avg Div 10; inc(Count2);
              end;
          end;
    
        procedure TForm1.Button1Click;
          begin
             HThread1:=CreateThread (nil,0,@Execute1,nil,0,ThreadId1);
          end;
    
        procedure TForm1.Button2Click;
          begin
             HThread2:=CreateThread (nil,0,@Execute2,nil,0,ThreadId2);
          end;
    
        procedure TForm1.TrackBar1Change(Sender: TObject);
          begin
             SetThreadPriority(HThread1,TrackBar1.Position);
          end;
    
        procedure TForm1.TrackBar2Change(Sender: TObject);
          begin
            SetThreadPriority(HThread2,TrackBar2.Position);
          end;
    
        procedure TForm1.Timer1Timer(Sender: TObject);
          begin
            form1.Edit1.Text:=intTostr(Count1);  Count1:=0;
            form1.Edit2.Text:=intToStr(Count2);  Count2:=0;
          end;
    
        procedure TForm1.Button3Click(Sender: TObject);
          begin
            close;
          end;
    
    end.

    Вроде бы работает.