Delphi-PRAXiS
Seite 5 von 5   « Erste     345   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Thread Anfängerfrage (https://www.delphipraxis.net/12179-thread-anfaengerfrage.html)

Kamil 27. Nov 2003 15:26

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.)

Spurius 27. Nov 2003 15:46

Re: Thread Anfängerfrage
 
Hallo,
hier ist der Code meines Threads:
Delphi-Quellcode:
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.
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?
Gruß
Spurius

Kamil 27. Nov 2003 15:55

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.

Spurius 27. Nov 2003 16:41

Re: Thread Anfängerfrage
 
Hallo,
es geht!!!!!!!!!!!!!!!!!!!!!!!! :-D :-D :-D :-D
Hier ist der Code:
Delphi-Quellcode:
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.
Vielen Dank für die Hilfe, besonders an choose und kamil!
Gruß
Spurius


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:56 Uhr.
Seite 5 von 5   « Erste     345   

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