[lazarus] convert edit.text to pchar ?

Michael Van Canneyt michael.vancanneyt at wisa.be
Thu Jun 28 03:44:13 EDT 2001




On Wed, 27 Jun 2001, NORBERT ALLAIN wrote:

> I want convert a string in a edit component in a pchar (i use a c
> fonction in a dynamic library)

Just do a typecast:

  YourCFunction(pchar(edit.text));

But beware:
the resulting string is only valid for the duration of the particular statement
it is in, i.e. the C function should consider it a 'const' argument.

If you want a more 'permanent' string, you'll have to use strnew() to allocate
a new string on the heap, but then it must also explicitly be released:

  p:=strnew(pchar(edit.text));
  ... // use P as much as needed.
  strdispose(p);

Michael.






More information about the Lazarus mailing list