* * *

Author Topic: Case statements  (Read 675 times)

JLWest

  • Full Member
  • ***
  • Posts: 192
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.
JLWEST 
 FPC 3.0.4, Lazarus IDE v1.8.2 Windows 10 Pro
 Intel i7 770K CPU 4.2GHz 16 Gig Ram
GeForce GTX 1080 Graphics - 8 Gig 1.5 Terabyte SSD

taazz

  • Hero Member
  • *****
  • Posts: 5336
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

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

JLWEST 
 FPC 3.0.4, Lazarus IDE v1.8.2 Windows 10 Pro
 Intel i7 770K CPU 4.2GHz 16 Gig Ram
GeForce GTX 1080 Graphics - 8 Gig 1.5 Terabyte SSD

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus