home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D+,F-,G+,I+,K+,L+,N-,P+,Q-,R-,S+,T-,V+,W-,X+,Y+}
- {$M 16384,8192}
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: PCHAR1 }
-
- { This program demonstrates how to use PCHARS, arrays
- of Char, and some of the built-in Delphi functions
- used to manipulate variables of these types.
-
- If you want to embed the current compiler options in
- your code, as shown above, press Ctrl + O + O. }
-
-
- interface
-
- uses
- WinTypes, WinProcs, Classes,
- Graphics, Forms, Controls,
- StdCtrls, Dialogs;
-
- type
- TForm1 = class(TForm)
- BSizeOf: TButton;
- BStrLen: TButton;
- Edit1: TEdit;
- BStrCatErr: TButton;
- StrCatOk: TButton;
- BStrNew: TButton;
- BStrPCopy: TButton;
- procedure BSizeOfClick(Sender: TObject);
- procedure BStrLenClick(Sender: TObject);
- procedure BStrCatErrClick(Sender: TObject);
- procedure StrCatOkClick(Sender: TObject);
- procedure BStrNewClick(Sender: TObject);
- procedure BStrPCopyClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- SysUtils,
- StrBox;
-
- {$R *.DFM}
-
- { CR is defined in STRBOX as #13#10, which is a
- carriage return line feed pair. }
- procedure TForm1.BSizeOfClick(Sender: TObject);
- var
- S: string[255];
- s1: array[0..30] of Char;
- Temp: string;
- begin
- Temp := 'SizeOf Data' + CR +
- 'string[255] = ' + IntToStr(SizeOf(S)) + CR +
- 'array[0..30] of char = ' + IntToStr(SizeOf(S1));
- MessageDlg(Temp, mtInformation, [mbOk], 0);
- end;
-
- procedure TForm1.BStrLenClick(Sender: TObject);
- var
- MyString: array[0..100] of Char;
- begin
- StrCopy(MyString, 'Null terminated strings');
- Edit1.Text := IntToStr(StrLen(MyString));
- end;
-
- procedure TForm1.BStrCatErrClick(Sender: TObject);
- var
- S1, S2: array[0..100] of Char;
-
- begin
- StrCat(S1, 'Hello');
- StrCat(S2, ', gentle reader');
- StrCat(S1, S2);
- Edit1.Text := S1;
- end;
-
-
- procedure TForm1.StrCatOkClick(Sender: TObject);
- var
- S1, S2: array[0..100] of Char;
-
- begin
- StrCopy(S1, 'Hello');
- StrCopy(S2, ', gentle reader');
- StrCat(S1, S2);
- Edit1.Text := S1;
- end;
-
- procedure TForm1.BStrNewClick(Sender: TObject);
- var
- S1: PChar;
- begin
- S1 := StrNew('Hello');
- Edit1.Text := StrPas(S1) + ' Length: ' + IntToStr(StrLen(S1));
- StrDispose(S1);
- end;
-
- procedure TForm1.BStrPCopyClick(Sender: TObject);
- var
- S1: String;
- S2: array[0..100] of Char;
- begin
- S1 := 'Confront the difficult while it is still easy';
- StrPCopy(S2, S1);
- Edit1.Text := StrPas(S2);
- end;
-
- end.
-