Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 4 Jahren, 7 Monaten
Letzter Beitrag:
vor 4 Jahren, 7 Monaten
Beteiligte Autoren:
Giu, Jose Antonio Garrido, Piet van Zanten, Al, Arie, GuenterP, Thomas Brauner

Variable loosing it's value?

Startbeitrag von Giu am 30.05.2013 16:47

Hi all,

I have this procedure:

PROCEDURE CerrarMesa(nNumeroMesa is int)

AparcarMesa()

IF HReadSeekFirst(MesasAbiertas,NumMesa,nNumeroMesa) THEN
HDelete(MesasAbiertas,hCurrentRecNum)
END


With a breakpoint in AparcarMesa() line, nNumeroMesa value is 2 for example...
AparcarMesa() pass, and has this code:


PROCEDURE AparcarMesa()
STC_LABEL = ""
gnMesaAbierta = 0


and Debugger is now in HReadSeekFirst line, ok? well...nNumMesa value is now 0.

Somebody knows how can be possible this?

Antworten:

Hi Giu,

actually, what you're doing in the procedure is:

Find a certain record of a file -> file pointer is set to that record
if the record is found then delete exactly this record -> file pointer value is meaningless now.

von GuenterP - am 30.05.2013 16:55
Probably I don't explained correctly

At Breakpoint, nNumeroMesa = 1
[attachment 385 Screenshot-30_05_201318_57_50.jpg]

Press F8, and debugger goes to next line.
[attachment 386 Screenshot-30_05_201318_58_04.jpg]

nNumeroMesa changed his value from 1 to 0, and AparcarMesa() has nothing to do with local variable nNumeroMesa

von Giu - am 30.05.2013 17:00
Hi Giu,

how was the result of hreadseekfirst?
Is nNumeroMesa changing all the time or only, if hreadseekfirst is false?

Maybe the parameter of hreedseekfirst is by reference and is changed inside this function ?!?!

Thomas

von Thomas Brauner - am 30.05.2013 17:15
Quote
Thomas Brauner
Hi Giu,

how was the result of hreadseekfirst?


Should be false, because the value searched is 0, and there are any record with 0 as value.

Quote

Is nNumeroMesa changing all the time or only, if hreadseekfirst is false?


Don't understand. nNumeroMesa is a local variable I pass to this procedure and use in HReadSeekFirst function to search the record I want. The problem is, this variable, loose it's value after AparcarMesa() procedure.

Problem seems to be
gnMesaAbierta = 0

when this sentence is executed, nNumeroMesa variable takes the same value. I tried changin to
gnMesaAbierta = 58
and then, nNumeroMesa changes to 58.

There is an easy solution, but I would like to know why is this happening.

von Giu - am 30.05.2013 17:32
O_O

I have no clue, and I thing that it has no logic.

I would try to create new procedures called "CerrarMesa_2" and AparcarMesa_2, and you write the exact same code, I think that it will works normally.

Regards,

José Antonio.

von Jose Antonio Garrido - am 30.05.2013 17:35
Quote
Jose Antonio Garrido
O_O

I have no clue, and I thing that it has no logic.

I would try to create new procedures called "CerrarMesa_2" and AparcarMesa_2, and you write the exact same code, I think that it will works normally.

Regards,

José Antonio.


Hi José antonio,

If i extract the 2 lines code from aparcarmesa and copy into this "main" procedure , result is the same.

von Giu - am 30.05.2013 18:37
You are passing nNumeroMesa by reference.
Where does this value come from? It sits somewhere in your parent code.
Could it be that AparcarMesa() is changing this "higher level" variable?

von Arie - am 30.05.2013 19:28
So you are statin what I put in bold?:

PROCEDURE CerrarMesa(nNumeroMesa is int)

trace(nNumeroMesa) //Returns 1

STC_LABEL = ""
gnMesaAbierta = 0

trace(nNumeroMesa) //Returns 0

IF HReadSeekFirst(MesasAbiertas,NumMesa,nNumeroMesa) THEN
HDelete(MesasAbiertas,hCurrentRecNum)
END

If that is, then I would try to make the things new. I had some strange problems with code that finally solved creating a new control and pasting the code on the new control (I think it was a button, but I dont remember.) BTW, what version do you have? That happened to me only once time in WD15 or WD16, but not in WD17. The behaviour it was so strange and crazy that it was clear to me that I had to discard that control.

Regards,
José Antonio

von Jose Antonio Garrido - am 31.05.2013 00:51
Hello Giu

If your parameter "nNumeroMesa" is first created outside the procedure then sometimes the debugger may display it incorrectly.

You could try to rename the parameter in the procedure so it is unique to the procedures or make it local to the procedure

PROCEDURE CerrarMesa(nNumeroMesa1 is int)
or
PROCEDURE CerrarMesa(LOCAL nNumeroMesa is int)


I always pass parameters to procedures with default values as this makes them optional and makes the procedures more flexible. It also give me a definite starting value in testing for values passed in or not.

PROCEDURE CerrarMesa(LOCAL nNumeroMesa = 0)


Regards
Al

von Al - am 31.05.2013 02:16
Hi Giu,

Just step through the code using F7 and check where exactly nNumeroMesa changes.

Regards,
Piet

von Piet van Zanten - am 31.05.2013 07:20
As Arie sais, the problem comes to pass the parameter to the procedure by ref.

2 or 3 procedures back, when all starts, I call the first procedure with the global gnMesaAbierta and this parameter is what I'm using to pass to next procedures. For this reason, in last moment, when I modify gnMesaAbierta, I modify the value of nNumeroMesa too.

Passing variable byValue or declaring as LOCAL in procedure declaration as Al suggest, works.

My Fault, I'm accustomed to vars passed by default by value.

Thanks a lot.

von Giu - am 31.05.2013 07:35
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.