Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:56:20+00:00 2026-05-15T15:56:20+00:00

Subj. I’d like to use strings instead of PChar because that spares me much

  • 0

Subj. I’d like to use strings instead of PChar because that spares me much casting, but if I just do

procedure SomeExternalProc(s: string); external SOMEDLL_DLL;

and then implement it in some other project with non-shared memory manager:

library SeparateDll;
procedure SomeExternalProc(s: string);
begin
  //a bla bla bla
  //code here code here
end;

I have (formally) no guarantee Delphi does not decide for whatever reason to alter the string, modify its reference counter, duplicate or unique it, or whatever else. For example

var InternalString: string;

procedure SomeExternalProc(s: string);
begin
  InternalString := s;
end;

Delphi increments refcounter and copies a pointer, that’s it. I’d like Delphi to copy the data. Does declaring the parameter as “const” make it safe for that reason? If not, is there a way to do it? Declaring parameter as PChar doesn’t seem to be a solution because you need to cast it every time:

procedure SomeExternalProc(s: Pchar); forward;
procedure LocalProc;
var local_s: string;
begin
  SomeExternalProc(local_s); //<<--- incompatible types: 'string' and 'PAnsiChar'
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:56:21+00:00Added an answer on May 15, 2026 at 3:56 pm

    That would probably work, as long as you only ever use your DLL from code compiled in the same version of Delphi. The internal format of string has been known to change between releases, and you have no formal guarantee that it won’t change again.

    If you want to avoid having to cast everywhere you use it, try wrapping the function, like this:

    procedure SomeExternalProc(s: Pchar); external dllname;
    procedure MyExternalProc(s: string); inline;
    begin
      SomeExternalProc(PChar(local_s));
    end;
    

    Then in your code, you call MyExternalProc instead of SomeExternalProc, and everyone’s happy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that there's no a documented API to accomplish the subj, but maybe
I am trying to implement SUBJ but can't make destination segue appear in my
It seems that this is a new feature in JQuery UI 1.9.0, because I
Sorry for some crazy subj. I'd like to override django models save method and
subj. Something like: (lexical-let (oldf #'original-func) (flet ((original-func (arg) do-something (funcall oldf arg))) do-something))
Subj. I mean that I don't want to paste dozens of '\' into search
I use SQL Server 2005 and I have a query like this : INSERT
Subj. Are they implemented in trivial way with complexity O(N) or they are faster?
Subj. I am using Silverlight 4 with VS2010, here is a source code: <ComboBox
I found solution for subj related to the Visual Studio XSLT processor: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.