Convert String to PChar and viceversa

Some API routines need PChar type info and that's driving me mad, as  I don't know how to convert string to PChar.


  Directory: string;
  Directory := Edit1.Text + '\*.*';
                   {don't know if this parameter is rigth, but it's not the point}.

An error occurs because Directory must be PChar. How could I solve this problem?

I've looked up in Delphi help for 'string to PChar conversions' and there's actually a help file about that, but it doesn't help much. It only explains what a PChar is and what it's  functionality, but it doesn't mention anything about 'string to PChar conversions' as it's title says.
:( I'm sorry to say that Delphi4 help is not as good as I expected, but that's life...

My last question has to do with standards.. I mean, why do API's need PChar types and not string or integer types. I know they are null terminated strings, and I believe they are pointers, but that doesn't help me much.
There must be some interesting reason, and I would like to know why.

Thanks. Sorry for the points.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do this:


Windows API routines take pointers to chars for their arguments - thats just life! Delphi uses nice string types which makes life much easier. The cast is all you need, so its pretty simple...



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pablocastaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.