Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why donot i use exception handler in dpr ?

Status
Not open for further replies.

IPOz

Programmer
Jul 11, 2001
109
CN
The following is a dpr framework
.....
const
APP_FLAG = 'LON-METER-READER';
var
app_atom : ATOM;

begin
Application.Initialize;

app_atom := globalFindAtom(APP_FLAG);
try
if app_atom <> 0 then begin //only allow one instance
Application.Terminate ;
end
else begin
splash_frm := Tsplash_frm.create(Application);
splash_frm.show;
splash_frm.update;
app_atom := globalAddAtom(APP_FLAG);
try
try
DM := TDM.Create(application);
except
//can not come here even if there is a exception
//in TDM's onCreate method as below
raise;
end;
login_frm := Tlogin_frm.create(application);
finally
splash_frm.hide;
splash_frm.free;
end;

if login_frm.ShowModal <> idOk then begin
application.Terminate;
exit;
end;
Application.CreateForm(Tmain_frm, main_frm);
Application.Run;
end;
finally
//do cleanup work
globalDeleteAtom(app_atom);

login_frm.free;
DM.free;
end;
end.

procedure TDM.DataModuleCreate(Sender: TObject);
begin
...
try
myDB.Connected := true;
except
raise; //will raise exception here
end;
end;

----------------------------------------------

I donot know why i cannot catch the exception raised by TDM.DataModuleCreate :(


Any suggestion is appreciated ! ipo_z@cmmail.com
garbage in,garbage out
 
The runtime system is not running yes, as your exception is triggered. Move your code to the FormCreate event of main_frm, or maybe to the OnShow event, what is the most convenient for your app.
I'm not that much up to speed in datamodules, but why are you trying to start something that should be started only on first database-access?

HTH,
TonHu
 
The runtime system is not running yet, as your exception is triggered. Move your code to the FormCreate event of main_frm, or maybe to the OnShow event, what is the most convenient for your app.
I'm not that much up to speed in datamodules, but why are you trying to start something that should be started only on first database-access?

HTH,
TonHu
 
thank you for your quick answer !
if what you said is right then why does the &quot;try ... finally&quot; works in dpr ?
By delving the assembly code i find that compiler seems do something for the &quot;try...finally&quot; however nothing for &quot;try...except&quot; !

sorry i donot understand how the compiler creates the assembly code for exception handling very well :(

can you explain it in detail ? ipo_z@cmmail.com
garbage in,garbage out
 
I was merely shouting what came to mind first, and as you call application.run after generating the exception I would thing the 'system' is not in it's 'normal' state yet.
I dunno anything about the assembly generation s-) sorry.

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top