Mega Code Archive

 
Categories / Delphi / Strings
 

Does delphi use pascal or c style strings

Both. Delphi has two different sets of string manipulation functions, one for null-terminated strings, and one for Pascal-type (I.E. length byte) strings. You will find yourself stumbling across this distinction from time to time. Mostly, there are Delphi functions that wrap around the most common Windows API functions; for example, MessageBox, which is a Windows API call, requires a PChar; but Delphi also has MessageDlg, which accepts Pascal-type strings. If you have text in a Pascal string and you want to pass it to a function that expects a PChar, the following code is a "quick and dirty" way of doing it, assuming that s is of type string and that the string has room for one more character: s[length(s)+1] := #0; { Appends a null to the end of the string } C_Style_Function(@s[1]); { @s[1] is a PChar to the beginning of s }