AGB  ·  Datenschutz  ·  Impressum  







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

Basic TThread doesn't work

Ein Thema von FaNIX · begonnen am 1. Feb 2008 · letzter Beitrag vom 1. Feb 2008
 
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#7

Re: Basic TThread doesn't work

  Alt 1. Feb 2008, 09:12
This is a bit tricky. Here's a simple example:
Delphi-Quellcode:
Type
  TMythread = Class (TThread)
  private
     fLabelMsg : String; // a private field to display in the main form from within a thread
     procedure DoShowMessage;
  Protected
     Procedure Execute; Override;
  End;
Procedure TMyThread.DoShowMessage;
Begin
  MainForm.MyLabel.Caption := fLabelMsg;
End;

Procedure TMyThread.Execute;
Begin
  ....
  fLabelMsg :='Show this!'; // Write what you want to display in your private fields
  Synchronize (DoShowMessage); // Call the method which actually talks to the VCL via Synchronize
  ...
// The Thread terminates automatically, when the Execute-Method is exited.
End;
Bear in mind that ANY access to VCL-Controls (not only on the main form) must be wrapped in a Synchronize call, otherwise your app will hang.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
 


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 04:23 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