home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap15 / pchar1 / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.6 KB  |  120 lines

  1. {$A+,B-,D+,F-,G+,I+,K+,L+,N-,P+,Q-,R-,S+,T-,V+,W-,X+,Y+}
  2. {$M 16384,8192}
  3. unit Main;
  4.  
  5. { Program copyright (c) 1995 by Charles Calvert }
  6. { Project Name: PCHAR1 }
  7.  
  8. { This program demonstrates how to use PCHARS, arrays
  9.   of Char, and some of the built-in Delphi functions
  10.   used to manipulate variables of these types.
  11.  
  12.   If you want to embed the current compiler options in
  13.   your code, as shown above, press Ctrl + O + O. }
  14.  
  15.  
  16. interface
  17.  
  18. uses 
  19.   WinTypes, WinProcs, Classes, 
  20.   Graphics, Forms, Controls,
  21.   StdCtrls, Dialogs;
  22.  
  23. type
  24.   TForm1 = class(TForm)
  25.     BSizeOf: TButton;
  26.     BStrLen: TButton;
  27.     Edit1: TEdit;
  28.     BStrCatErr: TButton;
  29.     StrCatOk: TButton;
  30.     BStrNew: TButton;
  31.     BStrPCopy: TButton;
  32.     procedure BSizeOfClick(Sender: TObject);
  33.     procedure BStrLenClick(Sender: TObject);
  34.     procedure BStrCatErrClick(Sender: TObject);
  35.     procedure StrCatOkClick(Sender: TObject);
  36.     procedure BStrNewClick(Sender: TObject);
  37.     procedure BStrPCopyClick(Sender: TObject);
  38.   private
  39.     { Private declarations }
  40.   public
  41.     { Public declarations }
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48.  
  49. uses
  50.   SysUtils,
  51.   StrBox;
  52.  
  53. {$R *.DFM}
  54.  
  55. { CR is defined in STRBOX as #13#10, which is a
  56.   carriage return line feed pair. }
  57. procedure TForm1.BSizeOfClick(Sender: TObject);
  58. var
  59.   S: string[255];
  60.   s1: array[0..30] of Char;
  61.   Temp: string;
  62. begin
  63.   Temp := 'SizeOf Data' + CR +
  64.           'string[255] = ' + IntToStr(SizeOf(S)) + CR +
  65.           'array[0..30] of char = ' + IntToStr(SizeOf(S1));
  66.   MessageDlg(Temp, mtInformation, [mbOk], 0);
  67. end;
  68.  
  69. procedure TForm1.BStrLenClick(Sender: TObject);
  70. var
  71.   MyString: array[0..100] of Char;
  72. begin
  73.   StrCopy(MyString, 'Null terminated strings');
  74.   Edit1.Text := IntToStr(StrLen(MyString));
  75. end;
  76.  
  77. procedure TForm1.BStrCatErrClick(Sender: TObject);
  78. var
  79.   S1, S2: array[0..100] of Char;
  80.  
  81. begin
  82.   StrCat(S1, 'Hello');
  83.   StrCat(S2, ', gentle reader');
  84.   StrCat(S1, S2);
  85.   Edit1.Text := S1;
  86. end;
  87.  
  88.  
  89. procedure TForm1.StrCatOkClick(Sender: TObject);
  90. var
  91.   S1, S2: array[0..100] of Char;
  92.  
  93. begin
  94.   StrCopy(S1, 'Hello');
  95.   StrCopy(S2, ', gentle reader');
  96.   StrCat(S1, S2);
  97.   Edit1.Text := S1;
  98. end;
  99.  
  100. procedure TForm1.BStrNewClick(Sender: TObject);
  101. var
  102.   S1: PChar;
  103. begin
  104.   S1 := StrNew('Hello');
  105.   Edit1.Text := StrPas(S1) + ' Length: ' + IntToStr(StrLen(S1));
  106.   StrDispose(S1);
  107. end;
  108.  
  109. procedure TForm1.BStrPCopyClick(Sender: TObject);
  110. var
  111.   S1: String;
  112.   S2: array[0..100] of Char;
  113. begin
  114.   S1 := 'Confront the difficult while it is still easy';
  115.   StrPCopy(S2, S1);
  116.   Edit1.Text := StrPas(S2);
  117. end;
  118.  
  119. end.
  120.