Solved

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

Posted on 2004-09-03
5
1,291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

763 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