Board index » delphi » Problem with a little program...HELP!!!!

Problem with a little program...HELP!!!!

I have a little source code that is making me a
lot of problems:

procedure TForm1.Table1CalcFields(DataSet: TDataset);
var i: integer;
    s: string;
begin
     i := 1;
     Table1.First;
     repeat
          Table1.Edit;
          Table1.FieldByName('ST_ZAPISA').AsInteger := i;
          Table1.Post;
          Table1.Next;
          Inc(i);
     until Table1.EOF;
end;

This should work fine, but it comes to Table1.Post it just
jumps back to begin!! Does anyone know what the problem
could be?

Please E-Mail

 

Re:Problem with a little program...HELP!!!!


hello,
The pb doesn't come from the post but from the event you use,
If you put this code on a tbuttonclick for example it works well.

In your sample, that's what append :
1. calcfields event is fired
2. your code is executing and when you do the post, the post fires a
calcfields event
and so on....
You can check it by looking to the call stack at runtime.
The code associated to the oncalcfields event should not modify the active
table.
for more information, look at the autocalcfields property in delphi help.
May be that
putting it to false will solve the pb.

Now I know that you'll try to erase the post from the code, and it won't
work because
the Next, or prior... methods automatically call the post method.
You'll have to try something else.

Best wishes
--
------------------------------------------------
Julien DEVILLERS
jdevill...@ceteso.min-equip.fr
jdevill...@cete33.equipement.gouv.fr
Ne faites jamais confiance un ordinateur
Never trust a computer (in english in ze text)
------------------------------------------------

ZoneMan <Rok.An...@guest.arnes.si> a crit dans l'article
<5jv6b1$ol...@kanja.arnes.si>...

Quote
> I have a little source code that is making me a
> lot of problems:

> procedure TForm1.Table1CalcFields(DataSet: TDataset);
> var i: integer;
>     s: string;
> begin
>      i := 1;
>      Table1.First;
>      repeat
>           Table1.Edit;
>           Table1.FieldByName('ST_ZAPISA').AsInteger := i;
>           Table1.Post;
>           Table1.Next;
>           Inc(i);
>      until Table1.EOF;
> end;

> This should work fine, but it comes to Table1.Post it just
> jumps back to begin!! Does anyone know what the problem
> could be?

> Please E-Mail

Re:Problem with a little program...HELP!!!!


        Or in the code, set the OnCalc event to Nil while you handler runs.
        This may work, give it a try.

procedure TForm1.Table1CalcFields(DataSet: TDataset);
var i: integer;
    s: string;
begin
    Table1.OnCalcFields := Nil;         {Add this line}
     i := 1;
     Table1.First;
     repeat
          Table1.Edit;
          Table1.FieldByName('ST_ZAPISA').AsInteger := i;
          Table1.Post;
          Table1.Next;
          Inc(i);
     until Table1.EOF;
         Table1.OnCalcFields := Table1CalcFields;       { and this line}
end;

--
Rob Tanner B.E.,B.Sc.
Design Engineer
WestBau Technologies, Inc.

Julien DEVILLERS <jdevill...@ceteso.min-equip.fr> wrote in article
<01ba163e$89effda0$53411...@jdevillers.cete33.equipement.gouv.fr>...

Quote
> hello,
> The pb doesn't come from the post but from the event you use,
> If you put this code on a tbuttonclick for example it works well.

> In your sample, that's what append :
> 1. calcfields event is fired
> 2. your code is executing and when you do the post, the post fires a
> calcfields event
> and so on....
> You can check it by looking to the call stack at runtime.
> The code associated to the oncalcfields event should not modify the
active
> table.
> for more information, look at the autocalcfields property in delphi help.
> May be that
> putting it to false will solve the pb.

> Now I know that you'll try to erase the post from the code, and it won't
> work because
> the Next, or prior... methods automatically call the post method.
> You'll have to try something else.

> Best wishes
> --
> ------------------------------------------------
> Julien DEVILLERS
> jdevill...@ceteso.min-equip.fr
> jdevill...@cete33.equipement.gouv.fr
> Ne faites jamais confiance un ordinateur
> Never trust a computer (in english in ze text)
> ------------------------------------------------

> ZoneMan <Rok.An...@guest.arnes.si> a crit dans l'article
> <5jv6b1$ol...@kanja.arnes.si>...
> > I have a little source code that is making me a
> > lot of problems:

> > procedure TForm1.Table1CalcFields(DataSet: TDataset);
> > var i: integer;
> >     s: string;
> > begin
> >      i := 1;
> >      Table1.First;
> >      repeat
> >           Table1.Edit;
> >           Table1.FieldByName('ST_ZAPISA').AsInteger := i;
> >           Table1.Post;
> >           Table1.Next;
> >           Inc(i);
> >      until Table1.EOF;
> > end;

> > This should work fine, but it comes to Table1.Post it just
> > jumps back to begin!! Does anyone know what the problem
> > could be?

> > Please E-Mail

Re:Problem with a little program...HELP!!!!


Quote
ZoneMan wrote:

> I have a little source code that is making me a
> lot of problems:

> procedure TForm1.Table1CalcFields(DataSet: TDataset);
> var i: integer;
>     s: string;
> begin
>      i := 1;
>      Table1.First;
>      repeat
>           Table1.Edit;
>           Table1.FieldByName('ST_ZAPISA').AsInteger := i;
>           Table1.Post;
>           Table1.Next;
>           Inc(i);
>      until Table1.EOF;
> end;

> This should work fine, but it comes to Table1.Post it just
> jumps back to begin!! Does anyone know what the problem
> could be?

> Please E-Mail

It looks like this is inside your OnCalcFields event handler. If it is,
calling Post will fire the OnCalcFields event, which will get you back
into this loop, starting again with the first record.

What interests me is, how does this end?

Other Threads