Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2001-06

convert edit.text to pchar ?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to NORBERT ALLAIN
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.

Reply by email