home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
chap14
/
easystr
/
main.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-03-20
|
2KB
|
82 lines
unit Main;
{ Program copyright (c) 1995 by Charles Calvert }
{ Project Name: EASYSTR }
{ This programs demonstrates some basic facts
about the way strings are structured. In particular,
it gives you a look at the length byte, which is the
zeroth element in all Pascal based strings. The length
byte determines the length of a string. If the
length byte is too large, then garbage characters can
appear in your strings.
}
interface
uses
SysUtils, WinTypes, WinProcs,
Messages, Classes, Graphics,
Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TEasyString = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Valid: TButton;
Bad: TButton;
procedure BValidClick(Sender: TObject);
procedure BBadClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
EasyString: TEasyString;
implementation
{$R *.DFM}
procedure ScrambleString(var S: String);
var
i: Integer;
begin
for i := 0 to 255 do
S[i] := Chr(Random(255));
end;
procedure TEasyString.BValidClick(Sender: TObject);
var
S: String;
begin
ScrambleString(S);
S[0] := #5;
S[1] := 'H';
S[2] := 'e';
S[3] := 'l';
S[4] := 'l';
S[5] := 'o';
Label1.Caption := S;
end;
procedure TEasyString.BBadClick(Sender: TObject);
var
S: string;
begin
ScrambleString(S);
S[0] := #150;
S[1] := 'H';
S[2] := 'e';
S[3] := 'l';
S[4] := 'l';
S[5] := 'o';
Label1.Caption := S;
end;
end.