Questions tagged [pchar]
33 questions
11
votes
3 answers
In Delphi in my DLL do I have to allocate the return pchar of a function
I have a DLL in which I have a function that returns a pchar. (as to avoid having to use borlndmm) What I was doing originally was casting a string as a pchar and returning that
Result := pChar(SomeFuncThatReturnsString)
But I was getting expected…

Tim
- 1,549
- 1
- 20
- 37
8
votes
2 answers
Why Does SetString Take Less Memory in Delphi (with Unicode)?
This is Delphi 2009, so Unicode applies.
I had some code that was loading strings from a buffer into a StringList as follows:
var Buffer: TBytes; RecStart, RecEnd: PChar; S: string;
FileStream.Read(Buffer[0], Size);
repeat
…

lkessler
- 19,819
- 36
- 132
- 203
8
votes
1 answer
Is PChar('') guaranteed to be a pointer to #0 (not nil)?
I understand that in Delphi, an empty string (AnsiString or WideString) can be represented by a nil pointer, or by a pointer to an actual empty string.
By experiment I've shown that in Delphi XE2 (with particular compiler settings) PChar('') <> nil.…

Ian Goldby
- 5,609
- 1
- 45
- 81
7
votes
2 answers
How do I pass a string variable to a function that expects a PChar?
I have this code:
ShellExecute(Handle, 'open',
'C:\Users\user\Desktop\sample\menu\WTSHELP\start.html',
nil, nil, sw_Show);
How can I replace the literal in the third argument with a string variable? If I use code like…

user1884060
- 75
- 1
- 7
4
votes
1 answer
Importing Pchar Delphi DLL to C#?
I have a procedure in delphi:
procedure PasswordDLL(month integer; password pchar);
export;
The procedure should output the password to "password" pchar that I passed in..
From what I google..and reading....
ref: HERE and HERE
I come up with:…

King
- 43
- 1
- 4
4
votes
2 answers
How can I extract part of a PChar into a string?
During profiling I came across a function that was taking quite a bit of time, but essentially boiled down to this very simple piece of code:
function GetSubstring(AInput: PChar; AStart, ASubstringLength: Integer): string;
begin
Result :=…

PersonalNexus
- 1,292
- 1
- 9
- 25
4
votes
3 answers
Ask user and send the Response back in a Message-Receiver
I want to ask the user to input a password. As the password is sometimes needed in a different thread than the main thread where VCL runs, I tried to send a Message to the main window and ask for the password. Then the main window asks the user.
How…

rollstuhlfahrer
- 3,988
- 9
- 25
- 38
3
votes
3 answers
When can ((Pointer)(P)+1)^ work?
I'am working on delphiXE2 and i was working on PInteger.
if i did this in my delphi code
var
P: PInteger;
testInt: Integer;
Scores: array[0..4] of Integer=(33,44,56,78,78);
begin
P := @Scores;
testInt := (P+1)^;
WriteLn(testInt);
…

changyu
- 81
- 5
3
votes
1 answer
Passing Delphi PChar to C#
I have some problems transferring data for delphi imported activeX control in c# environment.
I have a function on delphi side, which takes and returns PChar. I can modify it or do whatever I want with it.
function TActiveFormX.DelphiFunction(S:…

Martin R
- 33
- 3
2
votes
3 answers
How Can I Get PChar To Go Past Hex 00s to Get to the End of the File in Delphi?
I am parsing very large files (Unicode - Delphi 2009), and I have a very efficient routine for doing so using PChar variables as outlined in the Stackoverflow question: What is the fastest way to Parse a line in Delphi?
Everything was working great…

lkessler
- 19,819
- 36
- 132
- 203
2
votes
1 answer
Why would a routine need a PChar(type-cast from a string) passed to it remain in memory after it returns?
var
S: string;
begin
SetLength(S, MAX_SIZE);// when casting to a PChar, be sure the string is not empty
SetLength(S, GetModuleFilename(0, PChar(S), Length(S)));
// statements
end;
To eliminate the overhead of copying the buffer, you can…

lockedscope
- 965
- 17
- 45
2
votes
2 answers
Translate unsigned char *buf=NULL to Pascal?
I'm working in Borland Delphi, and i have a few lines code in Borland C++ Builder. I would like to translate these lines into Delphi source.
unsigned char *buf=NULL;
buf=new unsigned char[SPS*2];
for (i=0; i

user558126
- 1,303
- 3
- 21
- 42
2
votes
1 answer
Passing string from Delphi to C# returns null. However it works fine when I call the Delphi lib from Delphi. How to receive string from Delphi
I am completely new to Delphi and have been trying to make a few DLLs for .NET.
What I want to achieve is to send and receive txt output from my DLLs.
Here's what I've done so far:
Delphi Library function:
function DBConnet(inputStr: PChar; connStr:…

user1635508
- 31
- 3
2
votes
1 answer
String to PAnsiChar conversion trouble
These are a C DLL function example and its Delphi translation:
C definition:
DLL_EXPORT int AR_dll_function (const char *terminal_no, const char *description);
Delphi definition:
function Ar_Dll_Function(const TerminalNo: PAnsiChar; const…

ErkanK
- 95
- 7
2
votes
1 answer
Passing PChar from the Delphi DLL
How i can pass pchar from the DLL?
dll must be compatible with other apps, not just delphi.
In help is written that it is dangerous to pass pointers to local variables, if we make this variable global, the code will not be thread-safe.
We can safely…

The North Star
- 104
- 1
- 10