Solved

paramstr() can't handle long filenames?

Posted on 1997-05-24
4
417 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
ID: 1336570
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
ID: 1336571
Edited text of question
0
 

Author Comment

by:hellfire052497
ID: 1336572
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
ID: 1336573
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

772 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