Solved

catastrophic failure in Delphi COM Automation call (2nd call)

Posted on 2004-09-03
5
1,283 Views
Last Modified: 2010-08-05
I have written COM automation server and client both of them connect to SQL Server using ADO.
When I made a second call to COM server, an exeption was generated saying about Catastrophic error. What does it mean? Here is my Com Client code :-

procedure TfrmFirstConnect.mnuNewPayphoneClick(Sender: TObject);
var
    Zone, ZoneParam : string;
    PMSID, PayphoneID : Integer;
begin
    if not ADOSpMaster.Active then Exit;
    ConfSvr := nil;
    ConfSvr := CoPayphoneConfigSvr.Create;

    PMSID       := ADOSpMaster.FieldByName('PMSID').AsInteger;
    PayphoneID  := ADOSpMaster.FieldByName('PayphoneID').AsInteger;
    Zone        := MainDM.ServerName;
    ZoneParam   := MainDM.ADOConn.ConnectionString;
    if ConfSvr.Login('user','user',Zone, ZoneParam) then
    begin
        ConfSvr.NewLine(Zone, PMSID, PayphoneID);
    end
    else
        MessageDlg('Cannot login',mtError,[mbYes],0);
end;

Execption occured at this line
     -----> if ConfSvr.Login('user','user',Zone, ZoneParam) then
0
Comment
Question by:soapsiam
  • 2
  • 2
5 Comments
 
LVL 22

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 75 total points
ID: 11972482
Catastrophic error is an Error generated by Com object, not by delphi. You have to debug your ConfSvr at the Login method to step into and look what happen.

BTW this one:

ConfSvr := nil; (what about the previous com object? Never unassigned? Never logged out?)...

As you said 'When I made a second call to COM server, an exeption was generated....at this line -----> if ConfSvr.Login('user','user',Zone, ZoneParam)'... it seems that you're logging into a server that is already logged in....

F68 ;-)

0
 
LVL 1

Author Comment

by:soapsiam
ID: 11986852
I mak change the two lines below :--
    ConfSvr := nil;
    ConfSvr := CoPayphoneConfigSvr.Create;

TO:-
    if not Assigned(ConfSvr) then ConfSvr := CoPayphoneConfigSvr.Create;

Now, the problem is gone away. Who can give me the explanation of this situation, I will give the point.

SoapSiam.
0
 
LVL 14

Assisted Solution

by:DragonSlayer
DragonSlayer earned 50 total points
ID: 11987629
as F68 said, I would guess that there might be some problem with your ConfSvr's cleaning up code? because when you assign it to nil, the object get destroyed. I think I would start tracing from there.
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 75 total points
ID: 11987704
Setting an object to nil means to unassign a pointer to a memory allocation, but it don't frees the object itself. A dirty example to better explain: P is a var assigned to a Com Server. The Com Server is connected, then P is forced to nil: the Com server interface is still connected...Recreating and Reassigning P to it and then trying to connect it give an error...
Checking the assigned without forcing the pointer to nil returns a nil result just if it was correctly destroyed...

Better writing  the procs into a try/finally/except statement like

procedure TfrmFirstConnect.mnuNewPayphoneClick(Sender: TObject);
var
    Zone, ZoneParam : string;
    PMSID, PayphoneID : Integer;
begin
    if not ADOSpMaster.Active then Exit;
    ConfSvr := nil;
    ConfSvr := CoPayphoneConfigSvr.Create;

    PMSID       := ADOSpMaster.FieldByName('PMSID').AsInteger;
    PayphoneID  := ADOSpMaster.FieldByName('PayphoneID').AsInteger;
    Zone        := MainDM.ServerName;
    ZoneParam   := MainDM.ADOConn.ConnectionString;
    if ConfSvr.Login('user','user',Zone, ZoneParam) then
    begin
        ConfSvr.NewLine(Zone, PMSID, PayphoneID);
    end
    else
        MessageDlg('Cannot login',mtError,[mbYes],0);
end;
procedure TfrmFirstConnect.mnuNewPayphoneClick(Sender: TObject);
var
    Zone, ZoneParam : string;
    PMSID, PayphoneID : Integer;
begin
    if not ADOSpMaster.Active then Exit;
    ConfSvr := CoPayphoneConfigSvr.Create;
    try
       PMSID       := ADOSpMaster.FieldByName('PMSID').AsInteger;
       PayphoneID  := ADOSpMaster.FieldByName('PayphoneID').AsInteger;
       Zone        := MainDM.ServerName;
       ZoneParam   := MainDM.ADOConn.ConnectionString;
       try
           ConfSvr.Login('user','user',Zone, ZoneParam) then
           ConfSvr.NewLine(Zone, PMSID, PayphoneID);
       except
           MessageDlg('Cannot login',mtError,[mbYes],0);
       end;
      ....
      ....
    finally
       FreeAndNil(ConfSrv);
   end;
end;

F68 ;-)
0
 
LVL 1

Author Comment

by:soapsiam
ID: 12023849
As it is COM interface, setting it to nil should make the COM object get destroyed if it ref. count =0, am I correct?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question