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 1 von 3  1 23      
Benutzerbild von sk.Silvia
sk.Silvia

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

Realtime Input? Thread?

  Alt 13. Mai 2006, 20:01
hi there, lets say i have this simple code

i:=0;
repeat
i:=i+1;
until i=10;

and i will enter numbers from a edit component - i write a number to edit and press the button, then the cycle continues

like :

Delphi-Quellcode:
i:=0;
repeat
  Memo1.Lines.Append('Enter field values '+IntToStr(i));
  P[i]:=%MyInput%; //Edit1.text;
  i:=i+1;
until i=10;
and it will looks like

> program starts
> it displays -> Enter field values 1
> then i write the values to an edit component and press the ok button //smt like the program stops and w8 for input from anothe component
> then again it displays -> Enter field values 2
> then again enter the numbers to edit component and click ok

it looks simple, but i have no clue how to do this, how to stop a procedure at a certain point, work with another procedure and the result inputs and continue from the neeede point

maybe to give the procedure to a threat, but thats also :/ for me

thanks
  Mit Zitat antworten Zitat
C.Schoch

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

Re: Realtime Input? Thread?

  Alt 13. Mai 2006, 20:34
why you dont try

Delphi-Quellcode:
i:=0;
repeat
  inputbox('Enter Number', ''Enter field values '+IntToStr(i)', '') // here i changed
  P[i]:=%MyInput%; //Edit1.text;
  i:=i+1;
until i=10;
?
The code waits while the Inputbox is diplayed.

Or don`t I understand the question?
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

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

Re: Realtime Input? Thread?

  Alt 13. Mai 2006, 22:44
ok thanks, thats it, but can i make my custom input box?
  Mit Zitat antworten Zitat
C.Schoch

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

Re: Realtime Input? Thread?

  Alt 13. Mai 2006, 23:09
Yes you can. go to File - New - (in german version "Weitere") the rest is shown in the screenshot of course you can use the red marked.

you can add buttons, fields ... .
But you have to write every funktion by own hand.
like this:
Delphi-Quellcode:
procedure TMainForm.pmAddClick(Sender: TObject);
// Job hinzufügen
begin
  // here you can set standart values if you need
  TEditChange.ShowModal;
  if not (TEditChange.ModalResult = mrCancel) then // maybe use mrOK and leave "not"
    begin
      // do sometheng whith the Input Data
      lvSourceDestination.Items.Add;
      lvSourceDestination.Items[lvSourceDestination.Items.Count-1].SubItems.clear;
      lvSourceDestination.Items[lvSourceDestination.Items.Count-1].SubItems.add(TEditChange.eSourcePath.Text);
      lvSourceDestination.Items[lvSourceDestination.Items.Count-1].SubItems.add(TEditChange.eDestinationPath.Text);
      lvSourceDestination.Items[lvSourceDestination.Items.Count-1].SubItems.add(TEditChange.eApplicationPath.Text);
      // reset the edit fields, if you don`t do the old is shown at next show
      TEditChange.eSourcePath.Text := '';
      TEditChange.eDestinationPath.Text := '';
      TEditChange.eApplicationPath.Text := '';
    end
