Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FLUSH command did not work
Message
De
08/12/2011 18:50:23
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01530590
Message ID:
01530687
Vues:
53
Hi Dionísio.

Flush would make no difference here as the Flush writes changes to disk, it does not affect your reading of them.

Set refresh controls when it reads the record form disk, but only when a possible read is triggered. That's why doing a GoTo reads that data. If it was to read the data from disk every time you accessed a field in the record then lines of code line
lcName = Title +" "+ GivenName +" "+ OtherNames +" "+ LastName
would wind up accessing the disk 4 times, which would make the speed abysmal.

Finally, this code isn't really correct became it has no record locking. If I remember my Clipper properly, this code will have the same problem there too. Before checking the flag you should RLock() the record. This makes sure that not only do you have the version of the record that it on disk, regardless of the Set Refresh setting, but also prevents anyone else from locking the record. As this code stands now it's possible for two copies running at once to both see that the flag is not set and then try to set it. Don't forget to unlock the record when you are done updating it.

One other thing about this method though, if the program that sets the flag crashes then it will never turn the flag off, leaving no program ever able to take control again. If, as you are here, you are only using the record to indicate if a particular copy of the program has control of a particular operation, What I have found to be good is to just use the RLock as the flag. If the code and Lock the record then no one else has the lock so it can proceed. When it's finished it just unlocks the record. This has the advantages that it takes less checking, and if the program crashes and shuts down Windows will automatically release the lock for you, allowing other copies of the program to continue operating.

Ian Simcock.






>Hi Friends,
>
>The routine below only worked when I used the command GOTO RECORD RECNO ("Table1"), This is correct?
>
>There's another alternative to SET REFRESH. Before using the SET REFRESH tried to use the FLUSH command but this did not work for me.
>
>I come from the clipper and I'm trying to learn more about the best options to use the VFP
>
>Thanks in advance,
>
>Dionísio
>
>
>* THE TABLE table1 HAS ONLY THE FIELD flag, NO INDEX AND NO DATA BUFFERING
>
>SET REFRESH TO 0,-1
>
>USE Table1 SHARED 
>
>DO WHILE .t.
>
>     GOTO RECORD RECNO("Table1")
>
>     IF Table1->flag
>
>        IF MESSAGEBOX("Routine is being used by another user",5)=2
>            EXIT	   	  	
>        ELSE
>            LOOP 
>        ENDIF
>	   
>     ELSE
>
>        * Flag to warn that the routine is being used
>        REPLACE Table1->flag WITH .T.
>
>        IF MESSAGEBOX("Routine is being used by me",1)=2
>            EXIT
>        ENDIF
>		
>        * Routine no longer being used by any users
>        REPLACE Table1->flag WITH .F.
>
>        IF MESSAGEBOX("Routine no longer being used",1)=2
>            EXIT 
>        ENDIF
>
>    ENDIF
>
>ENDDO
>
>REPLACE Table1->flag WITH .F.
>USE
>
>SET REFRESH TO 0,5
>
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform