Hello. I began to make the program-registration list for competitions where teams are saved. The program is organized as follows: there is a database, it has a table “General table of participants”, there is a table “Pairs”, there is a table “Table of pairs”. When the participant arrives, he fills in the registration sheet of the program. There he indicates the name, surname, patronymic, telephone number, and name of the team. After clicking the save registration button, first the name, surname, etc. are entered into the table “General table of participants”. If the command does not exist, then in the table “Table of pairs” a line is created with its (registered participant) key (the key is determined using combinations of functions SelectPerson and GetUsual - the code is attached below). the key is stored in the first field of the "pairs table". In the "Pairs" line is created with the field "total number of the pair" and the field "place in the competition." The total number of a pair is determined by the key in the "pairs table". Place in the competition is determined after the competition. If a participant came after the first one, then his key is simply stored in a table in a different field. But when I wrote the code for the program, I discovered that when the command is saved in "Paras", only an empty string is created, and the value "common number of the pair" remains empty. Tell me - what's the problem? Thanks in advance. SelectPerson Code:

function TFRegistrationForm.SelectPerson(phone:string):boolean; var NoErrors:boolean; begin NoErrors:=true; try NoErrors:=DBComponents.TAll.Locate('Телефон', phone, []); except NoErrors:=false; end; Result:=NoErrors; end; 

GetUsual Code:

 function TFRegistrationForm.GetUsual:integer; begin Result:=DBComponents.TAll.FieldByName('Код').Value; end; 

The code of the function with which I select the desired string of pairs:

  function TFRegistrationForm.SelectPair(PairName:string):boolean; begin Result:=DBComponents.TPairTable.Locate('Название пары', PairName, []); end; 

Function code for sending "pairs" to database:

 procedure TFregistrationForm.PostPairTable; begin DBComponents.TPairTable.Edit; DBComponents.TPairTable.Post; end; 

The code for the function to send the "pairs table" database:

 procedure TFregistrationForm.PostPair; begin DBComponents.TPair.Edit; DBComponents.TPair.Post; end; 

The code of the function with which I am trying to save the changes:

 function TFRegistrationForm.RegisterPair:boolean; var NoError:boolean; IsPair:boolean; begin NoError:=true; with DBComponents.TPairTable do begin try SelectPerson(EPhone.Text); IsPair:=SelectPair(EPairName.Text); if not IsPair then append; Edit; if not IsPair then begin FieldByName('Общий номер 1-ого участника(цы)').Value:=GetUsual; FieldByName('Название пары').Value:=EPairName.Text; DBComponents.TPair.append; DBComponents.TPair.Edit; DBComponents.TPair.FieldByName('Номер пары').Value:=FieldByName('Код').Value; PostPair; end else FieldByName('Общий номер 2-ого участника(цы)').Value:=GetUsual; PostPairTable; PostPair; except NoError:=false; end; end; Result:=NoError; end; 

Maybe I missed some functions. If so, I will edit the topic. Tell me - why the pair number is not saved?

    1 answer 1

    the error is that you make an append and then immediately edit, remove the edit - it is superfluous if you insert lines. edit is needed only if you are editing the current entry. In particular:

     if not IsPair then append else edit; 

    and in other cases, too - either edit or append ...