Hi,
I am a bit struggling with what should be fairly simple. I have a pchar
where I am adding and removing characters. What I did so far is to allocate
new memory every time and copying the source pchar over to a new one to
append or delete a character. This required two helper variables in order
Pchars are just a pain, I do not use any Pchars.. instead I use AnsiStrings
that I can manipulate in a way that is easy and then I just do
Pchar(myvariable) whenever I need to use a function that needs a Pchar… like
this:
Var
MessageBoxText:Ansistring;
..
..
windows.messagebox(0,pchar(Me
Also StrPCopy will take the contents of an existing PChar and put it in an
AnsiString…
And sometimes I have regular pascal strings I want to pass to something as a
Pchar, so then I do:
Pchar(AnsiString(mystring));
But lately I’ve been just making all strings AnsiStrings anyway.
James
I think you could just manage the end of your string with a #0 char.
Just allocate enough space for the maximum size of your string plus the
terminal #0 char.
For example
program Project1;
{$mode objfpc}{$H+}
uses
SysUtils, Classes;
var
s: array[0..30] of char;
p: PChar;
begin
p:
Note: if your string is UTF8 encoded, the last "character" can be
encoded, can span over 1 to 4 "Char", you need to know the length of
your character.
For example:
program Project1;
{$mode objfpc}{$H+}
uses
SysUtils, Classes;
var
s: array[0..30] of char;
p: PChar;
i: Integer;
begin