![]() |
Re: Thread Anfängerfrage
Warum ohne Polling? Ich habe eigentlich gemeit, dass er ATimeout auf einen Wert ungleich IdTimeoutInfinite setzt.
(Das war ich nach dem Zitat geschriebenen habe war nicht an dich sondern an Spurius gerichtet, weil er dies in seinem Code noch nicht berücksichtigt hat.) |
Re: Thread Anfängerfrage
Hallo,
hier ist der Code meines Threads:
Delphi-Quellcode:
Also, oben meine Kommentare im Code, und dann noch ne Frage, es ist schon richtig dass ich den thread im mainthread einfach create, ich muss sonst nichts dort verändern, oder?
unit threadtest;
interface uses Classes,idtcpclient,dialogs,StdCtrls,sysutils; type tmythread = class(TThread) private fclient:tidtcpclient; fmemo:tmemo; s: string; procedure updatememo; protected procedure Execute; override; public constructor create(const aclient: tidtcpclient; const amemo: tmemo); end; implementation uses modul; constructor tmythread.create(const aclient: tidtcpclient; const amemo: tmemo); begin inherited create(true); fclient := aclient; fmemo := amemo; resume; end; procedure tmythread.Execute; begin while not terminated do fclient.ReadLn(s,500); //<- wenn ich das bei unten bei updatememo einsetzt, friert synchronize(updatememo); // das prog ein, wenn es hier lasse, friet nix ein, aber sleep(100); // der thread bewirkt auch nichts end; procedure tmythread.updatememo; begin fmemo.Lines.Append(s); end; end. Gruß Spurius |
Re: Thread Anfängerfrage
Kein Wunder, dass dein Thread nichts bewirkt. Du hast ein begin...end Block vergessen, die Parameter von ReadLn sind falsch und du solltest den TIdTCPClient im Thread erstellen.
So langsam wiederhole ich mich... was hat dir an dem Code, den du davor gepostet hast nicht gepasst? Du musstest nur noch ein paar Sachen ändern. |
Re: Thread Anfängerfrage
Hallo,
es geht!!!!!!!!!!!!!!!!!!!!!!!! :-D :-D :-D :-D Hier ist der Code:
Delphi-Quellcode:
Vielen Dank für die Hilfe, besonders an choose und kamil!
unit threadtest;
interface uses Classes,idtcpclient,dialogs,StdCtrls,sysutils; type tmythread = class(TThread) private fclient:tidtcpclient; fmemo:tmemo; s:string; procedure updatememo; protected procedure Execute; override; public constructor create(const aclient: tidtcpclient; const amemo: tmemo); end; implementation uses modul; constructor tmythread.create(const aclient: tidtcpclient; const amemo: tmemo); begin inherited create(true); fclient := aclient; fmemo := amemo; resume; end; procedure tmythread.Execute; begin while not terminated do begin s := fclient.readln; synchronize(updatememo); sleep(100); end; end; procedure tmythread.updatememo; begin fmemo.Lines.Append(s); end; end. Gruß Spurius |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:56 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz