 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ross Wise Guest
|
Posted: Tue Apr 27, 2004 1:30 am Post subject: Event Handler |
|
|
Hey!
How do I write and attach an event handler to an un-published (doesn't show on object inspector) event?
Specifically in D7 connected to IB6.5
I am trying to trap for an EDatabaseError exception on a TSQLDataSet.
A Try..Execpt block doesn't work; appareantly because the component has handled the exception by the time it would fall through
to the except block. I assume that I need to write an OnPostError event handler but that is not a published event.
How do I do this, or is there an easier way?
Ross
WEAVE, Inc.
Sacramento, CA
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Tue Apr 27, 2004 2:22 am Post subject: Re: Event Handler |
|
|
Ross Wise wrote:
| Quote: |
I am trying to trap for an EDatabaseError exception on a TSQLDataSet.
A Try..Execpt block doesn't work; appareantly because the component
has handled the exception by the time it would fall through to the
except block.
|
That shouldn't be the case, how are you trying to trap it? Show us the
try/except block.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Tue Apr 27, 2004 2:38 am Post subject: Re: Event Handler |
|
|
Since TSQLDataSet is read only it is not possible to generate an
OnPostError event. That is why the event is not published. To update
data returned by TSQLDataSet interactively you must use a
DataSetProvider and TClientDataSet. Errors will be returned through
the ClientDataSet's OnReconcileError event handler.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Ross Wise Guest
|
Posted: Tue Apr 27, 2004 5:23 pm Post subject: Re: Event Handler |
|
|
Wayne,
Thanks for replying, the code is below:
Bill,
Thanks for replying. I'm not trying to update data returned, I'm executing an INSERT statement.
This is the Statement in the tSQLDataSet "sqldsV_InsertPhoneNumbers"
INSERT INTO DX_PHONE_NUMBERS
VALUES ( :ClientID,
:PhoneID,
:AreaCode,
:PhoneNumber,
:Extension,
:CallingRule ) ;
The primary key on DX_PHONE_NUMBERS is (ClientID+PhoneID), I am trying to capture a "PRIMARY or UNIQUE KEY constraint" exception.
Here is the code, the MessageDlg statement is never executed, an EDatabaseError halts the program:
:
:
then with cDemogRec.PH_Numbers[loopCount]
{with} do begin
sqldsV_InsertPhoneNumbers.close ;
sqldsV_InsertPhoneNumbers.ParamByName('ClientID').AsInteger := cDemogRec.ClientID ;
if Phone_ID <> ''
then sqldsV_InsertPhoneNumbers.ParamByName('PhoneID').AsString := Phone_ID
else sqldsV_InsertPhoneNumbers.ParamByName('PhoneID').AsString := 'Phone#'+IntToStr(loopCount) ;
sqldsV_InsertPhoneNumbers.ParamByName('AreaCode').AsString := Phone_AreaCode ;
sqldsV_InsertPhoneNumbers.ParamByName('PhoneNumber').AsString := Phone_Number ;
sqldsV_InsertPhoneNumbers.ParamByName('Extension').AsString := '' ;
sqldsV_InsertPhoneNumbers.ParamByName('CallingRule').AsString := Phone_CallingRule ;
try
sqldsV_InsertPhoneNumbers.ExecSQL ;
except
on E: EDataBaseError
{exception} do begin
MessageDlg('Exception Encountered...',mtInformation,[mbOK],0) ;
ShowException(E,Addr(E)) ;
{exception} end ;
{try} end ;
{with} end ;
:
:
Wayne Niddery [TeamB] wrote:
| Quote: | Ross Wise wrote:
I am trying to trap for an EDatabaseError exception on a TSQLDataSet.
A Try..Execpt block doesn't work; appareantly because the component
has handled the exception by the time it would fall through to the
except block.
That shouldn't be the case, how are you trying to trap it? Show us the
try/except block.
|
Bill Todd (TeamB) wrote:
| Quote: | Since TSQLDataSet is read only it is not possible to generate an
OnPostError event. That is why the event is not published. To update
data returned by TSQLDataSet interactively you must use a
DataSetProvider and TClientDataSet. Errors will be returned through
the ClientDataSet's OnReconcileError event handler.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Tue Apr 27, 2004 8:03 pm Post subject: Re: Event Handler |
|
|
Ross Wise wrote:
| Quote: | try
sqldsV_InsertPhoneNumbers.ExecSQL ;
except
on E: EDataBaseError
{exception} do begin
MessageDlg('Exception
Encountered...',mtInformation,[mbOK],0) ;
ShowException(E,Addr(E)) ;
{exception} end ;
{try} end ;
{with} end ;
|
Perhaps the exception being raised is not of type EDataBaseError. Put a
case - on E:Exception - and se if it goes there in the debugger. You'll be
able to see what class the exception is.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Ross Wise Guest
|
Posted: Tue Apr 27, 2004 8:41 pm Post subject: Re: Event Handler |
|
|
Wayne,
I found out what was happening. The Debugger was capturing the error!
Running the application outside the IDE or with the debugger instructed to ignore EDatabaseError exceptions, the code works as
expected.
Now, a new question: Identifying a Duplicate Key error as opposed to some other error:
This works:
ErrorCondition := E.Message ;
if pos('PRIMARY or UNIQUE KEY constraint',ErrorCondition) > 0
then MessageDlg('Duplicate Key Encountered',mtInformation,[mbOK],0)
else ShowException(E,Addr(E)) ;
But seems somewhat unreliable since it depends on the error string remaining exactly the same. Is there another property or
method for identifying error 'sub-types'?
Ross Wise
WEAVE, Inc.
Sacramento, CA
Wayne Niddery [TeamB] wrote:
| Quote: | Ross Wise wrote:
try
sqldsV_InsertPhoneNumbers.ExecSQL ;
except
on E: EDataBaseError
{exception} do begin
MessageDlg('Exception
Encountered...',mtInformation,[mbOK],0) ;
ShowException(E,Addr(E)) ;
{exception} end ;
{try} end ;
{with} end ;
Perhaps the exception being raised is not of type EDataBaseError. Put a
case - on E:Exception - and se if it goes there in the debugger. You'll be
able to see what class the exception is.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|