I have to convert my shortstring parameters to PChar to ensure that my DLL will work with VB ??
Firstly the above statement true?
Anyway this is a converted function (in the DLL)
But the Delphi help on PChar seems to say that this should not work.
But my fuction seems to be working is it because of the stdcall directive or do I need to change this?
Steve [The sane]: Delphi a feersum engin indeed.
Firstly the above statement true?
Anyway this is a converted function (in the DLL)
Code:
function RetrieveSettings(Code: integer): PChar; stdcall;
var S: string;
begin
with datamodule2 do
case code of
0: S := Server.LocalName;
1: S := inttostr(Server.DefaultPort);
2: S := Server.Bindings[0].IP;
3: S := inttostr(Server.Bindings[0].Port);
4: S := Server.Bindings[0].PeerIP;
5: S := inttostr(Server.Bindings[0].PeerPort);
6: S := Server.Version;
else S := 'Illegal Code';
end;
result := PChar(S);
end;
But the Delphi help on PChar seems to say that this should not work.
Code:
A common error when working with PChars is to store a local variable in a data structure, or return it as a value. When your routine ends, the PChar disappears because it is a pointer to memory, and not a reference counted copy of the string. For example:
function title(n: Integer): PChar;
var
s: string;
begin
s := Format('title - %d', [n]);
Result := PChar(s); // DON'T DO THIS
end;
This example returns a pointer to string data that is freed when the title function returns.
But my fuction seems to be working is it because of the stdcall directive or do I need to change this?
Steve [The sane]: Delphi a feersum engin indeed.