I want to make a program that would show the text when I pressed the button and hide it when I pressed it again. What is the error?

procedure TForm1.Button1Click(Sender: TObject); if Memo1.Visible then begin Memo1.Visible:=False end else begin Memo1.Visible:=True end. 
  • what specifically does not work? and what does the compiler write? - Alexander Moshnov
  • I am always terribly enraged when they write in the question "does not work." Not compiled due to missing comma? Flies at the start? Does the system crash? In the log does not appear the right letters? Doesn't the window open? The color of the button is blue, and the author wanted red? Telepaths work at a separate rate. - VladD
  • They also like to be interviewed - show the code that was written by someone who knows what herbs and, looking, say “find ten mistakes”. And the code is such that it is not something that will not compile, but the notebook will fall when they enter. - KoVadim

1 answer 1

Let's start with the fact that in this case you can not write extra begin / end:

 if Memo1.Visible then Memo1.Visible:=False else Memo1.Visible:=True; 

Secondly, if you copied the real code, then it should not work because:
1. the procedure is not fenced by its begin / end
2. end with end point

Try this:

 procedure TForm1.Button1Click(Sender: TObject); begin if Memo1.Visible then Memo1.Visible:=False else Memo1.Visible:=True; end; 
  • one
    it is better to write all the runin / endy - Sugar Sugar
  • one
    @ Sugar, between readability and code cluttering is a fine line. In this example, the beguins double the amount of code, they don’t give improved readability, and the logic is clear without them. - teanYCH
  • 9
    I would just write Memo1.Visible: = not Memo1.Visible; And if in this case is a sign of ignorance. - KoVadim