Thanks Marc,
Removing the 'var' from the declaration did the trick!
Although I had to change the StrLCopy back to the normal StrPCopy. StrLCopy
for some reason chopped everything off after the third character (even
though the sting was buffered with 100 characters), but StrPCopy works fine.
Working with PChar types can be a real pain in the proverbial sometimes.
But if it works, leave it...
-----Original Message-----
From: Marc Pelletier [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 18 January 2001 2:58 AM
To: [EMAIL PROTECTED]
Subject: RE: MI-L MB/Delphi - Passing strings from MB to Delphi DLL
(revisited)
Peter,
I'm not a mapbasic programmer, so I can't help you with that end, but I'm
intrigued by the Delphi part. Did you try removing the 'var' modifiers. It
may be that since pchar is a pointer anyway passing it as a var is
confusing things.
cheers
Marc
At 10:28 AM 5/24/01 +1000, you wrote:
>Marc,
>
>I tried your solution but still get the error message:
>
>""This program has performed an illegal operation and will be shut down...
>yada.. yada. yada..."
>
>Here's my sample MB code...
>Is there anything obviously wrong?
>
>
>-----------------------------------------------------------------
>Include "MAPBASIC.DEF"
>
>Declare Sub ChangeValue Lib "Project_PCharAlternative.DLL"
> Alias "ChangeValue"
> (FName as String, LName as String)
>
>Declare Sub Main
>
>
>'**********************************************************
>
>Sub Main
>Dim
> FName as String,
> LName as String
>
>FName = Space$(100)
>LName = Space$(100)
>FName = "Mapinfo First Name"
>LName = "Mapinfo Last Name"
>
>Note FName + chr$(13) + LName
>call ChangeValue(FName, LName)
>Note FName + chr$(13) + LName
>
>End Sub
>-----------------------------------------------------------------
>
>
>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED]]On Behalf Of Marc Pelletier
>Sent: Wednesday, 17 January 2001 2:06 AM
>To: [EMAIL PROTECTED]
>Subject: Re: MI-L MB/Delphi - Passing strings from MB to Delphi DLL
>(revisited)
>
>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.
_______________________________________________________________________
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.