Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Edits over a filtered field
Thu, Apr 23 2009 5:51 AMPermanent Link

Paul Baumann
Hi all,

in an older application i am using V2.12.

now i am implemeting a function where user can initiate a batch edit, lets say write in
the field "groups" the value "sponsor".

the problem ocurrs, if one sets a filter right to the editing field, lets say "groups IS
NULL".
now in every batch editing job only the half of records is edited.
in batch editing i use this code (simplyfied)

Table1.First;
while not Table1.EOF do
begin
 Table1.Edit;
 Table1.FindField('Groups').AsString := 'Sponsor';
 Table1.Post;
 Table1.Next;
end;

i know why only the half records are processed. to do it with a query is no way, cause as
i wrote this code above is simplyfied. user is able to configure if he wants to replace
the field value with a new value, add the new value to the current field value, or to
delete value from current field value and to empty the field. also it should work with
text and memo fields.

i tried it with a second table, which doesnt belong to the same database. i stepp through
Table1, locate and edit the record in Table2. but this didnt change anything.

Any tipps for me? Thank you.
Thu, Apr 23 2009 3:04 PMPermanent Link

"Jeff Cook"
Paul Baumann wrote:

>
> Table1.First;
> while not Table1.EOF do
> begin
>   Table1.Edit;
>   Table1.FindField('Groups').AsString := 'Sponsor';
>   Table1.Post;
>   Table1.Next;
> end;
>
> i know why only the half records are processed. to do it with a query

Kia Orana Paul

The problem is that when you post the changed record to the table, it
now doesn't satisfy the filter.  This means the cursor must move to
another record.  Then you say "Next" which hops over that record.

Simply change the .Next to .First and you should be fine.

Kia Manuia

Jeff

--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz
+
Joan and Jeff Cook
The Cooks Oasis
www.cookislandsoasis.com
Fri, Apr 24 2009 2:38 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Jeff


>> Table1.First;
>> while not Table1.EOF do
>> begin
>> Table1.Edit;
>> Table1.FindField('Groups').AsString := 'Sponsor';
>> Table1.Post;
>> Table1.Next;
>> end;
>>
>> i know why only the half records are processed. to do it with a query
>
>Kia Orana Paul
>
>The problem is that when you post the changed record to the table, it
>now doesn't satisfy the filter. This means the cursor must move to
>another record. Then you say "Next" which hops over that record.
>
>Simply change the .Next to .First and you should be fine.

That will only work if none of the records satisfy the filter, if you ever hit one that satisfies the filter after being altered you have an infinite loop. What's needed is something like:

Table1.First;
oldid := Table1.FieldByName(idfield).AsString;
while not Table1.EOF do
begin
Table1.Edit;
Table1.FindField('Groups').AsString := 'Sponsor';
Table1.Post;
if Table1.FieldByName(idfield).AsString = oldid then Table1.Next;
oldid := Table1.FieldByName(idfield).AsString;
end;

Roy Lambert [Team Elevate]
Fri, Apr 24 2009 5:35 AMPermanent Link

Paul Baumann
Roy Lambert wrote:

That will only work if none of the records satisfy the filter, if you ever hit one that
satisfies the filter after being altered you have an infinite loop. What's needed is
something like:

Table1.First;
oldid := Table1.FieldByName(idfield).AsString;
while not Table1.EOF do
begin
Table1.Edit;
Table1.FindField('Groups').AsString := 'Sponsor';
Table1.Post;
if Table1.FieldByName(idfield).AsString = oldid then Table1.Next;
oldid := Table1.FieldByName(idfield).AsString;
end;

----------------------
Thanks for answers.

yeah, Roy, thats it Smile
sometimes you dont see the forest cause of all the trees Frown
Fri, Apr 24 2009 6:41 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Paul


>yeah, Roy, thats it Smile
>sometimes you dont see the forest cause of all the trees Frown

I have been lost in that particular forest many times for many hours

Roy Lambert [Team Elevate]
Fri, Apr 24 2009 3:58 PMPermanent Link

"Jeff Cook"
Roy Lambert wrote:

>
> That will only work if none of the records satisfy the filter, if you
> ever hit one that satisfies the filter after being altered you have
> an infinite loop. What's needed is something like:
>

True, Roy

But the original poster said there was a filter of

"groups IS NULL",

so setting groups to anything except NULL will ensure it doesn't satify
the filter.  Unless of course empty fields were treated as NULL, which
reminds me of a debate somewhere Wink

--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz
+
Joan and Jeff Cook
The Cooks Oasis
www.cookislandsoasis.com
Sat, Apr 25 2009 4:00 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Jeff

>But the original poster said there was a filter of
>
>"groups IS NULL",
>
>so setting groups to anything except NULL will ensure it doesn't satify
>the filter. Unless of course empty fields were treated as NULL, which
>reminds me of a debate somewhere Wink

Forcing myself to ignore the deliberate provocation Smileyyou're right and in that specialised case your solution would work. How much would you like to bet that the OP doesn't have other filters?

Roy Lambert [Team Elevate]
Mon, Apr 27 2009 3:19 PMPermanent Link

"Jeff Cook"
Roy Lambert wrote:

>
> Forcing myself to ignore the deliberate provocation Smileyyou're right
> and in that specialised case your solution would work. How much would
> you like to bet that the OP doesn't have other filters?
>
> Roy Lambert [Team Elevate]


Deliberate provocation?  Moi?


--
Jeff Cook
Aspect Systems Ltd
www.aspect.co.nz
+
Joan and Jeff Cook
The Cooks Oasis
www.cookislandsoasis.com
Image