[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

paramstr() can't handle long filenames?

Posted on 1997-05-24
4
Medium Priority
?
430 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

834 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