Difference between revisions of "PChar"

From Free Pascal wiki
Jump to navigationJump to search
m
m (Fixed syntax highlighting; removed categories included in template)
Line 1: Line 1:
 +
 
{{Pchar}}
 
{{Pchar}}
 +
 +
 +
Back to [[Data type|data types]].
 +
  
 
A '''PChar''' is [[Data type]] and a [[Pointer]] to a null-terminated string. The most important application of a PChar is interaction with system libraries like dll's.   
 
A '''PChar''' is [[Data type]] and a [[Pointer]] to a null-terminated string. The most important application of a PChar is interaction with system libraries like dll's.   
  
 
Messagebox:
 
Messagebox:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
var  
 
var  
 
   s: String;
 
   s: String;
Line 14: Line 20:
  
 
Declaration:
 
Declaration:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
var  
 
var  
 
   p: PChar;  
 
   p: PChar;  
Line 20: Line 27:
  
 
Valid assignments:
 
Valid assignments:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
   p := 'This is a null-terminated string.';
 
   p := 'This is a null-terminated string.';
 
   p := IntToStr(45);
 
   p := IntToStr(45);
Line 26: Line 34:
  
 
Invalid assignments:
 
Invalid assignments:
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
   p := 45;
 
   p := 45;
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
The integer value is not casted to a PChar as might be expected.
 
The integer value is not casted to a PChar as might be expected.
  
 
== See also ==
 
== See also ==
 
* [[Character and string types]]
 
* [[Character and string types]]
 
[[Category:Data types]]
 

Revision as of 08:00, 23 February 2020

Template:Pchar


Back to data types.


A PChar is Data type and a Pointer to a null-terminated string. The most important application of a PChar is interaction with system libraries like dll's.

Messagebox:

var 
  s: String;
begin
  s := 'Test';
  Application.MessageBox( PChar(s)),'Title', MB_OK );
end;

Declaration:

var 
  p: PChar;

Valid assignments:

   p := 'This is a null-terminated string.';
   p := IntToStr(45);

Invalid assignments:

   p := 45;

The integer value is not casted to a PChar as might be expected.

See also