Solved

paramstr() can't handle long filenames?

Posted on 1997-05-24
4
412 Views
Last Modified: 2010-04-04
when using the paramstr() option for opening a file, it cannot handle long filenames. For example in explorer from windows and you doubleclick on a file then it starts the program but cannot load any file with a space.
and so refuses it to load in the edit field, I use richedit, and when I click a file it loads in the richedit field fine, but when the file contains a space it refuses to do so.
putting the file in brackets helps "this is a testfile.txt" from a commandline but this is not possible in explorer so what code does open and display long filenames correct?

The Code I use is as follows:

if ExtractFileName(ParamStr(1)) <> '' then
   begin
     OpenCode(ParamStr(1));


and Opencode relates to the Procedure Opencode...
What needs to be changed here.
0
Comment
Question by:hellfire052497
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
sleach earned 50 total points
Comment Utility
The problem is that ParamStr() sees the space character as a devider between multipul parameters.  If you only have a single parameter that is a filename, the solution is to fuse all the peices together.  See example below.

{'parameters' will hold the whole parameter string and will
  include any spaces}
parameters := '';
for x := 1 to paramCount do
  parameters := parameters + paramStr(x)+' ';


0
 

Author Comment

by:hellfire052497
Comment Utility
Edited text of question
0
 

Author Comment

by:hellfire052497
Comment Utility
I updated my question, I included the code I use for opening.
Please give clear explanation of what needs to be changed in my codelines, I am pretty new to Delphi so explain a bit better.
Thanks

0
 
LVL 1

Expert Comment

by:sleach
Comment Utility
Here is the WHOLE FormCreate event as it should be in your code.  Just copy and paste it in.:

procedure TForm1.FormCreate(Sender: TObject);
var
parameters:  string;
x:  integer;
begin
{Extract Parameters from ParamString.  Will include spaces.}
parameters := '';
for x := 1 to paramCount do
  begin
  parameters := parameters + paramStr(x);
  if x < paramCount then parameters := parameters +' ';{dont add a space to the last parameter}
  end;

{Process Parameters}
in Parameters <> '' then OpenCode(Parameters);
end;
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now