Board index » delphi » could someone tell me why this doesn't work (short code example)

could someone tell me why this doesn't work (short code example)

Quote
Rene Veerman wrote:

> this code fails on using the function paramstr. I'd like to know why.
> What am I missing?

> program project;

> uses
>   procs in 'procs.pas',

insert SYSTEM !!!

Quote

>   forms,
>   registry,
>   windows;

> type
>   tCommandList = (cmdConvert);

[snip]

Hi Rene,

you need to insert the unit SYSTEM in the uses statement.

Hope this helps,
Robert.

=======================================================
Robert Stephan
     mailto:clone@*delete_stars_&_this_text*ns.noell.de
     http://www.noell.de
=======================================================

At least my life isn't object orientated...

 

Re:could someone tell me why this doesn't work (short code example)


Quote
In article <3365bce8.7042...@news.xs4all.nl>, lowle...@xs4all.nl (Rene Veerman) wrote:

>this code fails on using the function paramstr. I'd like to know why.
>What am I missing?

{$APPTYPE CONSOLE}

Jim.

_______________________________________________________________________
James A. O'Brien, R&D, Performance Trading Technologies, Inc.
HQ:  630 Third Avenue, New York, NY 10017  
+1 (212) 972-1702 (voice)    +1 (212) 972-0288 (fax)
R&D:  132 Cherry Hill Road, Orange CT 06477      
+1 (203) 891-8333 (voice)    +1 (203) 795-3598 (fax)
Wiz...@PTTI.com      http://www.PTTI.com

Re:could someone tell me why this doesn't work (short code example)


Quote
>  params:='r';
>  params:=paramstr(1);
>  for i:=2 to 9 do params:=params+paramstr(i);

>  if paramstr(1)[1]<>'/' then begin
>  //no command parameter entered.
>    displayHelp;
>    exit;
>  end;

        are you passing nine arguments to your program??  If not, that would
probably do it.  You should use the ParamCount function to return the number
of parameters on the command line..

        for i := 2 to ParamCount do
                blah blah..

brian, People used to play with toys, now the toys play with them.
<http://fatz.dorm.umd.edu/lahuman8/>

Re:could someone tell me why this doesn't work (short code example)


Quote
Rene Veerman wrote:

> On Mon, 28 Apr 1997 13:42:11 +0200, Robert Stephan <cl...@ns.noell.de>
> wrote:

> >Rene Veerman wrote:

> >> this code fails on using the function paramstr. I'd like to know why.
> >> What am I missing?

> >Hi Rene,

> >you need to insert the unit SYSTEM in the uses statement.

> >Hope this helps,
> >Robert.

> Maybe I forgot to mention something. It DOES compile, it just
> generates an eAccessviolation of some sort. This occurs the moment you
> try to execute a line which uses paramstr()...

        I missed the beginning of this. You don't call paramstr(), you
call paramstr(index) for some integer value of index. If index is larger
than ParamCount you'll get a GPF - are you checking that first?

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:could someone tell me why this doesn't work (short code example)


Rene Veerman <lowle...@xs4all.nl> wrote in article
<336638ac.19836...@news.xs4all.nl>...

Quote

> On Tue, 29 Apr 1997 09:21:48 GMT, lowle...@xs4all.nl (Rene Veerman)
> wrote:
> figured out the solution myself during the course of the day. Would
> like to thank the responders anyway :)

> The problem was that a borland exe crashes when you try to retrieve
> the LAST parameter from the commandline, even though you'd sometimes
> like to SEE that last param, AND the fact that the borland manual says
> that if there is no paramstr(int) to give because you simply don't
> have that parameter, it should just return a empty string.

This performance is what I experience on my system.
I tried to retrieve 9 parameters when there were in fact
none. Each was returned as an emptry string.

