"Vassil Nazarov" <s...@bulnet.bg> wrote in message news:395b6aa9@dnews...

> "Brian Slack" <br...@digitalwired.net> wrote in message

> news:8jevtk$70i2@bornews.borland.com...

> > Here is the full code

> > type

> > TDeleteArea = class(TForm)

> > Button1: TButton;

> > Button2: TButton;

> > cbToDelete: TCheckListBox;

> > adoMain: TADOTable;

> > edtAdd: TEdit;

> > Button3: TButton;

> > adoDelete: TADOCommand;

> > adoConn: TADOConnection;

> > procedure FormCreate(Sender: TObject);

> > procedure Button3Click(Sender: TObject);

> > procedure Button2Click(Sender: TObject);

> > procedure Button1Click(Sender: TObject);

> > private

> > function GetRid(WhatToGetRid:string):boolean;

> > public

> > procedure CreateParams(Var params: TCreateParams);override;

> > end;

> > var

> > DeleteArea: TDeleteArea;

> > implementation

> > {$R *.DFM}

> > procedure TDeleteArea.CreateParams(Var params: TCreateParams);

> > begin

> > inherited CreateParams( params );

> > params.ExStyle := params.ExStyle or WS_EX_TOOLWINDOW and not

> > WS_EX_APPWINDOW;

> > end;

> > procedure TDeleteArea.FormCreate(Sender: TObject);

> > begin

> > adoMain.FindFirst;

> > while not adoMain.Eof do

> > begin

> > cbToDelete.Items.Add( adoMain.FieldByName('Areas').AsString);

> > adoMain.Next;

> > end;

> > end;

> > procedure TDeleteArea.Button3Click(Sender: TObject);

> > var

> > ToAdd:string;

> > begin

> > ToAdd:= edtAdd.Text;

> > if edtAdd.Text > '' then

> > begin

> > adoMain.Append;

> The above line is redundant.

> > adoMain.InsertRecord([nil,ToAdd]);

> > cbToDelete.Clear;

> > adoMain.FindFirst;

> > while not adoMain.Eof do

> > begin

> > bToDelete.Items.Add( adoMain.FieldByName('Areas').AsString);

> > adoMain.Next;

> > end;

> > end;

> > end;

> For each new record you insert in adoMain you clear and populate

> cbToDelete again and again. Brian, that's crazy!

> > procedure TDeleteArea.Button2Click(Sender: TObject);

> > var

> > x: Integer;

> > begin

> > for x:= 0 to cbToDelete.Items.Count - 1 do

> > begin

> > if cbToDelete.Checked[x] = True then

> > begin

> > GetRid(cbToDelete.Items.Strings[x]);

> > end;

> > end;

> > cbToDelete.Clear;

> adoMain.Requery

> {Add this line to see the results}

> > adoMain.FindFirst;

> > while not adoMain.Eof do

> > begin

> > cbToDelete.Items.Add( adoMain.FieldByName('Areas').AsString);

> > adoMain.Next;

> > end;

> > end;

> > procedure TDeleteArea.Button1Click(Sender: TObject);

> > begin

> > close;

> > end;

> > function TDeleteArea.GetRid(WhatToGetRid:string):boolean;

> > begin

> > try

> > adoDelete.Prepared:=False;

> > adoDelete.CommandText:= 'DELETE * FROM Areas WHERE Areas.Areas =

'''

> > + WhatToGetRid + '''';

> > adoDelete.Prepared:=True;

> > adoDelete.Execute;

> > Result:=True

> > except

> > Result:=False;

> > end;

> > end;

> 1. In the procedure above it's better to leave adoDelete unprepared.

> 2. It's best to have:

> ...CommandText:= 'DELETE * FROM Areas WHERE Areas.Areas = :Areas';

> adoDelete.Prepared:=True;

> once and then:

> adoDelete.Parameters[0].Value := WhatToGetRid;

> adoDelete.Execute;

> many tymes.

> 3. Make shure that all of the following are true:

> - adoDelete.Connection is set to adoConn

> - adoMain.Connection is set to adoConn too.

> - adoDelete.ExecuteOptions=[eoExecuteNoRecords]

> - adoMain.ExecuteOptions=[ ]

> 4. Enjoy

> HTH

> --

> V. Nazarov

> IT Manager, Sofia Cable