Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5848057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:48:22+00:00 2026-05-22T12:48:22+00:00

I get the error Error: Operator is not overloaded on line 7. Do I

  • 0

I get the error Error: Operator is not overloaded on line 7. Do I have to do a another repeat and can’t use the and operator?

Function GetValidPlayerName : String;
  Var
    PlayerName : String;
  Begin
    Repeat
      Readln(PlayerName);
      If PlayerName = '' And Length(PlayerName) > 10
        Then Write('That was not a valid name.  Please try again: ');
    Until PlayerName <> '';
    GetValidPlayerName := PlayerName;
  End;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:48:23+00:00Added an answer on May 22, 2026 at 12:48 pm

    First, you need to write

    If (PlayerName = '') And (Length(PlayerName) > 10) Then
    

    The parentheses are required.

    Secondly, this will always evaluate to false, because there is no string that is both empty and has length 11 or more. Indeed, a string is empty if and only if its length is zero, so basically you say “if the length is zero and the length is 11 or more, then…”.

    Most likely you wish instead to use a disjunction, that is, to use or instead of and:

    If (PlayerName = '') Or (Length(PlayerName) > 10) Then
    

    This will display the error message if the name is empty or if it is too long.

    In addition, the loop will exit even if the name is invalid, because if PlayerName is equal to ThisIsATooLongName then indeed PlayerName <> ''.

    What you need is something like

    Function GetValidPlayerName : String;
    Var
      PlayerName : String;
    Begin
      Repeat
        Readln(PlayerName);
        If (PlayerName = '') Or (Length(PlayerName) > 10) Then
        Begin
          Write('That was not a valid name.  Please try again: ');
          PlayerName := '';
        End;
      Until PlayerName <> '';
      GetValidPlayerName := PlayerName;
    End;
    

    or

    Function GetValidPlayerName : String;
    Var
      PlayerName : String;
    Begin
      result := '';
      Repeat
        Readln(PlayerName);
        If (PlayerName = '') Or (Length(PlayerName) > 10) Then
          Write('That was not a valid name.  Please try again: ')
        Else
          result := PlayerName;
      Until result <> '';
    End;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: var ExtString: string; const Extensions : array[0..4] of string =
Can i get the source code for a WAMP stack installer somewhere? Any help
I need to solve the following question which i can't get to work by
I'm getting an error here that says I haven't defined a method, but it
I have a new web app that is packaged as a WAR as part
I would like to get a sum from a column, with and without a
I want to get the header of a selected tab-item of a tab-control and
I tried to create a container for posible metadata that can be attached to
I'm trying to create delegates to access any Property Get & Set methods. I
Why I cannot cout string like this: string text ; text = WordList[i].substr(0,20) ;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.