Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2004, 07:29 AM
zeroms zeroms is offline
Member
 
Join Date: Dec 2001
Posts: 85
Default Problem with Bookmarks/DBGRID

Hi guys,

Got a problem with the following code, have picked it apart and cannot find anything obvious, i select items on the grid using a standard multiselect = true and use CTRL, when i press the add to order button sometimes the grid goes white and just freezes, if i then end the task it has done some of the bookmarks but not others, it seems to fail depending on what order the bookmarks are selected???

i am using a standard Ttable and standard Tdbgrid and delphi 7 with paradox tables.

Code:
    procedure TForm25.BitBtn21Click(Sender: TObject);
    var order,custno:string; currentRecord : TBookmark; iRecordsProcessed : Integer;
    begin
      if MessageDlg('Add part/s to order number: ' + order, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
        begin
          if table1.findkey([strtoint(order)]) then
            if (Table1Received.Value = True) or (Table1Sent.value = True) then
              showmessage('Cannot add to this order')
          else
            begin
              table10.DisableControls;
              CurrentRecord := table10.GetBookmark;
              table10.First;
              iRecordsProcessed := 0;
                while (NOT table10.EOF) and (iRecordsProcessed < DBGrid7.SelectedRows.Count) do
                  begin
                    if DBGrid7.SelectedRows.CurrentRowSelected then
                      begin
                        table2.append;
                        table2ordernumber.value := strtoint(order);
                        table2partnumber.value := table10partnumber.value;
                        table2description.value := table10description.value;
                        table2lastprice.value := table10lastprice.value;
                        table2location.value := table10location.value;
                        table2qty.value := table10qty.value;
                        table10.delete;
                        inc(iRecordsProcessed);
                      end;
                     table10.Next;
                  end;
              table10.FreeBookmark(CurrentRecord);
              table10.EnableControls;
            end;
        end;
    end;
Reply With Quote
  #2  
Old 09-28-2004, 08:55 AM
afx2029 afx2029 is offline
Senior Member
 
Join Date: Jul 2004
Posts: 478
Default RE: Problem with Bookmarks/DBGRID

Your logic is no good.

if you delete a record....the current record must change. Also, you're comparing your counter with the number of selected rows....if you delete a selected row...the Count property will change...but your counter just keeps incrementing....try using this:

OldBookmark: TBookmarkStr;
i: integer;


//First part of your code....
//"ELSE" part of IF clause
Table1.DisableControls;
try
OldBookmark := Table1.Bookmark;
try
for i := 0 to DBGrid1.SelectedRows.Count - 1 do
begin
Table1.Bookmark := DBGrid1.SelectedRows[i];
//Do all your operations on Table2
Table1.Delete;
end;
finally
Bookmark := OldBookmark;
OldBookmark := '';
end;
finally
table1.EnableControls;
end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:18 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.