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: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Thu, 20 Dec 2007 13:44:35 |
"soonic" <xxsoonic@op.pl> wrote in message
news:476ad924@newsgroups.borland.com...
> Well, it's not the context of the main thread
Then you need to change how you are calling Application.Terminate(). The
easiest way is to simply pass Application.Terminate() to
TThread.Synchronize(), ie:
Synchronize(Application.Terminate);
Another option is to post a custom message to the main thread and let the
message handler call Terminate(), ie:
const
APPWM_TERMINATE = WM_APP + 100;
begin
//...
PostThreadMessage(MainThreadID, APPWM_TERMINATE, 0, 0);
//...
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;
procedure TMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = APPWM_TERMINATE then
begin
Handled := True;
Application.Terminate;
end;
end;
> but I need to run things which are located in FormShow
You can use the same custom message approach for that. Have CTIStartup()
post a custom message to TMainForm, and then have the message handler
execute what you need. You can also have the OnShow event post the same
message as well.
Alternatively, simply move your logic into the form's constructor or
OnCreate event instead.
> AssignFile(F, Dir+FileName);
> Reset(F,1);
You are not checking to make sure the file is ok to read from.
> BlockRead(F, pCB1st, SizeOf(pCB1st));
> when this line is executed my program fails, but it doesn't fail
> when starts normally.
You did not show what pCB1st is. My guess is that you are not setting it up
properly beforehand.
Gambit