[twsocket] connect to IDE without app running ?

Stephen Williams SWilliams@fm.optus.net.au
Wed, 14 Jun 2000 08:45:35 +1000


Yes that is the correct way to prevent things happening during design time.
You will see many checks for csDesigning in ComponentState throughout the
VCL source code.

I would put the test for design mode in the property write method.

  procedure TCustomCiaServer.SetActive(value: boolean);
  begin
    if value <> FActive then
    begin
      FActive := value;
      if not (csDesigning in ComponentState) then
      begin
        PostMessage(Handle, WM_CONNECT, 0, 0);
      end;

This prevents sending the message in the first place if the application is
in design mode.  But then, that's probably personal preference.

Steve 'Sly' Williams
IT Development
Cable & Wireless Optus Outsourcing Services
swilliams@fm.optus.net.au
------------------------------------------------------------
(On the difference between men and women:) "On the one hand, we'll never
experience childbirth. On the other hand, we can open all our own jars."
------------------------------------------------------------

> I found a workaround but I'm not sure it is the right 
> place/way. To be sort
> it is compoennt that use TWSocketerver inside. I have 
> 'Active' property
> witch I had set to True in the object instpector and it do following:
> 
> procedure TCustomCiaServer.SetActive(value: boolean);
> begin
>   if value <> FActive then
>   begin
>     FActive := value;
>     PostMessage(Handle, WM_CONNECT, 0, 0);
> 
> This code is of course also executed at design time. The 
> component has it
> own message handler witch look like this:
> 
> procedure TCustomCiaServer.WndProc(var MsgRec: TMessage);
> begin
>   with MsgRec do
>     case Msg of
>       WM_CONNECT:    WMConnect;
>       ...
>       else Result := DefWindowProc(Handle, Msg, wParam, lParam);
> 
> While WMConnect does nothing else than closing the WSocketServeer if
> neccesary but it cals FWSocketServer.LISTEN if closed. This 
> means that the
> TWSocketServer is going to listen while the project is open 
> in IDE WITHOUT
> that the application runs because I had set the Active 
> property to True;
> 
> I have fixed this in the message handler as this:
> 
> procedure TCustomCiaServer.WndProc(var MsgRec: TMessage);
> begin
>   if csDesigning in ComponentState then Exit;
>   with MsgRec do
>     case Msg of
>       WM_CONNECT:    WMConnect;
>       ...
> 
> Do you think this is the right place ????
> 
> thanks in advance, Wilfried