Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing string as const string

Status
Not open for further replies.

IAdams

MIS
Jul 9, 2008
11
US
I have a C# dll that is called from Delphi (version 6). The parameters for the C# method are <string,string,string,...> but for some reason Delphi is insisting on <const: widestring,const: widestring,const: widestring,...> as the passed-in parms. However, I need to reassign these fields in a loop and call the routine many times.

How can I either: relax the const requirement or assign a varying string to a const string?

Thanks,
 
Wow, sorry to respond so late...

The C# method is asking for a widestring reference and promising not to modify the string.

You can use both ansistring and widestring together, and assign the one to the other:
Code:
var
  astr: ansistring;
  wstr: widestring;
begin
  astr := 'Hello world!';
  wstr := astr;
  MessageBoxW( 0, pWideChar(wstr), 'A message', MB_OK or MB_TASKMODAL )
end;

I'm pretty sure that Delphi VCL functions (like ShowMessage) can take widestrings too, but I've been playing with C++ for the past few months so I don't remember exactly...

Hope this helps (in time). :-\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top