Peter,

There's nothing obviously wrong with the function below, and I've done the 
same thing numerous times. It's good practice, though, to pass the lengths 
of the pchars as well so that you can ensure you're not overwriting 
something. That's probably what's happening here.

I'm really not sure how your record type works, given that the pchars could 
be any length, in that case I would use an array of char with fixed length.

One way to modify the function so you can be sure you're not overwriting 
anything is as follows:

procedure ChangeValue(var FName:PChar; var LName:PChar);
begin
    StrLcopy( FName, 'Delphi First Name', sizeof( FName ) - 1 );
    StrLcopy( LName, 'Delphi Last Name',  sizeof( LName ) - 1 );
end;

Knocking 1 off of the length ensures that if FName is null terminated to 
begin with it will remain so.

Hope this helps.

Marc Pelletier
Traxis Inc.


At 12:51 PM 5/23/01 +1000, you wrote:
>procedure ChangeValue(var FName:PChar; var LName:PChar); Stdcall;
>
>implementation
>
>//******************************************************
>procedure ChangeValue(var FName:PChar; var LName:PChar);
>begin
>     StrPcopy(FName,'Delphi First Name');  //<--Everything crashes in a great
>heap!
>     StrPcopy(LName,'Delphi Last Name');
>end;
>//******************************************************
>end.



_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to