Board index » delphi » Converting String to Pchar;

Converting String to Pchar;

Hi!
Iwant to start a webbrowser from a Delphi-program and I use the following
command:
ShellExecute(handle,'open',browser,url,nil,SW_SHOW);
I want the user to specify the browser-path; for example:
d:\programfiler\internet explorer\iexplore.exe
The problem is to convert the string into a Pchar. The following procedure
almost work:
Procedure convertStringToPchar(myString : string; var pch: PChar);
var ch               : array[0..60] of Char;
        i                 : integer;
begin
    //empty the array
    for i:=0 to 60 do begin
       ch[i]:=chr(32);
    end;
    for i:=0 to length(streng)-1 do begin
       ch[i]:=MyString[i+1];
    end;
    Pch:=ch;
end;
The problem with this is that if myString:='d:\programfiler\internet
explorer\iexplore.exe' the
pch:='d:\programfiler\internet explorer\iexplore.exe           ' <----up to
60, and the the browser refuse to start.
Anyone know how to remove the spaces, or know a better method to this??

Ivar Katmo
Norway

 

Re:Converting String to Pchar;


    I think the more simple is to use this to convert the string to Pchar :
    var
        p:pchar;

    begin
    p:=pchar('the string to convert');
    end;

    I hope it resolves your problem.

    @+
    Aurlien
    destroy...@usa.net

Re:Converting String to Pchar;


Which version of Delphi are you using? New versions have all the pchar
routines built in.

Re:Converting String to Pchar;


Quote
Ivar Katmo wrote:
> Hi!
> Iwant to start a webbrowser from a Delphi-program and I use the following
> command:
> ShellExecute(handle,'open',browser,url,nil,SW_SHOW);
> I want the user to specify the browser-path; for example:
> d:\programfiler\internet explorer\iexplore.exe
> The problem is to convert the string into a Pchar. The following procedure
> almost work:
> Procedure convertStringToPchar(myString : string; var pch: PChar);
> var ch               : array[0..60] of Char;
>         i                 : integer;
> begin
>     //empty the array
>     for i:=0 to 60 do begin
>        ch[i]:=chr(32);
>     end;
>     for i:=0 to length(streng)-1 do begin
>        ch[i]:=MyString[i+1];
>     end;
>     Pch:=ch;
> end;
> The problem with this is that if myString:='d:\programfiler\internet
> explorer\iexplore.exe' the
> pch:='d:\programfiler\internet explorer\iexplore.exe           ' <----up to
> 60, and the the browser refuse to start.
> Anyone know how to remove the spaces, or know a better method to this??

> Ivar Katmo
> Norway

try this:

pch:=stralloc(length(mystring)+1) {create space for the #0 char}
strPcopy(pch,mystring);

// now do someting with pch

strdispose(pch);

Ralph van Berloo

Re:Converting String to Pchar;


try...
ShellExecute(handle,'open',@browser[1],url,nil,SW_SHOW);

On Mon, 20 Apr 1998 19:15:26 +0200, "Ivar Katmo" <iva...@hotmail.com>
wrote:

Quote
>Hi!
>Iwant to start a webbrowser from a Delphi-program and I use the following
>command:
>ShellExecute(handle,'open',browser,url,nil,SW_SHOW);
>I want the user to specify the browser-path; for example:
>d:\programfiler\internet explorer\iexplore.exe
>The problem is to convert the string into a Pchar. The following procedure
>almost work:
>Procedure convertStringToPchar(myString : string; var pch: PChar);
>var ch               : array[0..60] of Char;
>        i                 : integer;
>begin
>    //empty the array
>    for i:=0 to 60 do begin
>       ch[i]:=chr(32);
>    end;
>    for i:=0 to length(streng)-1 do begin
>       ch[i]:=MyString[i+1];
>    end;
>    Pch:=ch;
>end;
>The problem with this is that if myString:='d:\programfiler\internet
>explorer\iexplore.exe' the
>pch:='d:\programfiler\internet explorer\iexplore.exe           ' <----up to
>60, and the the browser refuse to start.
>Anyone know how to remove the spaces, or know a better method to this??

>Ivar Katmo
>Norway

Re:Converting String to Pchar;


It's better to use this instead of type-casting.

  StrPCopy(Dest: PChar; const Source: string);

--

Janus N. T?ndering
Email: janusnt<alpha>usa<dot>net
Please correct my email address if you
want to mail me....thanks

Quote
Chris Hope wrote in message <353d8347.35343...@news.xtra.co.nz>...
>try...
>ShellExecute(handle,'open',@browser[1],url,nil,SW_SHOW);

>On Mon, 20 Apr 1998 19:15:26 +0200, "Ivar Katmo" <iva...@hotmail.com>
>wrote:

>>Hi!
>>Iwant to start a webbrowser from a Delphi-program and I use the following
>>command:
>>ShellExecute(handle,'open',browser,url,nil,SW_SHOW);
>>I want the user to specify the browser-path; for example:
>>d:\programfiler\internet explorer\iexplore.exe
>>The problem is to convert the string into a Pchar. The following procedure
>>almost work:
>>Procedure convertStringToPchar(myString : string; var pch: PChar);
>>var ch               : array[0..60] of Char;
>>        i                 : integer;
>>begin
>>    //empty the array
>>    for i:=0 to 60 do begin
>>       ch[i]:=chr(32);
>>    end;
>>    for i:=0 to length(streng)-1 do begin
>>       ch[i]:=MyString[i+1];
>>    end;
>>    Pch:=ch;
>>end;
>>The problem with this is that if myString:='d:\programfiler\internet
>>explorer\iexplore.exe' the
>>pch:='d:\programfiler\internet explorer\iexplore.exe           ' <----up
to
>>60, and the the browser refuse to start.
>>Anyone know how to remove the spaces, or know a better method to this??

>>Ivar Katmo
>>Norway

Other Threads