Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key generator
Message
De
05/01/2000 10:19:01
 
 
À
04/01/2000 19:50:29
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00312803
Message ID:
00313189
Vues:
36
>>
>>I recommend the structure changed to cTableName, nKeyValue
>>
>
>Yeah, I was expecting this since I've seen that approach discussed here at length.
>
>But I'm not sure that would solve my problem. Maybe if I SKIP to the next record, that would do it. But then I can do that with the existing structure... Hmmm... I'll give that a try.
>
>Thanks for the feedback


Do you store the result of the function call into a variable? Is the variable in the caller named the same as any variable you use in the subroutine? If so you can have a subsequent call to the function corrupt the variable in the caller by writing the new value to it. Declare the variables in the subroutine as local. The following code implements many of the recomendations that you have been given:
set exclusive off
set reprocess to 300

if !file("system.dbf")
	create table system free (cTableName c(254), nKeyValue i)
	insert into system (cTableName, nKeyValue);
		values (padr(upper(alltrim("TEST")), len(cTableName), "*"), 0)
	use
endif

if !file("results.dbf")
	create table results free (cKeyValue i)
	index on cKeyValue tag cKeyValue candidate
	use
endif

set escape on
do while .t.
	insert into results (cKeyValue) values (GetKeyValue("TEST"))
enddo

*-------------------------------------------------
function GetKeyValue

lparameters tcTableName, tnFieldLength
local lcOldAlias, llTableUsed, llDone, lnReturnValue, lnBufferMode

lcOldAlias = alias()
llTableUsed = used("System")

if llTableUsed
	select system
	lnBufferMode = cursorgetprop("Buffering")
	cursorsetprop("Buffering", 1)
else
	select 0
	use system
endif

llDone = .f.
locate for cTableName == padr(upper(alltrim(tcTableName)), len(cTableName), "*")

if !found()
	error "No key record for Table:  '" + tcTableName + "'."
endif

do while !llDone
	if rlock()
		replace nKeyValue with nKeyValue + 1
		lnReturnValue = nKeyValue
		unlock
		llDone = .t.
	endif
enddo

if !empty(lcOldAlias)
	select (lcOldAlias)
endif

if llTableUsed
	cursorsetprop("Buffering", lnBufferMode)
else
	use in system
endif

return lnReturnValue
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform