Software snipets for the Delphi & Pascal Community
Sep 05, 2010 - 04:54 AM
alt1
Borland :: Mailing Lists
alt1
Search  
alt1
alt1 alt1 alt1
alt1
Main Menu
alt1
· Home
· Your Account

Other Options

· AvantGo
· Downloads
· FAQ
· Members List
· Messages
· News
· Recommend Us
· Reviews
· Search
· Sections
· Stats
· Submit News
· Topics
· Top List
· Web Links

alt1
Who's online
alt1
There are currently, 7 guest(s) and 0 member(s) online.

You are an anonymous user. You can register for free by clicking here


alt1
alt1
Fix Conflict between TDatabase & TObject
Posted by: Gayle
alt1
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.


alt1
alt1
 
alt1
Login
alt1
Username

Password

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.

alt1
Related links
alt1
· More about General Database Handling
· News by admin


Most read story in General Database Handling:
Fix Conflict between TDatabase & TObject


Printer friendly page  Send this story to a friend

"Fix Conflict between TDatabase & TObject" | Login/Create an account | 0 Comments
Threshold
Comments are owned by the poster. We aren't responsible for their content.
alt1
Report Bugs :: Tasks :: Developers 
alt1




alt1