end;
edit: In D7 it`s in File - New - (in german version "Weitere") in the register "Dialogs"
Miniaturansicht angehängter Grafiken
dialog_130.jpg  
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

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

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 10:43
but thats not exactly what i wanted... i will make smt like this // StopProcedure(Haf); and ContinueProcedure(Haf); this procedures dont exist, but i will make smt like this

Delphi-Quellcode:
procedure Haf;
var i:integer;
 begin
 i:=0;
 repeat
  StopProcedure(Haf); //this stops the procedure, but local variables, nothing will be lost, smt like it freezes the procedure for a while
  input[i]:=Edit1.text;
  i:=i+1;
 until i=3;
 end;

//we can work with the program and when we press Button, Haf will contiue
procedure ButtonClick;
 begin
 ContinueProcedure(Haf);
 end;
i hope its a bit clearer now
  Mit Zitat antworten Zitat
C.Schoch

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

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:16
You can do this with WaitForSingleObject and an Event

Your function
Delphi-Quellcode:
procedure Haf;
var i:integer;
begin
i:=0;
repeat
//////Wait///////////////////////////////////
repeat
  WaitResult := DWORD WaitForSingleObject(HANDLE hHandle, { handle of object to wait for} DWORD dwMilliseconds    { time-out interval in milliseconds}); // for Handele use "event" and you must set an timeout that the funktion returns and Messages are viewed and worked on
  if WaitResult <> WAIT_OBJECT_0 then
  begin
    Application.ProcessMessages;
  end;
until WaitResult = WAIT_OBJECT_0;
/////////////////////////////////////////////
// here you can use reset event if you want to wait contiously
  input[i]:=Edit1.text;
  i:=i+1;
until i=3;
end;
Create the event:
Delphi-Quellcode:
procedure TForm1.FormShow(Sender: TObject);
begin
event := HANDLE CreateEvent(

    LPSECURITY_ATTRIBUTES lpEventAttributes,   // pointer to security attributes
    BOOL bManualReset,   // flag for manual-reset event
    BOOL bInitialState,   // flag for initial state
    LPCTSTR lpName    // pointer to event-object name
   );
end;
Set the event:
Delphi-Quellcode:
procedure ButtonClick;
begin
SetEvent(event)
end;
Close the event:
Delphi-Quellcode:
procedure TForm1.FormClose(Sender: TObject);
begin
 CloseHandle(event)
end;
Now a lot of Pseudocode (not tested)
for additional informatin wiew the SDK.
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Olli
(Gast)

n/a Beiträge
 
#7

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:23
If it runs in a separate thread MSDN-Library durchsuchenSuspendThread and MSDN-Library durchsuchenResumeThread might be exactly what you are searching for.

However, if you suspend the thread from the outside, the context is undetermined. So if you want the thread to be suspended at a certain position, it may suspend itself using SuspendThread and be woken up from another thread using ResumeThread.

Note: if you have the usual Delphi-like architecture of an application, there is only one main thread with a message queue. So to achieve the above you need to have a secondary thread at least. And be sure to sync them because the VCL does not like threads too much
  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
 
#8

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 13:31
So you have like 10 input params you want to fetch from the user?

Why not just make a second form:

Delphi-Quellcode:
for i := 0 to 9 do
  if form2.ShowModal = mrOK then
    begin
      values[i] := form2.some_public_field_assigned_before_closing;
    end
  else
    begin
      ShowMessage('Naaah... don''t press cancel!'); // ;-)
      Break;
    end;
EDIT: if you don't know how to make a form act modal, there should be enough material in the forum. or just ask
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
 
#9

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 14:06
@Olli the mainform is a thread too, and bacause of this you can use the wait function too.
Here i work with events and thay you can set from everywhere in the programm.

I made a little test program:
Angehängte Dateien
Dateityp: zip test_146.zip (6,0 KB, 14x aufgerufen)
Tschau Christian
Das System hofft auf Besserung
[Siemens]
  Mit Zitat antworten Zitat
Benutzerbild von sk.Silvia
sk.Silvia

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

Re: Realtime Input? Thread?

  Alt 14. Mai 2006, 14:11
thanks for your help, threat are looking good, but what am i making wrong, why does it do - nothing - ?

Delphi-Quellcode:
var fiber:TThread;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
  begin
  fiber:=TTHread.Create(false);
  //fiber.Synchronize(???);
  i:=0;
  repeat
    Memo1.Lines.Append(IntToStr(i));
    fiber.Suspend;
    i:=i+1;
  until i=3;
  fiber.Terminate;
  end;

procedure TForm1.Button2Click(Sender: TObject);
  begin
  fiber.Resume;
  end;
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


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 10: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