Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Putting a Table in Edit Mode

Posted on 1997-06-06
7
Medium Priority
?
168 Views
Last Modified: 2010-05-18
When I run the code below, I get an error stating 'Datset not in Insert or Edit Mode'.  As you can see, I place the table in edit mode several times. What am I doing wrong? (By the way, I'm trying to change a field's value to False if it equals True)

procedure TfrmGList.BitBtn1Click(Sender: TObject);
begin
if table1.state = dsInactive then
   table1.Active := True;
table1.edit;
table1.disablecontrols;
table1.first;
while not table1.EOF do
  begin
    if table1.FieldByName('Select').asBoolean <> False then
       table1.edit;
       table1.FieldByName('Select').asBoolean := False;
       table1.next;
  end;
  table1.first;
  table1.enablecontrols;
end;
0
Comment
Question by:d4jaj1
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
ygolan earned 80 total points
ID: 1336856
There should a "begin" following the "if" statement in the while loop. Because it is missing, the line where you modify the Select field will be activated even when the table is not in edit mode.  Here is the fixed code, note the comments :

procedure TfrmGList.BitBtn1Click(Sender: TObject);
begin
  if table1.state = dsInactive then
    table1.Active := True;
  table1.edit; // Not needed, you can remove this!
  table1.disablecontrols;
  table1.first;
  while not table1.EOF do
  begin
    if table1.FieldByName('Select').asBoolean <> False then
    begin // This was missing !!
      table1.edit;
      table1.FieldByName('Select').asBoolean := False;
      // it's safer to add table1.post here.
      table1.next;
    end; // And you need to add this as well
  end;
  table1.first;
  table1.enablecontrols;
end;
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1336857
Thanks for your quick response.  I think there is a problem though, when I run the code, nothing happens!  My system locks and the values aren't changed.  When I added the Showmessage when it finds False and after it makes the changes, it does so correctly - but goes on a continuous loop, like it never reached the EOF.   Some of the values are blank instead of false/true, could this be the problem. If I try to use ..."AsString" I get an error because the field is a logical Paradox field.  Where did I go wrong?

if table1.state = dsInactive then
   table1.Active := True;
   table1.disablecontrols;
   table1.first;
   while not table1.EOF do
     begin
       if table1.FieldByName('Select').asboolean <> False then
       Showmessage('Initial Found');  //It worked but never ended
       begin // This was missing !!
         table1.edit;
         table1.FieldByName('Select').asboolean := False;
         Showmessage('Changed');  //It worked but never ended
         //table1.post;
         table1.next;
       end; // And you need to add this as well
     end;
table1.refresh;
table1.first;
table1.enablecontrols;

0
 
LVL 1

Expert Comment

by:ygolan
ID: 1336858
Move the table1.next out of the "if". The way it is now, it will be an infinite loop indeed.


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:d4jaj1
ID: 1336859
Still doesn't work.  I commented the Disablecontrols and added the Showmessage methods so I couldl see it work.  here are still two problems, 1) The table changes values in every record, even if already equals False (although the Value Found only appears if True is found, not Blank) and 2) if never ends!  I moved the table1.next out of the If.. statement, but it still goes to the top of the grid and starts over.  Is the EOF in the wrong place?
************************************************************************
begin
table1.first;
showmessage('went first');
while not table1.EOF do
  begin
  if table1.FieldByName('Select').asBoolean <> False then
  showmessage('found value');
    begin // This was missing !!
    table1.edit;
    table1.FieldByName('Select').asBoolean := False;
    showmessage('changed');
    table1.post;
    end; // And you need to add this as well
  table1.next;
end;
end;
0
 
LVL 1

Expert Comment

by:ygolan
ID: 1336860
Remove the ShowMessage('found value') line and everything will work.

If you can't figure out why, up the points please.
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1336861
It worked!  I guess because the ShowMessage was the only statement being evaluated by the IF statement, thus the Begin statement execute regardless if teh IF statemenet returned a true or false value.

Great Job!!!
0
 
LVL 1

Expert Comment

by:ygolan
ID: 1336862
> It worked! I guess because the ShowMessage was the only
> statement being evaluated by the IF statement, thus the Begin
> statement execute regardless if teh IF statemenet returned a > true or false value.

Exactly.

I am glad to hear that it works.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question