SourceForge has been redesigned. Learn more.
Close

#1 Two apps access same comport

open
nobody
None
5
2004-01-04
2004-01-04
No

Received from "Davor Slutej" <davor@cutoff.nospam-se>:

I have made a small modification. Without this, when
two apps tried to access the same port, the application
would crash hard because it wasn't able to catch the
exception.

Lines added or changed are marked with >>>>>

In the Cport.pas file, around line 1342:

// open port
procedure TCustomComPort.Open;
begin
// if already connected, do nothing
if not FConnected and not (csDesigning in
ComponentState) then
begin
CallBeforeOpen;
// open port
>>>>> try
CreateHandle;
FConnected := True;
try
// initialize port
SetupComPort;
except
// error occured during initialization, destroy
handle
DestroyHandle;
FConnected := False;
raise;
>>>>> end;
>>>>> except
>>>>> raise;
>>>>> exit;
end;
// if at least one event is set, create special
thread to monitor
port
if (FEvents = []) then
FThreadCreated := False
else
begin
if (FSyncMethod = smWindowSync) then
{$IFDEF DELPHI_6_OR_HIGHER}
{$WARN SYMBOL_DEPRECATED OFF}
{$ENDIF}
FWindow := AllocateHWnd(WindowMethod);
{$IFDEF DELPHI_6_OR_HIGHER}
{$WARN SYMBOL_DEPRECATED ON}
{$ENDIF}
FEventThread := TComThread.Create(Self);
FThreadCreated := True;
end;
// port is succesfully opened, do any additional
initialization
CallAfterOpen;
end;
end;

Discussion

  • Karl Hans-Dieter

    Logged In: YES
    user_id=841730

    in my opinion this patch does nothing ...
    it just catches a possible exception thrown by CreateHandle
    and throws it again ???

     
  • Kevin Jesshope

    Kevin Jesshope - 2005-01-17

    Logged In: YES
    user_id=466223

    Agreed - this patch achieves nothing. BTW the exit after the
    raise will NEVER execute.