PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD21] FOR ALL does not always work as documented
[WD21] FOR ALL does not always work as documented
Débuté par Ola, 02 aoû. 2017 23:10 - 16 réponses
Posté le 02 août 2017 - 23:10
Al wrote in 2012: "The other thing I have found with the For All syntax is that it doesn't always work if the action you take inside the loop writes to the file being scanned, so if your Do_The_Deed code writes to the OrderItem file it can cause it to go to the end of the file and close out of the For All loop."
http://27130.foren.mysnip.de/read.php…
(bolding is mine)

Well, no improvement in this respect. The same problem still exists in WD21; the code doesn't do what it is supposed to do, it just slips through the loop doing nothing...

The workaround for this is to use instead a HReadFirst - HReadNext structure to do the deed.

Best regards
Ola

PCSoft's motto: "Why fix old bugs when it's much more fun creating new ones":eek:
Posté le 03 août 2017 - 07:10
Hi Ola,

you will not believe it - cannot remember a single case where I used that FOR ALL thing. The (my) good old way is to

HReadFirst(MyFile, MyKey)
While not HOut(MyFile)

// do whatever you want here ...

HReadNext(MyFile)
END

Next one: Write Operations like HAdd and HModify can / will put the file pointer somewhere else than you thought it to be during the browse. Personally, I'm using HSavePosition and HRestorePosition to exclude any unwanted effects. However, there's an option to HAdd

hWriteDefault (default value)
Effect of the addition on the browse: The addition does not affect the current browse.
For example, HReadNext used after HAdd positions on the record found after the current record before the addition.
The hAffectBrowse constant has priority over the hWriteDefault constant.

Whenever you're adding records within a browse you have to think about the file pointer. Where is it now? Do some tests to assure yourself ... the description of FOR EACH and FOR ALL is not very helpful in regards to detailing the file pointer's position after HAdd, HModify and HSave operations within the loop.
Posté le 03 août 2017 - 07:34
Hi Ola,

This is not really a bug, this is probably by design and the same is true for other programming languages. Even in Microsoft Navision ERP (C/AL Language), you have the same effect when you change some record that would effect the order, or number of items to browse inside the loop like FOR ALL.

So it is something you always have to be carefull with !

Danny
Posté le 03 août 2017 - 09:38
Hi Ola,

Tip: use FOR EACH on query result sets (As a matter of fact use queries in all cases).

This way you can do anything on the source db file (hExecuteQuery/hadd/hread+hmodify/hread+hdelete) without affecting the query result data set in memory that you are currently browsing.

As Danny stated, this is by design and would be the same in most programming languages having a similar direct db access syntax.

Cheers,

Peter Holemans
Posté le 03 août 2017 - 10:40
Hi all,

Thanks for the comments. I use FOR ALL a lot, especially when there is mostly just a few records to be handled. It's simple and easy. It's just updating the same file within the loop that does not work reliably in FOR ALL.

@Guenter: That's just what I said "The workaround for this is to use instead a HReadFirst - HReadNext structure to do the deed.". It works OK without HSavePosition and HRestorePosition, at least in my case. Maybe PCSoft should use something like them in the FOR ALL structure?

hWriteDefault (default value) is a new acquaintance for me. I'll have to take a closer look at it. Thanks for the hint.

@Danny and Peter: "this is by design and would be the same in most programming languages". Does this implicitely hint that there are also languages that do not have this negative "feature" in a similar structure?

IF HReadFirst - HReadNext works without problems, then why not FOR ALL? Basically they are both doing the same.

Best regards
Ola
Posté le 03 août 2017 - 11:50
Modifying multiple records IN A LOOP usually indicates that all valid records will be updated with the same values.
In this case an 'Update' query is the simplest and most efficient method.

The query can be generated in the Query Generator, the SQL code would take the formatUPDATE MyFile SET Column1 = NewValue Column2 = NewValue WHERE Column5 = A Value AND Column6 = {A param} //Could be an OR statement etc Benefits are obvious....
No complicated filtering of the records in the app code.
No loop - modifying 1 record at a time.
Single call - only 1 point of failure.
Runs on server - blindingly quick whether for a few or hundreds of records.
Posté le 03 août 2017 - 13:41
Hi Ola,

