Hi List
I have a query relating to passing strings from MB to Delphi, by (var).
Do PChar data types in Delphi always have to be embedded inside a "Packed
Record" in order to make changes to them (VAR), or can they be passed
directly as procedure parameters? I haven't had any success with the later
one.
-----------------------------------------------------------
This DOES work: (note the PChars snugly tucked away inside
the TName packed record data type)
-----------------------------------------------------------
unit Unit_Test;
interface
uses
Dialogs, SysUtils;
type
TName = packed record
FName : pchar;
LName : pchar;
end;
procedure ChangeValue(var Name:TName); Stdcall;
implementation
//******************************************************
procedure ChangeValue(var Name:TName);
begin
StrPcopy(Name.FName,'Delphi First Name'); //<-- Works fine.
StrPcopy(Name.LName,'Delphi Last Name'); //<-- Works fine.
end;
//******************************************************
end.
-----------------------------------------------------------
This DOESN'T work: (passing strings directly into PChar types
and then making changes seems to cause memory problems)
-----------------------------------------------------------
unit Unit_Test2;
interface
uses
Dialogs, SysUtils;
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.
Can anyone enlighten me as to why the "ChangeValue" procedure doesn't work
in the second example?
Peter Zyczynski
Analyst Programmer
Landfile Consultancy
Australia
Ph: (03) 6244-7344
email: [EMAIL PROTECTED]
_______________________________________________________________________
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.