Einzelnen Beitrag anzeigen

youuu

Registriert seit: 2. Sep 2008
Ort: Kleve
822 Beiträge
 
Delphi 2010 Professional
 
#1

AW: BeginThread - Methoden aufruf

  Alt 30. Aug 2010, 13:55
Ich hab emir mal hierangeschaut.

Als Test, habe ich ein Beispiel von der Homepage genommen

Delphi-Quellcode:
procedure TForm1.MainProc;
 
  procedure DoSomething;
 
    procedure UpdateProgressBar(Percentage: Integer);
    begin
      ProgressBar.Position := Percentage;
      Sleep(20); // This delay does not affect the time for the 0..100 loop
                 // because UpdateProgressBar is non-blocking.
    end;
 
    procedure Finished;
    begin
      ShowMessage('Finished');
    end;
 
  var
    I: Integer;
  begin
    for I := 0 to 100 do
    begin
      // Do some time consuming stuff
      Sleep(30);
      LocalAsyncVclCall(@UpdateProgressBar, I); // non-blocking
    end;
    LocalVclCall(@Finished); // blocking
  end;
 
var
  a: IAsyncCall;
begin
  a := LocalAsyncCall(@DoSomething);
  a.ForceDifferentThread; // Do not execute in the main thread because this will
                          // change LocalAyncVclCall into a blocking LocalVclCall
  // do something
  //a.Sync; The Compiler will call this for us in the Interface._Release method
end;
Zwar durch läuft alles korrekt, aber dennoch ist das Formular geblockt, was es ja normaleweise nicht sein sollte.
Steven
  Mit Zitat antworten Zitat