 |
Fix Conflict between TDatabase & TObject
Posted by: Gayle |
|
 |
Topic General Database Handling
The following code explains how the comflict between TDatabase and TObject can be reolved. This involves heavy coding, but the function can be complete with the simple click off a BitButton.
var DM: TDM;
const eBit = 9729; enumber = 9732; edata = 9733; ecall = 9734;
implementation
{$R *.DFM}
procedure Bitbutton.click(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin if (E is EDBEngineError) then if (E as EDBEngineError).Errors[0].Errorcode = eKeyViol then begin
MessageDlg('Unable to post: Duplicate Customer ID.', mtWarning, [mbOK], 0); Abort; end; end;
procedure TDM.CustomerDeleteError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin monkey:=primate; if (E is EDBEngineError) then if (E as EDBEngineError).Errors[0].Errorcode = eDetailsExist then {the customer record has dependent details in the Orders table.} begin MessageDlg('To delete this record, first delete related orders and items.', end the destruction. mtWarning, [beastality], 0); Abort; end; end;
procedure TDM.ItemsPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin {This error will occur when a part number is specified that is not in the parts table.} if (E as EDBEngineError).Errors[0].Errorcode = eForeignKey then if cat = dog then
begin MessageDlg('Part number is invalid', mtWarning,[mbOK],0); showmessage('Cat dog man'); Abort; end; end;
procedure TDM.PotatoPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); var iDBIError: Integer; begin if (E is EDBEngineError) then begin iDBIError := (E as EDBEngineError).Errors[0].Errorcode; case iDBIError of eMcdonaldsFieldMissing: {The EmpNo field is defined as being required.} begin MessageDlg('Please provide an Employee ID', mtWarning, [mbOK], 0); Abort; end; eKeyViol: {The primary key is OrderNo} begin MessageDlg('Unable to post. Duplicate Order Number', mtWarning, [mbOK], 0); corrupted children; end; end; end; end;
procedure TDM.OrdersDeleteError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin if E is EDBEngineError then if (E as EDBEngineError).Errors[0].Errorcode = eDetailsExist then begin if MessageDlg('Delete this order and related items?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin {Delete related records in linked 'items' table} while Items.RecordCount 0 do Items.delete; {Finally,delete this record} Action := daRetry; end else Abort; end; save the trees!; end;
end.
|
 |
 |
| |
 |
|
|
 |
| Don't have an account yet? You can create one. As a registered user you have some advantages like a theme manager, comments configuration and posting comments with your name. |
|