Autor Beitrag
reg107
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36



BeitragVerfasst: Sa 19.03.05 12:56 
Hallo,
ich möchte mit Threads arbeiten (eigentlich nur einer). Ich habe schon nach Tutorials gesucht, habe auch das von luckie gefunden, allerdings weiß ich jetzt immernoch nicht, wie man sows macht.
Ich denke ein einfaches(!) Beispiel Programm, z.B. per Button wird eine Endlosschleife in einem Thread gestartet und per Button wieder beendet, würde mir sehr viel weiter helfen.
Wo gibt es sowas?

Grüße,
reg107


Moderiert von user profile iconGausi: Topic aus VCL (Visual Component Library) verschoben am Di 22.03.2005 um 09:17
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 19.03.05 13:06 
Erster Eintrag von Suche bei Google TTHREAD TBUTTON (Direktlink: threads und events)
Ist zwar nicht genau das gesuchte Beispiel, aber auch ein relativ kurzes..
PattyPur
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 80

Win98, WinXP
Delphi 7
BeitragVerfasst: Sa 19.03.05 13:08 
In der Online-Hilfe von Delphi
Stichwort: "Multithread Anwendung Entwickeln"
Steht dort gut erklärt

_________________
Das Leben ist zum Spielen da,
alles andere ist Unsinn
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 19.03.05 13:25 
Einfaches Beispiel für einen Thread. Button1 startet den Thread und führt jede Sekunde die Win32API Funktion MessageBeep aus. Button2 beendet den Thread wieder.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
   MyThread: TThread;
  public
    { Public-Deklarationen }
  end;

  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyThread }

procedure TMyThread.Execute;
begin
  while not Terminated do
  begin
    MessageBeep(UINT(-1));
    Sleep(1000);
  end;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Assigned(MyThread) then
  begin
    MyThread := TMyThread.Create(True);
    with MyThread do
    begin
      FreeOnTerminate := True;
      Resume;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if Assigned(MyThread) then
    MyThread.Terminate;
end;

end.

_________________
Ciao, Sprint.
reg107 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36



BeitragVerfasst: Sa 19.03.05 13:38 
danke, danke! das bringt sehr viel weiter!!! :D :P
himitsu
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 40



BeitragVerfasst: Sa 19.03.05 14:34 
Und beim Luckie solle auch irgendwo ein Thread-Tutorial rumliegen (hab mal sowas dort gesehn) ...


www.luckie-online.de

_________________
warum einfach wenn's auch kompliziert geht
schreib wie du willst und halt dich an keine standards
reg107 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36



BeitragVerfasst: Sa 19.03.05 16:22 
user profile iconICH hat folgendes geschrieben:
Ich habe schon nach Tutorials gesucht, habe auch das von luckie gefunden, allerdings weiß ich jetzt immernoch nicht, wie man sows macht.

user profile iconhimitsu hat folgendes geschrieben:
Und beim Luckie solle auch irgendwo ein Thread-Tutorial rumliegen (hab mal sowas dort gesehn) ...
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 19.03.05 16:42 
user profile iconreg107 hat folgendes geschrieben:
Ich habe schon nach Tutorials gesucht, habe auch das von luckie gefunden, allerdings weiß ich jetzt immernoch nicht, wie man sows macht.
Ich denke ein einfaches(!) Beispiel Programm, z.B. per Button wird eine Endlosschleife in einem Thread gestartet und per Button wieder beendet, würde mir sehr viel weiter helfen.
Wo gibt es sowas?

Die Demos in dem Zip-Archiv hat du aber shcon entdeckt - oder? :roll:
reg107 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 36



BeitragVerfasst: Mo 21.03.05 19:12 
ja, die waren zu kompliziert :wink:
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 21.03.05 19:15 
user profile iconreg107 hat folgendes geschrieben:
ja, die waren zu kompliziert :wink:

Jetzt mach mich bitte nicht schwach.