Board index » delphi » Delete not deleting

Delete not deleting

To prevent garbage data being displayed when tables are first
opened before new records are started I want to clear out
'orphan' records from detail tables. These have an integer field
as part of a composite index. If this particular field is 0 or
null then I want to delete it. I open only the detail table but
the following code seems to do nothing, even though in tooltips
tell me that the value is indeed zero. There is no code in the
OnDelete event and there is no further detail table.

  if not dm.InsRepItems.Active then Begin
   dm.InsRepItems.Active := True;
   if not DM.InsRepItemsJobNo.Value>0 then      
DM.InsRepItems.Delete;
  end;

I would expect this code to check the first record in the table,
if it doesn't have a valid job no then delete and hence move bof
to the next record.

I have plugged the gap that caused the creation of such records
but I want to have a transparent means of clearing them out in
existing systems (some 200 of them).

Pat Bell

 

Re:Delete not deleting


Quote
"P.S.Bell" <p...@PatBell.demon.co.uk> wrote in message

news:VA.000002d3.002e50a7@patbell.demon.co.uk...

Quote
>    if not DM.InsRepItemsJobNo.Value>0 then
> DM.InsRepItems.Delete;
>   end;

> I would expect this code to check the first record in the table,
> if it doesn't have a valid job no then delete and hence move bof
> to the next record.

You might try changing that to -
  if not DM.InsRepItemsJobNo.ASINTEGER >0 then

However, the code you did not show may be more important.

If your code runs like ...

  First;
  if NotValidNumber then
    Delete;
  Next;

... then you have a set yourself a trap.

After you delete a record all the records below will jump up one so the
cursor is on the next record already.  In the above example it would then be
stepped to the next record again, so missing a row.

But you may know that already, in which case pardon me for intruding.  : )

--
Regards,
Chris Luck.
Responses to newsgroup please.

Re:Delete not deleting


You might try

if (DM.InsRepItemsJobNo.Value=0) or (Dm.InsRepItemsJobNo.IsNull) then
DM.InsRepItems.Delete;

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Delete not deleting


Quote
In article <8sfts5$5...@bornews.borland.com>, Bill Todd (TeamB) wrote:
> You might try

> if (DM.InsRepItemsJobNo.Value=0) or (Dm.InsRepItemsJobNo.IsNull) then
> DM.InsRepItems.Delete;

> --
> Bill Todd (TeamB)
> (Questions received via email cannot be answered.)

That did the trick. Thanks.

Pat Bell

Other Threads