1.4Linking controls to data & handling records
The essentials in 30 seconds
- The control ↔ item link is highly productive: ÉcranVersFichier() copies input to the items, FichierVersÉcran() does the reverse for display.
- HFSQL functions (H prefix) handle data: HAjoute, HModifie, HSupprime, HLitPremier/Suivant, HLitRecherche, HRAZ.
- Always test HEnDehors after a read or search: otherwise you work on nonexistent data — or even modify the wrong record.
Running mini-case — Yacine connects his order form to the data
Yacine has drawn his “Fiche commande” window. He now connects it to the data. First he links each control to its item: SAI_NomClient ↔ Client.Nom, SAI_Ville ↔ Client.Ville. Then he writes the management code. To create an order: he calls HRAZ to clear the items, lets the user enter data, then ÉcranVersFichier() copies the input in one go and HAjoute saves it. To search for a customer by code, he uses HLitRecherche then tests HEnDehors: if nothing is found, he displays a clear message instead of using phantom data. Thanks to linked controls, modifying a record takes a few lines. Yacine remembers: linking automates the screen/file exchange, and testing HEnDehors is a mandatory reflex.
Standalone case for this section: it returns in the course, diagram, script and 48h challenge of section 1.4.
1. The control ↔ item link
Here is one of WinDev's most productive mechanisms: the LINK between a window's controls and the analysis items. When a control is linked to an item (SAI_NomClient ↔ Client.Nom), WinDev knows where to take the value from and where to store it.
Two functions then do all the work: ÉcranVersFichier() (copies the screen input to the items, before saving) and FichierVersÉcran() (copies the file values to the controls, for display). No more dozens of manual assignments — and one less source of errors.
2. HFSQL functions
To handle data, WLangage provides the HFSQL functions, all prefixed with H: HAjoute (add), HModifie (update the current record), HSupprime, HLitPremier / HLitDernier / HLitSuivant / HLitPrécédent (move around), HLitRecherche (search on a key) and HRAZ (clear the items in memory before input).
Key notion: the CURRENT RECORD. At any given time, one record is “current” in memory, and it is the one HModifie or HSupprime will affect. Choosing the wrong current record is a classic error.
3. The HEnDehors reflex
After a read or search, HEnDehors indicates whether you are outside the file: nothing found, or end reached. You must always test it before using the result.
The typical cycle of a form is therefore: HRAZ → input → ÉcranVersFichier → HAjoute (or HModifie). Forgetting the HEnDehors test means displaying residual data, or even modifying the wrong record — a silent corruption that must be avoided at all costs.
🔎 Concrete example — 🔎 Concrete example — Saving and searching a record
Yacine's cycle for his order form:
// Créer une nouvelle commande (champs liés)
HRAZ(Commande) // vider les rubriques en mémoire
// ... l'utilisateur saisit dans les champs liés ...
ÉcranVersFichier(Commande) // recopier la saisie vers les rubriques
HAjoute(Commande) // enregistrer le nouvel enregistrement
// Rechercher un client, puis TOUJOURS tester HEnDehors
HLitRecherche(Client, IDClient, 1042)
SI HEnDehors(Client) ALORS
Info("Client introuvable : vérifiez le code.")
SINON
FichierVersÉcran(Client) // afficher la fiche trouvée
FIN
Reading: two calls (ÉcranVersFichier / FichierVersÉcran) replace dozens of assignments; the HEnDehors test protects against an empty search.
Reflex: HEnDehors is tested immediately after the read or search, before any use.
Section vocabulary
- Control linked to an item
- Screen control associated with an item (SAI_NomClient ↔ Client.Nom): WinDev knows how to read and save the value automatically.
Simple example: Yacine links SAI_Ville to Client.Ville in his window.
What it is not: copying each value by hand in the code, control by control.
Reflex: a screen control ↔ an item → link them.
- ÉcranVersFichier / FichierVersÉcran
- The two key functions of linking: ÉcranVersFichier copies input to the items; FichierVersÉcran copies the file values to the controls.
Simple example: Yacine calls ÉcranVersFichier just before HAjoute.
What it is not: manually assigning thirty items and forgetting one.
Reflex: screen ↔ file transfer → these two functions.
- HFSQL functions (H prefix)
- Data handling functions: HAjoute, HModifie, HSupprime, HLitPremier/Suivant/Précédent/Dernier, HLitRecherche, HRAZ.
Simple example: Yacine adds an order with HAjoute and reads it back with HLitRecherche.
What it is not: modifying a record by writing directly into the file.
Reflex: data → functions prefixed with H.
- Current record
- The “current” record in memory: it is the one HModifie or HSupprime will affect.
Simple example: Yacine positions on the right customer before calling HModifie.
What it is not: calling HModifie without positioning on the right record.
Reflex: modify/delete → check the current record.
- HEnDehors (to test)
- Indicates that you are outside the file after a read or search (nothing found, or end reached); to be tested systematically.
Simple example: Yacine displays “Client introuvable” when HEnDehors is true.
What it is not: using the result of a search without testing HEnDehors.
Reflex: after read/search → test HEnDehors.
In practice — In practice — Saving and reading back a record
- LINK the window controls to the corresponding analysis items (SAI_NomClient ↔ Client.Nom) through the control properties.
- For a CREATION: call HRAZ to clear the items, let the user enter data, then ÉcranVersFichier followed by HAjoute.
- For a MODIFICATION: position on the right record (HLitRecherche), display it with FichierVersÉcran, then after input ÉcranVersFichier and HModifie.
- SYSTEMATICALLY TEST HEnDehors after any read or search, before using the result.
Step-by-step script — connecting the form like Yacine (4 min)
1) Link each control to its item (SAI_NomClient ↔ Client.Nom) in the control properties. 2) Creation: HRAZ, user input, ÉcranVersFichier, HAjoute. 3) Modification: HLitRecherche to position, FichierVersÉcran to display, then ÉcranVersFichier and HModifie. 4) After each read or search, test HEnDehors and handle the “not found” case. 5) Deletion: position then HSupprime.
Never chain a write after a search without having tested HEnDehors.
Copy-paste template — Yacine's form cycle
// Création
HRAZ(Fichier)
< saisie de l'utilisateur >
ÉcranVersFichier(Fichier)
HAjoute(Fichier)
// Recherche + contrôle
HLitRecherche(Fichier, Clé, valeur)
SI HEnDehors(Fichier) ALORS
< cas non trouvé >
SINON
FichierVersÉcran(Fichier)
FIN
// Modification / Suppression (enregistrement en cours)
ÉcranVersFichier(Fichier)
HModifie(Fichier) // ou HSupprime(Fichier)
Read-only consultation
Yacine only uses HLitRecherche then FichierVersÉcran to display an order, without saving.
Add from a table
From the orders table, Yacine opens the add form, HRAZ, ÉcranVersFichier, HAjoute, then refreshes the table.
Unsuccessful search
When HEnDehors is true, Yacine offers to create a new customer instead of displaying an empty form.
Manual transfer
For a calculated control (the total incl. tax), Yacine computes the value then assigns it manually, without a linked control.
✓ Best practices
- Link the controls to the items rather than assigning by hand.
- Use ÉcranVersFichier / FichierVersÉcran before saving or displaying.
- Test HEnDehors after any read or search.
✗ Common pitfalls
- Forgetting the HEnDehors test after a search.
- Modifying the wrong record (current record).
- Rewriting dozens of assignments by hand instead of using linked controls.
Key takeaways
- The control ↔ item link is highly productive: ÉcranVersFichier copies input, FichierVersÉcran displays values.
- HFSQL functions (H prefix) handle data: HAjoute, HModifie, HSupprime, HLit…, HLitRecherche, HRAZ.
- The current record is the one HModifie or HSupprime affect: getting it wrong is a classic error.
- Mandatory reflex: test HEnDehors after any read or search before using the result.
48h challenge — apply it tomorrow
Take a file from your analysis and write, like Yacine, the complete cycle of a record: HRAZ → ÉcranVersFichier → HAjoute, then a HLitRecherche search followed by the HEnDehors test. Write in one sentence what happens if you forget to test HEnDehors.
- I know how to link a window's controls to the analysis items.
- I know how to add, search and modify a record with the HFSQL functions.
- I have the reflex of testing HEnDehors after each read or search.
Frequently asked questions
Why must HEnDehors always be tested after a search?
Because a search may find nothing. Without this test, the code continues using residual values in memory — often the last record read — and the application displays wrong data without crashing. Worse: chaining a HModifie after a failed search can modify a record that was not the intended one. So HEnDehors is tested immediately after the read or search, before any use.
What is the difference between linked controls and manual code?
Linked controls automate the screen ↔ file transfer via ÉcranVersFichier / FichierVersÉcran: it is fast, safe and preferred. Manual code (assignments one by one) remains useful for special cases: data transformed for display (calculation, conversion) or unlinked controls (filters, totals, indicators). On a thirty-control form, linked controls save considerable time and prevent many oversights.
How is the data entered in a linked window saved?