Autor Beitrag
Gerhard_S
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98



BeitragVerfasst: Fr 03.02.12 22:04 
Hallo,
ich arbeite mit Delphi XE und TThread.
Hier der Code für den Thread:
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
unit Unit8;
interface
uses
  Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF};
type
  Upload1 = class(TThread)
  protected
    procedure Execute; override;
    procedure UpdateStatusBar;
  end;
implementation
uses Unit1;
function ExecuteScript(Script: string):Boolean;
var Paramstring : string;
begin
Paramstring := 'ini='+WinSCPIni+'WinSCP.ini /log='+ScriptFolder+'\logfile1.txt' +' /script='+Script;
if ShellExecute_AndWait('open',PChar(WinSCPEx), Paramstring, ScriptFolder, SW_SHOWNORMAL, true) >=0 then
result := true;
end;
procedure Upload1.UpdateStatusBar;
begin
  Form1.StatusBar1.SimpleText := 'Upload der Zeitungsbox erfolgreich.';
end;
procedure Upload1.Execute;
var MyScript : string;
begin
  NameThreadForDebugging('Upload1Name');
  { Thread-Code hier einfügen }
  MyScript := ScriptFolder+'\upload.txt';
 if ExecuteScript(MyScript) then
   Synchronize(UpdateStatusBar);
end;
end.

Hier der Aufruf in Unit 1:
ausblenden Delphi-Quelltext
1:
2:
Uploader1 := Upload1.Create(False);
Uploader1.FreeOnTerminate := true;

wobei Uploader1 als globale Variable vom Typ Upload1 definiert ist.
Meine Probleme:
1. Ich möchte den Thread mehrmals aufrufen und ihm dabei jeweils einen anderen String als Parameter für MyScript übergeben. Wie geht das ?
2. Form1.StatusBar1.SimpleText := 'Upload der Zeitungsbox erfolgreich.'; wird nie ausgeführt.

Ich habe schon viel gelesen, aber eine verständliche Hilfe noch nicht gefunden.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 04.02.12 12:33 
Moin!

Du musst deine Thread-Klasse um die benötigten Parameter erweitern und einen eigenen Konstruktor dazu tun. :idea: ;) Hier ist ein Beispiel. :les: :think:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.