[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

paramstr() can't handle long filenames?

Posted on 1997-05-24
4
Medium Priority
?
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
sleach earned 100 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 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