Shellexecute Pchars

If you have a programming question, please feel free to post it here. Non-programming questions will be moved to Miscellaneous or deleted.

Shellexecute Pchars

by Blod » 26/04/09 18:35

Hello,

The user of my program will enter information into an edit box.
How can I copy this edit box.text into a Pchar variable that I can then use in the Shellexecute function?
I've tried a few ways and keep getting errors.

Thanks

Blod
Blod
Active Member
Active Member
 
Posts: 15
Joined: 05/06/08 12:54

Re: Shellexecute Pchars

by Kambiz » 27/04/09 00:54

When a function/procedure expects a PChar as parameter, just typecast the string argument as PChar.

For example:

Code: Select all
ShellExecute(0, 'open', PChar(UserCommandEditBox.Text), nil, nil, SW_NORMAL);
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1763
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Shellexecute Pchars

by Blod » 27/04/09 20:07

Thanks Kambiz,

It was simpler than I thought.
Can you help with this as well?

When I programatically code something like...

Edit1.text:=extractfilename(opendialog);

Edit1.text contains something like MYPROG.EXE but I'm unable to save that information to file.
If I actually type myprog.exe into the edit box then I am able to save this to file.
What is the reason for this?

Blod
Blod
Active Member
Active Member
 
Posts: 15
Joined: 05/06/08 12:54

Re: Shellexecute Pchars

by Kambiz » 28/04/09 00:43

Maybe it is because you use OpenDialog instead of OpenDialog.FileName.
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1763
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Shellexecute Pchars

by Blod » 28/04/09 12:59

This is the code that I actually use...

edit1.text:=extractfilename(opendialog1.filename);

It does put the name of the chosen file into the editbox.text as required.
However, when I try to save the editbox.text to file it fails to do so.
Although, if I physically type the filename into the editbox then it is saved for persistant use.

Blod
Blod
Active Member
Active Member
 
Posts: 15
Joined: 05/06/08 12:54

Re: Shellexecute Pchars

by Kambiz » 28/04/09 13:49

How do you save the edit1.text in to a file?
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1763
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Shellexecute Pchars

by Blod » 28/04/09 14:12

If I only have one or two items to save to file then I normally use an invisible memo in my program
and do something like...

Memo1.lines[0]:=edit1.text;
memo1.lines.savetofile('Myfile.txt');

I know that this isn't the approved way of doing things but it generally works ok.

Blod
Blod
Active Member
Active Member
 
Posts: 15
Joined: 05/06/08 12:54

Re: Shellexecute Pchars

by Kambiz » 28/04/09 17:27

All codes seems to be fine, but for sure there is a mistake somewhere.

If you attach a sample program, it would be much easier to trace the problem.
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site

Kambiz
Administrator
Administrator
 
Posts: 1763
Joined: 07/03/03 19:10
Location: Tehran, Iran


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 0 guests