Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 8 Jahren, 1 Monat
Letzter Beitrag:
vor 8 Jahren, 1 Monat
Beteiligte Autoren:
Jimbo, Piet van Zanten, christoph, Joel, Jeff Graham

WB12 - HReadSeekFirst issue

Startbeitrag von Joel am 06.08.2009 19:31

Hi -

This code is supposed to boot you out if you try to put the same RankGroup name in twice (into field EDT_RankGroupName) I KNOW that the name I am trying to put in is not in the database - I have checked using HFCC, but the code keeps telling me that the name is there, and boots me out giving me the "Info" message in fact, in there. Ideas?

//Test if Creating a new group name or using a current one...
IF Lst_rankGroupNames..Visible = False THEN //Creating a new Group Name
//Validate Fields
IF EDT_NewGrpName = "" THEN
Info("You must enter a New Group Name.", + CR + "For example -", + CR + "Adult Karate or Junior Karate")
RETURN
END
IF EDT_RankGrpDescription = "" THEN
Info("You must enter a Group Description.", + CR + " For example -", + CR + "Standard Martial Art Ranking system")
RETURN
END
//Check if Group Name already exist
HReadSeekFirst(HFRankGroups,sGroupName,EDT_NewGrpName)
WHILE NOT HOut(HFRankGroups)
HCancelSeek(HFRankGroups)
Info("Group Name already exists. You cannot add the same Group name twice")
Reset() //Clear Form
RETURN //go back and put in another Group name
END


I don't think that I need it, but I put in the HCancelSeek to try to solve the problem - it didn't do anything. I have four entries in that table now - I'm sure I am trying to put in a new name, but the code keeps kicking me out. ??

Antworten:

Why do you have a "WHILE HOut"?

I would think that

IF HFound(HFRankGroups) THEN

would be what you want. Even if you find the group or not, HOut can still be True.

See the Notes section of HReadSeekFirst for a valuable table of HFound and HOut values in various cases.

Jeff

von Jeff Graham - am 06.08.2009 20:15
Hi Joel,

checking for duplicates is done before saving a *new record* or a *modified record*. In RAD11 it's done in RADSave() before doing the ScreenToFile() thing.

The shown code is intentionally made to be simple to read, one can compress it by merging the "Creation" and the "Modif" part, but here you can see how it's done:


PROCEDURE RADSave()
// Function called when clicking the 'OK' button
// Returns 'True' if the record is validated, 'False' otherwise

// Validation
IF KGR_NUM < 1 OR KGR_NUM > 9999 THEN
Error("Die KundenGruppen-Nummer muß im Bereich 1 - 9999 liegen!")
ReturnToCapture(KGR_NUM)
END

IF Left(WindowMode,8) = "Creation" THEN
Ergebnisint = HSavePosition(KUGRUPPE)
HReadSeek(KUGRUPPE,KGR_NUM,KGR_NUM,hIdentical)
IF HFound(KUGRUPPE) AND KUGRUPPE.KGR_NUM = KGR_NUM THEN
Error("Die KundenGruppen-Nummer "+KGR_NUM+" wurde schon für "+KUGRUPPE.KGR_BEZ+" vergeben!")
IF Ergebnisint > 0 THEN HRestorePosition(Ergebnisint)
ReturnToCapture(KGR_NUM)
ELSE
IF Ergebnisint > 0 THEN HRestorePosition(Ergebnisint)
END
END

IF (Left(WindowMode,5) = "Modif" OR Left(WindowMode,6) = "Browse" OR Left(WindowMode,12)="LinkedBrowse") AND KGR_NUM OLD_KGR_NUM THEN
Ergebnisint = HSavePosition(KUGRUPPE)
HReadSeek(KUGRUPPE,KGR_NUM,KGR_NUM,hIdentical)
IF HFound(KUGRUPPE) AND KUGRUPPE.KGR_NUM = KGR_NUM THEN
Error("Die KundenGruppen-Nummer "+KGR_NUM+" wurde schon für "+KUGRUPPE.KGR_BEZ+" vergeben!")
IF Ergebnisint > 0 THEN HRestorePosition(Ergebnisint)
KGR_NUM = OLD_KGR_NUM
ReturnToCapture(KGR_NUM)
ELSE
IF Ergebnisint > 0 THEN HRestorePosition(Ergebnisint)
END
END

IF NoSpace(KGR_BEZ) = "" THEN
Error("Sie müssen eine Bezeichnung der KundenGruppe eingeben!")
ReturnToCapture(KGR_BEZ)
END

// Transfer controls to file buffer
ScreenToFile()

// The record is valid
RESULT True



Comment:
KUGRUPPE - file = Customer Group File, it consists of tree fields
KGR_NUM is an unsigned integer 1 - 9999
KGR_BEZ is a text description of KGR_NUM
KGR_NUMBEZ is a text for all combos, merging KGR_NUM and KGR_BEZ, merge is automatically done in a procedure started by a Trigger on each HAdd() & HModify()

other variables:
Ergebnisint is a signed 4-byte integer that takes the current position in the file. Basically not needed in the "Creation" part, but badly needed in "Modif"
OLD_KGR_NUM is set in RADDisplay() = KUGRUPPE.KGR (on Creation = 0, on Modif = the original customer group's name)

Any questions? Just post them!

Guenter


von Jimbo - am 07.08.2009 05:46
Hi Joel,

IF HReadSeekFirst(...) THEN
// exist
ELSE
// not exist
END

Christoph


von christoph - am 07.08.2009 06:36
Hi,

You can even use hSeekFirst, which does only a search and leaves the file buffer untouched.

Reagrds,
Piet

von Piet van Zanten - am 07.08.2009 08:07
Quote
christoph
Hi Joel,

IF HReadSeekFirst(...) THEN
// exist
ELSE
// not exist
END

Christoph


No Christoph, you cannot do this one! In case of a modification of another record, you would change the file pointer's position which possibly ends up with modifying the wrong record.
Guenter

von Jimbo - am 07.08.2009 11:13
Quote
Piet van Zanten
Hi,

You can even use hSeekFirst, which does only a search and leaves the file buffer untouched.

Reagrds,
Piet


Hi Piet, yes, HSeekFirst() does the job on simple key values because it does not change the file pointer. No HSavePosition(..) / HRestorePosition(..) required. However, I've seen some strange behaviour of HSeekFirst() in some very special cases (first access to the file in application) and sent a case description to Tech Support some months ago. If values within the record buffer have to be checked too, the HReadSeek(..) is unavoidable. As shown in my code snippet, the HSavePosition(..) / HRestorePosition(..) commands will do the job. And HReadSeekFirst(..) will not fail on a first access to the file.
Kind regards, Guenter

von Jimbo - am 07.08.2009 11:22
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.