AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Realtime Input? Thread?

Ein Thema von sk.Silvia · begonnen am 13. Mai 2006 · letzter Beitrag vom 14. Mai 2006
Antwort Antwort
Seite 2 von 3     12 3      
C.Schoch

Registriert seit: 2. Jan 2006
Ort: Wüstenrot
235 Beiträge
 
Turbo Delphi für Win32
 
#11

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:17
You have to add a Thread-Objekt to your programm and fill it with code

edit:
or view my test programm
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Olli
(Gast)

n/a Beiträge
 
#12

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:26
Zitat von C.Schoch:
@Olli the mainform is a thread too, and bacause of this you can use the wait function too.
Also IsWindow() gibt aber TRUE zurück. Ist wohl doch ein Fenster und kein Thread? Ist mir schon klar, daß das Hauptform im Hauptthread "lebt" und die Nachrichten über diesen Thread bekommt, aber was willst du mir damit sagen?

Zitat von C.Schoch:
Here i work with events and thay you can set from everywhere in the programm.
Jupp.

@sk.Silvia: The TThread class must not be used like this. It has to be derived and the derived class has to be instantiated (and obviously implemented).
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#13

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:30
but how?

Delphi-Quellcode:
type TFiber=class(TTHread)
  procedure execute; override;
  end;

  procedure TFiber.execute;
  var i:integer;
      begin
      repeat
        ShowMessage(IntToStr(i));
        Suspend;
        i:=i+1;
      until i=3;
      end;

var Fiber:TFiber;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
  begin
  Fiber:=TFiber.Create(false);
  Fiber.execute;
  end;

procedure TForm1.Button2Click(Sender: TObject);
  begin
  Fiber.Resume;
  end;
but thats not correct
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#14

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:32
I still don't know why you want to do this with a thread, if you mind looking at my post above.

But if, this is how to do it:

- place the query (or whatever fetches the input form the user) in a thread
- after the query was answered and confirmed by the user, the thread sets a variable "I'm done", places the user input somewhere the main thread has access to and goes asleep/terminates

- in your main thread, you use MSDN-Library durchsuchenwaitforsingleobject to wait until the thread does set this variable, fetch the input and continue your loop.

But unless you have to keep your app doing something else while waiting for the input (which wouldn't work the way I just described it), i don't know why you would want to use a thread here...

EDIT: you don't initialize your "i" in the thread, so it'll probably take a long time until it gets to "3". but I can't see any othermistakes in it.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#15

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:39
cause i dont want that other forms are opened, i want just to stop the process, work with some other procedures and then by cliking resume work with the stoped procedure again


but this codes dont stopes on Suspend, but counts directly up to 3

Delphi-Quellcode:
type TFiber=class(TTHread)
  Memo:TMemo;
    procedure execute; override;
    procedure doit;
    constructor Create(iMemo:TMemo);
  end;

  constructor TFiber.Create(iMemo:TMemo);
    begin
    inherited Create(false);
    Memo:=iMemo;
    end;

  procedure TFiber.execute;
  var i:integer;
      begin
      Synchronize(Doit);
      doit;
      end;

  procedure TFiber.doit;
  var i:integer;
      begin
      i:=0;
      repeat
        Memo.Lines.Append(IntToStr(i));
        Suspend;
        i:=i+1;
      until i=3;
      end;

var Fiber:TFiber;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
  begin
  Fiber:=TFiber.Create(Memo1);
  Fiber.execute;
  end;

procedure TForm1.Button2Click(Sender: TObject);
  begin
  Fiber.Resume;
  end;
  Mit Zitat antworten Zitat
C.Schoch

Registriert seit: 2. Jan 2006
Ort: Wüstenrot
235 Beiträge
 
Turbo Delphi für Win32
 
#16

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:43
IMHO you have to use suspend in the main thread
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#17

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:51
ah... think i got you.

You have to place the thing you want to be able to suspend in the second thread.

well, your first example does work fine with me:

Delphi-Quellcode:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    {...}
  end;

  TFiber=class(TTHread)
    procedure execute; override;
  end;


var
  Form2: TForm2;
  Fiber: TFiber;

implementation

procedure TFiber.execute;
var i:integer;
begin
  i := 0;
  repeat
    ShowMessage(IntToStr(i));
    Suspend;
    i:=i+1;
  until i=3;
end;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Fiber.Resume;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  Fiber := TFiber.Create(false);
end;

end.
@C.Schoch: Yes, if you want to stop the thread like when the user says so or similarly.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#18

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 14:11
but by me the Suspend; dont stop the threat, it do nothing(likle i could exclude Suspend from the code and it would be the same)

but i need to suspend the threat in the repeat, so i cannot suspend it in Form1

Delphi-Quellcode:
  procedure TFiber.execute;
  var i:integer;
      begin
      i:=0;
      repeat
        Memo.Lines.Append(IntToStr(i));
        Suspend; //<------------HERE
        i:=i+1;
      until i=3;
      end;
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#19

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 14:24
it DOES with me...

I attached some primitive prime test, which stops itself after every found prime.
Angehängte Dateien
Dateityp: rar threadtest_109.rar (1,2 KB, 7x aufgerufen)
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
C.Schoch

Registriert seit: 2. Jan 2006
Ort: Wüstenrot
235 Beiträge
 
Turbo Delphi für Win32
 
#20

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 14:26
maybe try :
Delphi-Quellcode:
   procedure TFiber.execute;
  var i:integer;
      begin
      i:=0;
      repeat
        Memo.Lines.Append(IntToStr(i));
        wait(1) // <--- Here i changed
        Suspend; //<------------HERE
        i:=i+1;
      until i=3;
      end;
i have no Delphi here to test this now
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:59 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz