Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 1 Jahr, 11 Monaten
Letzter Beitrag:
vor 1 Jahr, 11 Monaten
Beteiligte Autoren:
Hugo Tessaro, Peter Holemans, Fabrice Harari, Mark Crichton

[WD19] How to change key value of data file?

Startbeitrag von Hugo Tessaro am 10.08.2016 23:07


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)
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)

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


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

von Peter Holemans - am 11.08.2016 07:53
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.

von Mark Crichton - am 11.08.2016 12:29
Hi everybody

2 other solutions:

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

Best regards

von Fabrice Harari - am 11.08.2016 13:09
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?file_id=91


Peter Holemans

von Peter Holemans - am 11.08.2016 13:32
Thanks you all for the replies!

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


von Hugo Tessaro - am 11.08.2016 13:54
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.