Home How do I write a Delphi procedure that modifies a string that works for both PCHAR and string?
Reply: 0

How do I write a Delphi procedure that modifies a string that works for both PCHAR and string?

user792
1#
user792 Published in June 24, 2018, 3:07 am

To take an example, lets say I would like to write a simple procedure that deletes the 'X' characters from a string.

How can I design my procedure so that it works for both string and PCHAR parameters.

If I define it as:

procedure RemoveX( source : PCHAR);

than calls to RemoveX(PCHAR(mystring)) where myString is a string will remove the 'X' but will not take care of updating the string length ... Hence a subsequent myString := myString + 'done' will leave myString unchanged. And I don't want to change the length after the call to RemoveX, I expect the RemoveX procedure to deal with everything.

If on the other hand I define it as:

procedure RemoveX( var source : string);

I don't know how to pass it a PCHAR ...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309657 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO