Autor Beitrag
Nano-Ware
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: So 22.07.12 11:45 
Hey,

ich wollte meine Anwendung durch einen weiteren Thread erweitern. Ich habe mir nun das Tutorial hier durchgelesen: www.delphi-treff.de/...cal/threads/tthread/ Ich habe zuerst mit den Funktionen CreateThread und BeginThread gearbeitet. Schon da spiegelte sich ein Problem heraus. Der erste Code den ich geschrieben habe habe ich mit CreateThread gestartet (Code leider nicht vorhanden). Das hat sogar funktioniert, aber laut dem Tutorial Autor ist ja BeginThread besser, außerdem "Die Parameter entsprechen den bei CreateThread beschriebenen.". Also habe ich einfach mal "CreateThread" durch "BeginThread" ersetzt und bekomm direkt beim Starten des Threads ne Zugriffsverletzung.

Da ich davon keine Ahnung habe, habe ich mir TThread angeschaut. Das funktioniert auch alles, aber ist doch in meinen Augen relativ umständlich. Kann mir jemand eventuell anschaulich erklären, wie ich mit BeginThread arbeite oder mich überzeugen, dass TThread doch gut ist? (:
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: So 22.07.12 13:54 
Was findest du bei TThread denn umständlich?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
type
  TWorker = class(TThread)
  protected
    procedure Execute; override;
  end;

...

procedure TWorker.Execute;
begin
  while not Terminated do
    // Iregndwas machen
end;

// Hauptprogramm:
procedure TForm1.Button1Click(Sender: TObject);
begin
  worker := TWorker.Create(False);
end;

Für diesen Beitrag haben gedankt: Xion
Nano-Ware Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: So 22.07.12 13:59 
Du hast recht. Ich hab bis jetzt immer ein Object vom Typ TWorker erzeugt..
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: So 22.07.12 14:04 
user profile iconNano-Ware hat folgendes geschrieben Zum zitierten Posting springen:
Du hast recht. Ich hab bis jetzt immer ein Object vom Typ TWorker erzeugt..


Das muss man schon machen:

ausblenden Delphi-Quelltext
1:
worker := TWorker.Create(False);					


oder meinst du das anders?
Nano-Ware Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: So 22.07.12 14:40 
Okay, muss man dann auch "worker" wieder freigeben?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 22.07.12 14:47 
Moin!

Sag mal, ist deine Online-Hilfe kaputt oder hat dir einer die Suchmaschinen gesperrt? :suspect:

Es gibt da eine Eigenschaft: TThread.FreeOnTerminate, könnte was für dein Problem sein. :lupe: :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nano-Ware Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: So 22.07.12 14:57 
Nein natürlich nicht.. Ich komm mit der Onlinehilfe nur nicht klar und wüsste nicht nach was ich googlen soll. Trotzdem Danke!