Einzelnen Beitrag anzeigen

MrBrown90

Registriert seit: 7. Nov 2017
39 Beiträge
 
#65

AW: TCollection & TCollectionitem Tutorial

  Alt 14. Nov 2017, 20:21
Delphi-Quellcode:
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus, Vcl.ExtCtrls;
 
type
  TForm7 = class(TForm)
    Start: TButton;
    Button3: TButton;
    ListBox1: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    ListBox3: TListBox;
    Edit1: TEdit;
    Memo1: TMemo;
    Timer1: TTimer;
    procedure StartClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
 
  TMyThread = class(TThread)
  protected
    counter: integer;
    procedure Execute; override;
    procedure prog;
  public
    constructor create;
  end;
 
var
  Form7: TForm7;
  Thread1, Thread2, Thread3, Thread4, Thread5, Thread6: TMyThread;
  ID, ThreadID: integer;
 
implementation
 
{$R *.dfm}
 
procedure TMyThread.Execute;
var
  ProgID: integer;
begin
  ProgID := ID;
  while not Terminated do
  begin
    sleep(100);
    case ProgID of
      0:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 0 ' + DateTimeToStr(Now) + ' Uhr');
        end;
      1:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 1 ' + DateTimeToStr(Now) + ' Uhr');
        end;
      2:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 2 ' + DateTimeToStr(Now) + ' Uhr');
        end;
      3:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 3 ' + DateTimeToStr(Now) + ' Uhr');
        end;
      4:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 4 ' + DateTimeToStr(Now) + ' Uhr');
        end;
      5:
        begin
          Form7.Memo1.Lines.Add('Thread Nr. 5 ' + DateTimeToStr(Now) + ' Uhr');
        end;
    end;
  end;
end;
 
procedure TForm7.StartClick(Sender: TObject);
var
  i: integer;
begin
  ThreadID := ID;
  case ThreadID of
    0:
      begin
        Thread1 := TMyThread.create;
      end;
    1:
      begin
        Thread2 := TMyThread.create;;
      end;
    2:
      begin
        Thread3 := TMyThread.create;
      end;
    3:
      begin
        Thread4 := TMyThread.create;
      end;
    4:
      begin
        Thread5 := TMyThread.create;
      end;
    5:
      begin
        Thread6 := TMyThread.create;
      end;
  end;
end;
 
procedure TForm7.Timer1Timer(Sender: TObject);
begin
  Timer1.interval := 6000;
end;
 
procedure TMyThread.prog;
begin
 
end;
 
procedure TForm7.Button3Click(Sender: TObject);
begin
  case ID of
    0:
      begin
        Thread1.Terminate;
        Thread1.WaitFor;
        Thread1.Free;
      end;
    1:
      begin
        Thread2.Terminate;
        Thread2.WaitFor;
        Thread2.Free;
      end;
    2:
      begin
        Thread3.Terminate;
        Thread3.WaitFor;
        Thread3.Free;
      end;
    3:
      begin
        Thread4.Terminate;
        Thread4.WaitFor;
        Thread4.Free;
      end;
    4:
      begin
        Thread5.Terminate;
        Thread5.WaitFor;
        Thread5.Free;
      end;
    5:
      begin
        Thread6.Terminate;
        Thread6.WaitFor;
        Thread6.Free;
     end;
  end;
 
end;
 
constructor TMyThread.create;
begin
  inherited create(True);
  resume;
end;
 
procedure TForm7.FormCreate(Sender: TObject);
begin
  ListBox1.Items.AddObject('Thread Nr. 0', TObject(0));
  ListBox1.Items.AddObject('Thread Nr. 1', TObject(1));
  ListBox1.Items.AddObject('Thread Nr. 2', TObject(2));
  ListBox1.Items.AddObject('Thread Nr. 3', TObject(3));
  ListBox1.Items.AddObject('Thread Nr. 4', TObject(4));
  ListBox1.Items.AddObject('Thread Nr. 5', TObject(5));
 
end;
 
procedure TForm7.ListBox1Click(Sender: TObject);
begin
 
  ID := integer(ListBox1.Items.Objects[ListBox1.ItemIndex]);
end;
 
end.
Das wäre jetzt der ganze Code, dieser lässt sich auch compilieren.
Danke nochmal für die ganze Hilfe.

Mein Chef hätte jetzt noch gerne das ich da mit Messages arbeite.
ich hab mich schon kurz eingelesen, geht dann um Postmessage oder?
  Mit Zitat antworten Zitat