alogrep 0 Posted November 26 HI. I hope someone can give me a hint here. Printque is a Form created in the Main Thread, just before calling this thread. Its Formcreate contains this line: Tstuckthread.Create(Tprintqueue(self),printernames); The problem is in the showform procedure at the line .A.show It gives no error, but the app becomes unresponsive. The main form is hidden, and I have to stop the app.I Tstuckthread= class(TThread) private FForm: TFORM; L:tSTRINGLIST; function STUCK(title:string;l:Tstringlist): boolean; procedure listjobs(allprinters: string); protected public constructor Create(ownerForm:TFORM;printernames:string; ARUNS: INTEGER=0); destructor Destroy; override; procedure Execute(); override; procedure showform; published end; constructor Tstuckthread.Create(ownerForm: TFORM;printernames: string;ARUNS: INTEGER=0); begin L:=tSTRINGLIST.CREATE; FForm:= ownerForm; Self.FreeOnTerminate := True; inherited Create; end; destructor Tstuckthread.Destroy; begin inherited; L.FREE; end; procedure Tstuckthread.Execute; begin done :=FALSE; while not Terminated AND NOT done do begin <get printjobs list and save it in L......> if L.count>0 then BEGIN /// fine HERE Tprintqueue(FForm).MEMO1.LINES.ASSIGN(L); // fine HERE Synchronize(SHOWForm); SLEEP(500); END; DONE:=TRUE; end; end; And here is the showform() procedure; procedure Tstuckthread.showform; VAR A: Tprintqueue; begin A:=Tprintqueue(FForm); TRY IF NOT A.VISIBLE THEN A.show; // PROBLEM HERE. EXCEPT a.free;// 4 testing. It never gets there. END; Share this post Link to post
alogrep 0 Posted November 26 Sorry. This line was wrong. Printque is a Form created in the Main Thread, just before calling this thread. shold have been Printque is a Form created in the Main Thread, Share this post Link to post
Remy Lebeau 1405 Posted November 26 (edited) The only problem I see with this code is that you are not Synchronize'ing access to the Form's Memo. You must do so. Move that Assign() call into your ShowForm() method. //Tprintqueue(FForm).MEMO1.LINES.ASSIGN(L); Synchronize(ShowForm); ... procedure Tstuckthread.ShowForm; begin Tprintqueue(FForm).Memo1.Lines.Assign(L); FForm.Show; end; Edited November 26 by Remy Lebeau Share this post Link to post
alogrep 0 Posted November 28 Thank you very much Remy. That was it. Problem solved. Share this post Link to post