Solved

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

Posted on 2004-09-03
5
1,241 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Secure Boot on W8 & 8.1 8 44
Thread safe  opinion 7 110
Run video youtube webbrowse 10 44
how to update exe applicatio from internet ? 6 35
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now