BE CAREFUL!

You will have the exact same problem with a hreadfirst, hreadnext, if you modify the order of the key used in the loop and depending of the options of your hmodify.

You ALWAYS had the same problem in the old time, as the hAffectBrowse option did not exist, and the order was always affected.

I personnaly NEVER use the FOR ALL syntax.

Best regards
Posté le 03 août 2017 - 17:44
Hi Ola,

As Peter has already said, I always use a query and then use FOR EACH... to work through the result set.
Posté le 04 août 2017 - 10:34
Quote
Fabrice

I personnaly NEVER use the FOR ALL syntax.

For each string s1 of Str2
for each ds of data source
for each selected row of

No? :)

I had for each in Progress 4gl years ago and liked it, was actually my first posting on the Clarion forum some odd 20 years ago "Where is the for each" :D

Cheers
Tor-Bjarne
Posté le 04 août 2017 - 16:15
Hi Tor Bjarne

Nope

For each string s1 of Str2

Loop+extractstring

for each ds of data source
Hreadfirst/next

for each selected row of
loop+tableselect

I was raised in windev WAY before the for each appeared in WL, and I find that I have much more control over what is happening in what order when I use the old syntaxes. The "for all" seem to be in the categories of things they had to add for people coming from another language to feel at ease, and you seem to be confirming that.

And for those of you who don't know me yet, I DO like to be in control when I code :-)

Best regards
Posté le 04 août 2017 - 17:22
Quote
Fabrice

And for those of you who don't know me yet, I DO like to be in control when I code

Hi Fabrice,

Agree completely... I tend to be a control freak too (although I almost always use the For Each syntax ;-) ). But... with WX I felt often having no control at all about many areas of the WX runtime and its (often half baked) functions and features. It is one of the reasons I've been leaving it mostly for new projects in favour of a more general purpose language since a couple of years...

WX is great if you stick to its paradigm, accept its limitations and don't use it advertised features to their maximum. It claims to be an open general purpose language but as a matter of fact is not because of the many limitations (WD is the most mature)... I had to learn it the hard way. Been there done that for more than 17 years. I just hit the brick wall too many times without any embedded or third party alternatives (aside of developing a supplement myself in C or C#) available making development very tedious and slow. Stick to its paradigm as if you were using Filemaker or so and it'll work as advertised... And most important, don't try to write code that runs anywhere (WD+WB+WM). The runtime has too many holes in this area. The day it becomes a general purpose open platform I'll be the first to return.

Cheers,

Peter Holemans
Posté le 05 août 2017 - 00:11
Quote
Fabrice

The "for all" seem to be in the categories of things they had to add for people coming from another language to feel at ease, and you seem to be confirming that.

Yup, I can confirm and I love our "for each"`es, as mentioned earlier, in Clarion there where no "for each", personally I always saw that as a weakness in the Clarion language.

I do however feel I`m quite in control with the different "For each"`es, otherwise I would`t use them.

It`s one of the many small nifty stuff in WinDev that hopefully, if this not make me 10 times faster, and perhaps only 1.2 time faster, this still give me an advantage over the next dude:)

I do however execute a query, before a for each in a query(file) unless I`m sort of building a listbox, so I could do a hReadSek on the record if I need to change something in the same table (The "one filebuffer" point learned).

Well I guess we all have different coding-styles and preferences.

Cheers
Tor-Bjarne
Posté le 05 août 2017 - 13:41
Hi Peter,

Quote
Peter Holemans



