Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: closing an application over the network
| Subject: | Re: closing an application over the network |
| Posted by: | "soonic" (xxsoon..@op.pl) |
| Date: | Thu, 20 Dec 2007 22:07:26 |
> Where is ReadFrom() being called from exactly? If it is not in the
> context
> of the main thread, then your approach will not work.
Well, it's not the context of the main thread but starts with
(netunit.pas)
type
TReadingThread = class(TThread)
private
Fd: TRecordSend;
Cc: TIdTCPConnection;
procedure UpdateGrid;
protected
procedure Execute; override;
public
constructor Create(Cc: TIdTCPConnection); reintroduce;
destructor Destroy; override;
end;
and I then it executes (I can put try..end here )
procedure TReadingThread.Execute;
begin
try
while not Terminated do
begin
Fd.ReadFrom(Cc);
if not Terminated then Synchronize(Data);
end;
except
MainForm.Terminate;
end;
end;
(mainform.pas)
procedure TMainForm.Terminate;
begin
Application.Terminate;
end;
> Application.Terminate() must be called in the context of the main thread
> only. It posts a WM_QUIT to the calling thread. If it is called from
> another thread, then the message will go to the wrong thread and the
> application will not terminate.
then, how can I Terminate my application (maybe in different way)?
2) Another thing I'm dealing with...
when the applicaton starts with system it goes to tray (I use some component
for that with onstartup event handler that occures when an application
activates a session), simply:
procedure TMainForm.CTIStartup(Sender: TObject; var ShowMainForm: Boolean);
begin
FormShow(nil);
ShowMainForm:= False;
end;
but I need to run things which are located in FormShow
procedure TMainForm.FormShow(Sender: TObject);
var Dir: String;
F: File;
begin
....
Dir := ExtractFilePath(Application.ExeName);
AssignFile(F, Dir+FileName);
Reset(F,1);
BlockRead(F, pCB1st, SizeOf(pCB1st)); // when this line is executed
my program fails, but it doesn't fail when starts normally.
end;
is there a quick way so I can change that to avoid failing?