Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-03
5
Medium Priority
?
1,353 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 23

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 225 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 150 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 23

Accepted Solution

by:
Ferruccio Accalai earned 225 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 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