Autor Beitrag
Jojojoxx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 15:42 
Hallo!

Ich habe eine Prozedur, die ich als Thread starte (ich muss dazu sagen, dass ich nicht viel Ahnung von Threads habe und nur einige Tutorials gelesen habe).
Unter anderem wird in dieser Prozedur ein messagedlg aufgerufen. Wenn ich diese Prozedur aber als Thread starte, kommt es vor, dass Teile auf dieser messagedlg fehlen, z.b. Buttons, Labels, usw..
Bei Formen ist es dasselbe.
Nun habe ich den Aufruf dieser messagedlg ist einen kritischen Abschnitt gepackt, aber auch das bringt nichts.
Hat jemand eine Idee dazu?
Danke euch!
mfg

Jojo
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 27.03.08 16:03 
Die VCL ist NICHT Thread-Safe. Jegliche Zugriffe auf die visuelle Oberfläche bitte mit Synchronize ausführen ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 18:02 
Ahh ok :-)
Das Prinzip von Synchronzie hab ich jetzt verstanden.
Nur wenn ich jetzt z.b. den Text aus einem editfeld auslesen möchte, wie kann ich das dann mit Synchronize ausführen?
Danke!
mfg

Jojo
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1341
Erhaltene Danke: 120

Win 10
RIO, CE, Lazarus
BeitragVerfasst: Do 27.03.08 18:15 
Du schreibst dur eine Parameterlose Procedure die den Wert aus den Editfeld ausließt und in eine Variable schreibt die du im Thread deklarierst.
An der Stelle wo du den Wert haben willst rufst du diese Procedure einfach via Synchronize auf:
ausblenden Delphi-Quelltext
1:
Snychronize(ReadEditValue);					

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 18:21 
Also geht das nur mit globalen Variablen?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 27.03.08 18:26 
Moin!

user profile iconJojojoxx hat folgendes geschrieben:
Also geht das nur mit globalen Variablen?
user profile iconSinspin hat folgendes geschrieben:
in eine Variable schreibt die du im Thread deklarierst.
Was hat das mit globalen Variablen zu tun? :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 18:28 
Naja, wenn ich in der Prozedur vom Thread eine Variable deklariere, dann kennt doch die Prozedur, die ich mit Synchronize aufrufe zum Auslesen aus der VCL diese nicht...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 27.03.08 18:29 
Moin!

Hast du von TThread abgeleitet? Wenn ja, dann gehört die Variablendeklaration da rein. :idea: Wenn nicht, tja, dann... :?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 18:46 
Mein Thread-Objekt sieht so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
unit Unit6;

interface

uses
  Classes, unit1, Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms,
  Dialogs, Menus, unit4, konsole, unit3;

type
  Unrar = class(TThread)
  private
    { Private-Deklarationen }
  protected
    procedure Execute; override;
  end;

implementation

procedure Unrar.Execute;
begin
{Thread-Code}
end;

procedure getListBoxCount();
begin
//Diese Prozedur soll Form1.Listbox1.items.Count ermitteln
end;


Wenn ich in Unrar.Execute eine Variable deklariere, dann kann getListboxCount() nicht darauf zugreifen.
Wenn ich die Variable oberhalb von implemenation, also global, deklariere, dann funktioniert es...

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 27.03.08 18:49 
Moin!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type
  Unrar = class(TThread)
  private
    FCount: Integer;
  protected
    procedure Execute; override;
  end;
:idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Do 27.03.08 18:51 
Ahhhhh... :D
Vielen Dank!
mfg

Jojo
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 27.03.08 21:27 
Wobei ich eh nicht verstehe, warum man (außer für ne Progressbar) VCL-Zugriffe bräuchte ... Alles andere bekommt man recht sauber auch über Semaphoren\Mutexe zu anderen Threads geschaufelt, um das dort darstellen zu können ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.