Solved

paramstr() can't handle long filenames?

Posted on 1997-05-24
4
424 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 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

Independent Software Vendors: 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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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