Hallo,
nachdem ich es normal nicht geschafft habe, will ich nun versuchen, während meiner WS-Anfrage, ein InfoForm (in diesem MUSS sich was bewegen) anzuzeigen.
Habe mir gedacht, dass das nur noch mit Threads funktionieren kann...
Mein Thread sieht so aus:
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: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60:
| type TInformationThread = class(TThread) private m_infoForm : TFormInformation; i:integer; procedure UpdateInformation(); protected procedure Execute; override; procedure showInformationForm(); public constructor create(form:TFormInformation); end;
implementation
constructor TInformationThread.create(form: TFormInformation); begin inherited create(true); m_infoForm := form; end;
procedure TInformationThread.Execute; begin i:=0; showInformationForm();
end;
procedure TInformationThread.showInformationForm; begin
while true do begin
if self.Terminated then begin exit; end;
Synchronize(UpdateInformation);
inc(i); end;
end;
procedure TInformationThread.UpdateInformation; begin
m_infoForm.setInfoText('Update '+IntTostr(i)); m_infoForm.Update; Application.ProcessMessages; end; end. |
Dieser wird folgendermaßen aufgerufen:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| infoForm := TFormInformation.Create(nil); infoForm.Show; informationThread := TInformationThread.create(infoForm); informationThread.FreeOnTerminate := true; informationThread.Resume; informationThread.Terminate; if assigned(infoform) then begin infoForm.Close; infoForm.Free; end; |
Das form geht zwar auf, aber es ändert sich leider kein Text. Die Methode die im Form aufgerufen wird lautet:
Delphi-Quelltext
1: 2: 3: 4: 5: 6:
| procedure TFormInformation.setInfoText(text: string); begin PanelInformation.Caption := text; self.Update; Application.ProcessMessages; end; |
Könnt ihr mir helfen und Tipps geben oder ein funktionierende Bsp posten?
Hab schon im Forum gesucht und auch das Tutorial angesehen, aber ich finde meinen Fehler einfach nicht...
Danke,
winx
Moderiert von
Christian S.: Code- durch Delphi-Tags ersetzt.