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.

Example

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

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.
:)
pablocastaAsked:
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.

rwilson032697Commented:
Do this:

 FindFirstFile(PChar(Directory),fcFileName);

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...

Cheers,

Raymond.
0

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:
thanks.
0
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
Delphi

From novice to tech pro — start learning today.