Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 184
Performance of SQL statement 37 147
JAudiorecorder record freezing the app 29 92
how can i delete one control based on its tagstring ? 6 58
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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