Recent

Author Topic: Case statements  (Read 1845 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Case statements
« on: February 05, 2018, 06:18:40 am »
Code: Pascal  [Select][+][-]
  1. CASE I of
  2.     1 : ShowMessage( inttostr(i) + ' ' + S);
  3.     2 : ShowMessage( inttostr(i) + ' ' + S);
  4.     3 : ShowMessage( inttostr(i) + ' ' + S);
  5.     4 : ShowMessage( inttostr(i) + ' ' + S);
  6.     5 : ShowMessage( inttostr(i) + ' ' + S);
  7.     6 : ShowMessage( inttostr(i) + ' ' + S);
  8.     7 : ShowMessage( inttostr(i) + ' ' + S);
  9.     8 : ShowMessage( inttostr(i) + ' ' + S);
  10.     9 : ShowMessage( inttostr(i) + ' ' + S);
  11.     10 : ShowMessage( inttostr(i) + ' ' + S);
  12.     11 : ShowMessage( inttostr(i) + ' ' + S);
  13.     12 : ShowMessage( inttostr(i) + ' ' + S);
  14.     13: ShowMessage( inttostr(i) + ' ' + S);
  15.     14: ShowMessage( inttostr(i) + ' ' + S);
  16.  
  17.    Else
  18.      ShowMessage( inttostr(i) + ' ' + S);    
  19.  
  20. Example #2
  21.  
  22. CASE I of
  23.     1 : SetRecord;
  24.          Edit.Text1 := S;
  25.      .
  26.      .
  27.      .    
  28.    
  29.    Else
  30.      ShowMessage( inttostr(i) + ' ' + S);    
  31.  
  32.  
  33.  
  34.  
  35.  

How do I execute multiple statement like in Example 2.
It gives me an error.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Case statements
« Reply #1 on: February 05, 2018, 06:28:49 am »
Code: Pascal  [Select][+][-]
  1. CASE I of
  2.     1 : ShowMessage( inttostr(i) + ' ' + S);
  3.     2 : ShowMessage( inttostr(i) + ' ' + S);
  4.     3 : ShowMessage( inttostr(i) + ' ' + S);
  5.     4 : ShowMessage( inttostr(i) + ' ' + S);
  6.     5 : ShowMessage( inttostr(i) + ' ' + S);
  7.     6 : ShowMessage( inttostr(i) + ' ' + S);
  8.     7 : ShowMessage( inttostr(i) + ' ' + S);
  9.     8 : ShowMessage( inttostr(i) + ' ' + S);
  10.     9 : ShowMessage( inttostr(i) + ' ' + S);
  11.     10 : ShowMessage( inttostr(i) + ' ' + S);
  12.     11 : ShowMessage( inttostr(i) + ' ' + S);
  13.     12 : ShowMessage( inttostr(i) + ' ' + S);
  14.     13: ShowMessage( inttostr(i) + ' ' + S);
  15.     14: ShowMessage( inttostr(i) + ' ' + S);
  16.  
  17.    Else
  18.      ShowMessage( inttostr(i) + ' ' + S);    
  19.  
  20. Example #2
  21.  
  22. CASE I of
  23.     1 : SetRecord;
  24.          Edit.Text1 := S;
  25.      .
  26.      .
  27.      .    
  28.    
  29.    Else
  30.      ShowMessage( inttostr(i) + ' ' + S);    
  31.  
  32.  
  33.  
  34.  
  35.  

How do I execute multiple statement like in Example 2.
It gives me an error.
You enclose the statement in to begin end eg
Code: Pascal  [Select][+][-]
  1.  
  2. CASE I of
  3.     1 : begin
  4.            SetRecord;
  5.            Edit.Text1 := S;
  6.            S := inttostr(i)+ ' ' + S;
  7.            ShowMessage(S);
  8.          end;
  9.    Else
  10.      begin
  11.         S := inttostr(i)+ ' ' + S;
  12.         ShowMessage(S);
  13.      end;
  14.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Case statements
« Reply #2 on: February 05, 2018, 06:37:04 am »
Thanks;

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018