BeforeDelete

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mierlp
Posts: 29
Joined: Thu 26 Jan 2006 08:34
Location: Nederlands

BeforeDelete

Post by mierlp » Mon 16 Jul 2007 09:29

hi,

I have 2 tables :
- city (with fields cityID(int), cityName)
- user (with lastname, firstname and cityID(int))

when i add a user i use the table city for selecting a city.
Now i must prevent that customers can deleted city names from
the table CITY when this id exists in table USER.

So i used this code at the table CITY BEFOREDELETE event :


dmTables.qry_user.IndexFieldNames:='user_cityID';
if dmTables.qry_user.FindKey([dmTables.qry_city.FieldByName('city_id').asString]) then begin
Application.MessageBox('Record can't be deleted.', 'Warning', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Abort;
end;
dmTables.qry_user.IndexFieldNames:='user_lastname';


The result is that there's NO warning and the record
will be deleted in the table CITY.

What's wrong with this code/solutions...are there better solutions.
Using MyISAM tables.

Greetz Peter

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 16 Jul 2007 14:35

Please check once again whether the BeforeDelete event handler is assigned correctly.
Place the breakpoint within this event handler, and check whether the execution will stop when you try to delete a record. Trace program execution by F7.

Post Reply