Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The aim of the code below is to find and open a loan record and a member record. Since I'm creating a library system where the user does not have a card with a barcode, they have to remember the Unique ID so i thought it would be easier if they only have to remember one number that is the Unique ID to all their relevant records. However the code below has an error in that the function returns IsValid as false when both records exist. Help?

Delphi
procedure RecordCheck(var MemberID: integer);
var
  IsValid: boolean;
  { Procedure to check that Records exist }

  function ValidateID(Member_ID: integer): boolean;
  var
    Error: boolean; { True/False- false until there is an error }
    Count: integer; { For each letter and number }
 begin
    Error := false;
    AssignFile(MemberDetailsFile, 'MemberDetails.dat');
    Reset(MemberDetailsFile);
    while not eof(MemberDetailsFile) do
    begin
      read(MemberDetailsFile, MemberRecords);
      if  Member_ID = MemberRecords.UniqueId then
      begin
        { if match/record found }
        Error := false;
        end
        else
        Error := true
      end;
    begin
      AssignFile(LoanFile, 'LoanFile.dat');
      Reset(LoanFile);
      while not eof(LoanFile) do
      begin
        read(LoanFile, LoanRecords);
        if not Member_ID = LoanRecords.LoanUniqueId  then
        begin
          Error := true
        end
        else
          result := not Error;
      end; { of Check }
    end;
  end;

begin
  IsValid := ValidateID(MemberID);
  if IsValid = false then
    if MessageDlg('The Member ID or loan record does not exist! Try again?',
      mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
    begin
      { if user chooses not to try again }
      frmLoanProductsIDConfirm.Close;
      frmIssue.Show;
      exit;
    end
    else
    begin
      { if user chooses to try again }
      frmLoanProductsIDConfirm.Show;
      frmIssue.Hide;
    end;
  if IsValid = true then
    frmIssueProd.Show;
    frmIssue.Close;
    frmLoanProductsIDConfirm.Close;
end;
Posted
Updated 30-Dec-13 8:56am
v3

1 solution

Well, it would probably help is you ever assigned Error to something other than false...
These are every time you reference the variable:
SQL
Error: boolean; { True/False- false until there is an error }
    Error := false;
        Error := false;
          Error := false
          result := not Error;
So result will always be true.
 
Share this answer
 
Comments
Member 10495202 30-Dec-13 14:15pm    
i think theres something wrong with the begins and ends
OriginalGriff 30-Dec-13 14:36pm    
Well you probably want to set it true at some point - at the moment it only ever gets a false! :laugh:
Why do you think it's the begin...end pairs? What happens when you debug it?
Member 10495202 30-Dec-13 15:03pm    
sorry ignore last comment
i listened to your advice but not i have a stack overflow message?
ive changed the code in the comment to the current one where the error occurs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900