There should be no difference in behavior with any of
the parameters, from first to last. (that's theory, of course :-)

Quote
> But instead, it just generates an accessviolation and crashes the
> exe...
> Maybe someone could verify this on their machines and we could send a
> joint bug-report to borland?

No bug report required AFAIK
--
Grace + Peace   *   Peter N Roth  *   Engineering Objects International
Author of "C++ Jump Start" ISBN 0-9655862-2-7.
Tools for Developers: ClassBuilder 4 for Delphi, ClassBuilder++ for C++
Visit our website at http://www.inconresearch.com/eoi

Re:could someone tell me why this doesn't work (short code example)


On Tue, 29 Apr 1997 09:21:48 GMT, lowle...@xs4all.nl (Rene Veerman)
wrote:

Quote
>this code fails on using the function paramstr. I'd like to know why.
>What am I missing?

[snip]

Quote
>  params:='r';
>  params:=paramstr(1);
>  for i:=2 to 9 do params:=params+paramstr(i);

>  if paramstr(1)[1]<>'/' then begin
>  //no command parameter entered.
>    displayHelp;
>    exit;
>  end;

[snip]

OK, this may sound stupid, but are there 9 command line parameters? If
there aren't, then your for loop is going to crash because you are
attempting to access something that isn't there. You might want to
check the actual # of parameters with the ParamCount function before
you rip through the for loop. Something like this:

if (ParamCount <> 9) or (ParamStr(1)[1] <> '/')  then
  begin displayHelp; exit end;

params := '';
for i := 1 to 9 do params := params + ParamStr(i);

The above code assumes 9 parameters. If you can process *up to* 9
parameters, but require only one, then the following would suffice:

var
  max: integer;

max := ParamCount;

if (max = 0) or (max > 9) or (ParamStr(1)[1] <> '/') then
  begin displayHelp; exit end;

params := '';
for i := 1 to max do params := params + ParamStr(i);

Hope this helps.

ed yamada
KMS Systems

Re:could someone tell me why this doesn't work (short code example)


Rene Veerman <lowle...@xs4all.nl> wrote in article
<3365bce8.7042...@news.xs4all.nl>...

Quote

> this code fails on using the function paramstr. I'd like to know why.
> What am I missing?

[]

I ran what I thought was the important part of the code without problem.

Which invocation of paramstr() are you having trouble with (there are
several in the code).

Is there something in procs.pas that trumps system.paramstr()?
--
Grace + Peace   *   Peter N Roth  *   Engineering Objects International
Author of "C++ Jump Start" ISBN 0-9655862-2-7.
Tools for Developers: ClassBuilder 4 for Delphi, ClassBuilder++ for C++
Visit our website at http://www.inconresearch.com/eoi

Re:could someone tell me why this doesn't work (short code example)


this code fails on using the function paramstr. I'd like to know why.
What am I missing?

program project;

uses
  procs in 'procs.pas',

  forms,
  registry,
  windows;

type
  tCommandList = (cmdConvert);

const
  commandList  : array [tCommandList] of string = ('/convert');

var
  reg    : tRegistry;
  params : shortstring;
  i      : longint;
  cmd    : tCommandList;
begin
  application.initialize;

  params:='r';
  params:=paramstr(1);
  for i:=2 to 9 do params:=params+paramstr(i);

  if paramstr(1)[1]<>'/' then begin
  //no command parameter entered.
    displayHelp;
    exit;
  end;

  for cmd:=low (cmd) to high (cmd) do
    if commandlist[cmd]=paramstr(1) then exit;

  writeln (ord(cmd));

  reg:=tRegistry.create;
  readln (params);

end.

Re:could someone tell me why this doesn't work (short code example)


On Mon, 28 Apr 1997 13:42:11 +0200, Robert Stephan <cl...@ns.noell.de>
wrote:

Quote
>Rene Veerman wrote:

>> this code fails on using the function paramstr. I'd like to know why.
>> What am I missing?
>Hi Rene,

>you need to insert the unit SYSTEM in the uses statement.

>Hope this helps,
>Robert.

nope. system is auto-included. if you try to "use" it again, you'll
get an "identifier redeclared" error.

Re:could someone tell me why this doesn't work (short code example)


On Mon, 28 Apr 1997 13:42:11 +0200, Robert Stephan <cl...@ns.noell.de>
wrote:

Quote
>Rene Veerman wrote:

>> this code fails on using the function paramstr. I'd like to know why.
>> What am I missing?

>Hi Rene,

>you need to insert the unit SYSTEM in the uses statement.

>Hope this helps,
>Robert.

Maybe I forgot to mention something. It DOES compile, it just
generates an eAccessviolation of some sort. This occurs the moment you
try to execute a line which uses paramstr()...

Re:could someone tell me why this doesn't work (short code example)


On Mon, 28 Apr 97 13:28:12 GMT, james.obr...@pobox.com (Jim O'Brien)
wrote:

Quote

>In article <3365bce8.7042...@news.xs4all.nl>, lowle...@xs4all.nl (Rene Veerman) wrote:

>>this code fails on using the function paramstr. I'd like to know why.
>>What am I missing?

>{$APPTYPE CONSOLE}

nope. Did that in the Project | Options menu..

Re:could someone tell me why this doesn't work (short code example)


On Tue, 29 Apr 1997 09:21:48 GMT, lowle...@xs4all.nl (Rene Veerman)
wrote:

Quote
>this code fails on using the function paramstr. I'd like to know why.
>What am I missing?

figured out the solution myself during the course of the day. Would
like to thank the responders anyway :)

The problem was that a borland exe crashes when you try to retrieve
the LAST parameter from the commandline, even though you'd sometimes
like to SEE that last param, AND the fact that the borland manual says
that if there is no paramstr(int) to give because you simply don't
have that parameter, it should just return a empty string.
But instead, it just generates an accessviolation and crashes the
exe...
Maybe someone could verify this on their machines and we could send a
joint bug-report to borland?

Re:could someone tell me why this doesn't work (short code example)


Quote
Rene Veerman wrote:

> On Tue, 29 Apr 1997 09:21:48 GMT, lowle...@xs4all.nl (Rene Veerman)
> wrote:

> >this code fails on using the function paramstr. I'd like to know why.
> >What am I missing?
> figured out the solution myself during the course of the day. Would
> like to thank the responders anyway :)

