PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD19] How to change key value of data file?
[WD19] How to change key value of data file?
Iniciado por guest, 11,ago. 2016 01:07 - 5 respuestas
Publicado el 11,agosto 2016 - 01:07
Hello,

Look at my scenario and what Im trying to do:
I have 2 windows that use a data file ("cfop_table" at my case);
I use HReadSeekFirst(cfop_table,id,522) at window 1;
Then I use HReadSeekFirst(cfop_table,id,514) at window 2;
When I call cfop_table.id at window 1 the Id is that 514 and not 522.

I trying to solve it using variable type Record: _CFOP is Record of cfop_table at declaration of my window 1 and after the HReadSeekFirst(cfop_table,id,522) I assing to variable _CFOP = cfop_table the data file.

But, when I try to modify (using HWrite(cfop_table)):
First I assign the Record variable to data file then I run the HWrite.
I used Trace to check the Id's before and after and its ok, but when I profile the SQL run the Update using the Id of Window 2 (UPDATE `cfop_table` SET `descricao` = 'testtt' WHERE `id`=514 -- Im using Neor Profile SQL).
I already tryied use HReset(cfop_table) before the assign of record variable to data file but the result is the same.

Below is the code and Trace's:

Trace("Trace1@Window 1# "+cfop_table.id,_CFOP.id) HReset(cfop_table) Trace("Trace2@Window 1# "+cfop_table.id,_CFOP.id) cfop_table = _CFOP Trace("Trace3@Window 1# "+cfop_table.id,_CFOP.id) IF HWrite(cfop_table) THEN Trace("Trace4@Window 1# "+cfop_table.id,_CFOP.id) END
Trace's output:

Trace1@Window 2# 522 Trace2@Window 2# 514 Trace1@Window 1# 514 522 Trace2@Window 1# 0 522 Trace3@Window 1# 522 522 Trace4@Window 1# 522 522
Publicado el 11,agosto 2016 - 09:53
Hi Hugo,

In your Window description, make sure the 'Independent HyperFile Context' is flagged. If this is not the case, record context is global to the application so your second read will erase the in memory context of the first read.

If you use independent HyperFile contexts per window this is no longer the case...

This should do the trick!

Peter Holemans
Publicado el 11,agosto 2016 - 14:29
Hi Hugo

I agree with Peter, but if you want to use 1 window then you can't do that.
Option is to use an internal window for the second table.
Better still, use a query for one or both of the tables and use code to update the data file.

Using 2 tables on one form causes headaches if both pointing to same record. Update conflicts will occur.
Publicado el 11,agosto 2016 - 15:32
Hi all,

Or another solution close to Mark's solution: use a separate business layer tier to work with the data like I do in the WX OO framework.
This is the best practice for most future proof development having potentially many front ends but requiring an identical business logic...
See: http://repository.windev.com/resource.awp…

Cheers,

Peter Holemans
Publicado el 11,agosto 2016 - 15:54
Thanks you all for the replies!

I didn't know the option 'Independent HyperFile Context', I tested and works perfect!

Thanks.
Publicado el 11,agosto 2016 - 16:00
Hi everybody

2 other solutions:

1. use halias in your second window
2. use hsaveposition and hrestoreposition when you change windows

Best regards