I had to learn it the hard way. Been there done that for more than 17 years. I just hit the brick wall too many times without any embedded or third party alternatives (aside of developing a supplement myself in C or C#) available making development very tedious and slow. Stick to its paradigm as if you were using Filemaker or so and it'll work as advertised... And most important, don't try to write code that runs anywhere (WD+WB+WM). The runtime has too many holes in this area. The day it becomes a general purpose open platform I'll be the first to return.


I have to disagree here... Of course, I don't use the new features as soon as they come out. But I NEVER had to code in another language to do a work around, I just coded the features I needed myself in wlangage. By example, in WinDev 5.5, we (and mostly Dominique Daussy did) coded a full featured hierarchical table (with more features than the current one) in pure wlanguage, while Mario Igrec coded a full featured code editor, with syntax coloration and all of that (for the cutomized code management), and I created what amount to a SQL language interpretor and engine, and those are just a few examples of things completely doable in wlangage, even if the corresponding feature is missing of half baked, as you describe it.

As for writing code for multiplatform, WXReplication is the perfect example of me disagreeing with you. All the classes managing generic stuff are fully mobile/webdev/windev capable. Yes, it will require more discipline, but it is perfectly doable.

It just look to me like you prefer to complain about it and go somewhere else. In my case, I'm still waiting for the brick wall, and I'm at about 25 years on. Nothings perfect, and PCSoft product certainly not, but your description reflects more your personal frustration than the reality in my opinion.

Best regards
Posté le 05 août 2017 - 15:58
Hi Fabrice,

As an example: try to consume standard SharePoint webservices out of WX including ComplexType xml elements. Undoable unless you write your own C# stub .Net assembly to be called out of WX using basic types only to be exchanged.

As another example, try to use the Record datatype or dbgxxx functions in a WX program/function that you want to run on all platforms (WD+WB Windows+WMAndroid+WMiOS+WMWindows)... It won't work, won't even compile...

As another example, try to do an authentication using Negotiate/NTLM (for web services, remote calls, resource usage, any standard corporate domain integration and resource access, ...). Forget it. Only basic and oAuth are available.

There are workarounds like writing something yourself in another language but that kills the marketing claims of being a fast(er) development tool. I've been lightning fast with WD in the past due to my own frameworks written over the years. Development paradigms and general application architectures however have shifted so much over the last decade that WX is no longer in competition (surely not WB). As stated, the day it becomes again a general purpose language with a real platform agnostic runtime and moreover an open (!!!) architecture I'll be the first to evaluate it again. In my new environment I have tens of thousands of external resources I can tap into to speed up development. Heck, I can even write my own code generators that can write into real readable source files (another brick wall)... PCS has missed the community boat completely.

Disclaimer: None of my customers still want Windows client applications. It all are either Windows Server Side Services (black boxes), full (responsive) web applications and web services. You won't here me complain about WD if you are in the 'Windows Forms' or 'Windows Services' type of development. In that case it remains a valid platform. It's just something that will be harder and harder to sell however. WB is imho a no-go. We're currently decommissioning all our WB applications (started with WB12 unto WB21) after a rewrite in another technology.

If you want more examples of some of my encountered brick walls, I'll be happy to give you some...

Cheers,

Peter
Posté le 05 août 2017 - 19:25
Hi Peter,

I just have to underscore what Fabrice is saying. In the last 15 years we wrote quite a lot of very complex WINDEV applications and always could rely on WLanguage and API calls. We even solved some of your unsolvable riddles (the Web Service thing and some of the problems with dbgxxx functions). Admitted, we've had our problems and we had to look into the source code of solutions in VB, VB.NET .. in order to get a clue about how to solve our specific problem. However, there is our POS solution which displays 300+ buttons in the blink of a second - with WLanguage and API calls and many other feats .. we never ever used ActiveX or other third party components. We know the horrors of "composing" applications from third party bits and pieces and finding problems and getting them solved (mostly never).

And no, the cross-platform claim is not to be taken for serious. Even a beginner can find out easily that Groupware, repositionable notes and many other functions and gadgets are not cross-platform. In the Help-System PC Soft makes it even easy to identify functions and components which will not run / compile on a certain platform.

Web applications. While web applications by no way are the #1 in our business model, there is always the possibility to write a WINDEV / Java program doing the job. However, what's more in demand are mobile applications.
Posté le 07 août 2017 - 16:02
Quote
Tor-Bjarne



I had for each in Progress 4gl years ago and liked it, was actually my first posting on the Clarion forum some odd 20 years ago "Where is the for each" :D
And Russ Eggan said "If it's not there, you don't need it!" :D
Posté le 07 août 2017 - 19:56
Quote
Art Bonds

And Russ Eggan said "If it's not there, you don't need it!"

Yup, that was more or less the case :)

And in WinDev I can use "for each" in so many different areas table-browses, arrays, strings and so forth, Now I actually want a keyboard with a [for each] button :D

Cheers
Tor-Bjarne