> The problem was that a borland exe crashes when you try to retrieve
> the LAST parameter from the commandline, even though you'd sometimes
> like to SEE that last param, AND the fact that the borland manual says
> that if there is no paramstr(int) to give because you simply don't
> have that parameter, it should just return a empty string.
> But instead, it just generates an accessviolation and crashes the
> exe...

        That's what I thought. Then a few people said I was lying and
it looks to me like they were right - I have no problem with ParamStr(999).
Maybe the problem's elsewhere (or maybe it's different in different
versions of Delphi)?

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:could someone tell me why this doesn't work (short code example)


Quote
David Ullrich wrote:

> Rene Veerman wrote:

> > On Mon, 28 Apr 1997 13:42:11 +0200, Robert Stephan <cl...@ns.noell.de>
> > wrote:

> > >Rene Veerman wrote:

> > >> this code fails on using the function paramstr. I'd like to know why.
> > >> What am I missing?

> > >Hi Rene,

> > >you need to insert the unit SYSTEM in the uses statement.

> > >Hope this helps,
> > >Robert.

> > Maybe I forgot to mention something. It DOES compile, it just
> > generates an eAccessviolation of some sort. This occurs the moment you
> > try to execute a line which uses paramstr()...

>         I missed the beginning of this. You don't call paramstr(), you
> call paramstr(index) for some integer value of index. If index is larger
> than ParamCount you'll get a GPF - are you checking that first?

Nope. Paramstr(1) returns an empty string if no parameter #1 is entered.
At least for me, D2, Win95. This works both with and without huge
strings
enabled.

--
Svante Granqvist                 Speech, Music and Hearing
Phone +46-8-790 7561             Box 700 14
Fax   +46-8-790 7854             S-100 44 Stockholm
mailto:sva...@speech.kth.se      http://www.speech.kth.se/~svante

Other Threads