Subject Re: [IBO] Key Links and Deleting Records - Request Help
Author Helen Borrie (TeamIBO)
At 06:16 PM 27-02-02 +0000, Russ Newcomer wrote:
>Delphi 6.02, IBO4, FB RC2, Win2k.
>
>I have a piece of code that preforms a .locate on my dataset to find
>a specific record, delete it, then check to see if there is another
>record that meets to requirements of the .locate, delete, ad
>infinitum.
>
>The problem is that this code executes through fully the first time
>correctly, deleting all the records it needs to. The second time
>through this procedure, it dies on the first .delete.
>
>Here's the code that's giving me problems.
>
>var
> Index : Integer;
> Found : Boolean;
> RecordID : String;
>begin
> Index := 1;
> Found := True;
> cdm.ShipQuery.Edit;
> repeat {until not(found)}
> begin
> RecordID := ContractNum.Text + '.' + IntToStr(Index);
> Found := cdm.ShipQuery.Locate('Ship_ID', RecordID,
>[loCaseInsensitive]);
> if Found then
> cdm.ShipQuery.Delete;
> Index := Index + 1;
> end;
> until not(Found);
>end;

Replace this type of code for batch operations like this.

Drop a TIB_DSQL on your form and hook its ib_connection property up to your
connection object (IB_Connection or IBODatabase).

Give it this SQL:

DELETE FROM MyTable
WHERE Ship_ID STARTING WITH :Ship_ID


On your buttonclick, include this code:

...
with My_DSQL do begin
if not Prepared then Prepare;
Params[0].AsString := ContractNum.text + '.';
Execute;
end;
ShipQuery.Refresh;

Are you *really* determining your Keylinks from a field like this? I hope
you can trust your users to type in the right thing...


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com