IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Language Det...   Print This     
  From the May 2011 Issue of Prestwood eMag
 
Delphi Language Details:
Using Null Terminated and PChar Strings in Delphi
 
Posted 21 years ago on 3/13/2003 and updated 2/26/2008
Take Away: How to use Delphi's two varieties of string variables: Pascal strings and PChar strings.

KB100131

ObjectPascal has two varieties of string variables: Pascal strings and PChar strings. PChar strings are also known as null terminated strings because the last character in memory is always the null character (ASCII 0).

Using Pascal strings

The first character in memory is used to store the length of the string"¦because this character is an unsigned short integer it is limited to 255 characters; unsigned short integers have a range from 0 to 255.

procedure TForm1.Button3Click(Sender: TObject); 
var
    sPascalType: String[20];
begin
    sPascalType := 'Felina Prestwood';
    ShowMessage(sPascalType);
end;

Using PChar strings

var    s: String;


or

var    s2: PChar;


for example, type the following code into the onClick event of a button.

procedure TForm1.Button4Click(Sender: TObject);
var
    s1: String;
    s2: PChar;
begin
    s1 := 'Felicia Prestwood';
    s2 := 'Felina Prestwood';
    ShowMessage(s1);
    ShowMessage(s2);
end;    
Using the ^ operand
procedure TForm1.Button4Click(Sender: TObject);
var
   s2: PChar;
begin
   s2 := 'Felina Prestwood';
   while s2^ <> #0 do   {#0 is ASCII 0, the null character}
      begin
         ShowMessage(s2^);
         Inc(s2);
      end;
end;

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

The document is a way of education and location for the marks. the turns of the opportunity and https://bestwritingservicecanada.com/topresume-review/ are visited for the anticipation for the rooms. The suggestion is held for the brick paces. Nature is defined for the humble items for humans.

Posted 56 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1116A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100131 Counter
21666
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]