Vector7
asked on
PByte to PAnsiChar Conversion
Hi,
I'm migrating a system from Delphi 7 to Delphi XE4 and running into all sorts of conversion problems.
Is there a conversion function for converting PByte to PAnsiChar?
Many thanks
I'm migrating a system from Delphi 7 to Delphi XE4 and running into all sorts of conversion problems.
Is there a conversion function for converting PByte to PAnsiChar?
Many thanks
ASKER
Hi,
Thanks for your reply. The problem is that only the first character of 'Value' (code below) is being saved in the statement e.g. a 'Value' of 2048 is saved as 2.
Check(DbiCfgModifyRecord(h Cfg, P, ParamCount, pFld, pRec));
Herewith the code:-
var hCfg: hDBICfg;
Config: SYSConfig;
Path, Option: string;
ParamCount, i: word;
pFields, pFld: pFLDDesc;
pRecBuf, pRec: pBYTE;
Found, SelfInitialized: Boolean;
rslt: DBIResult;
P: PAnsiChar;
pFields := AllocMem(ParamCount * sizeof(FLDDesc));
pFld := pFields;
pRecBuf := AllocMem(10000);
pRec := pRecBuf;
{Get the node values... }
Check(DbiCfgGetRecord(hCfg , StrToPAnsiChar(Path), ParamCount, pFields, pRecBuf));
for i := 0 to ParamCount - 1 do
begin
if pFields^.szName = Option then
begin
StrPCopy(PAnsiChar(pRecBuf ), Value);
P := StrToPAnsiChar(Path);
Check(DbiCfgModifyRecord(h Cfg, P, ParamCount, pFld, pRec));
Found := True;
end;
Inc(pFields);
Inc(pRecBuf, 128);
end;
Thanks for your reply. The problem is that only the first character of 'Value' (code below) is being saved in the statement e.g. a 'Value' of 2048 is saved as 2.
Check(DbiCfgModifyRecord(h
Herewith the code:-
var hCfg: hDBICfg;
Config: SYSConfig;
Path, Option: string;
ParamCount, i: word;
pFields, pFld: pFLDDesc;
pRecBuf, pRec: pBYTE;
Found, SelfInitialized: Boolean;
rslt: DBIResult;
P: PAnsiChar;
pFields := AllocMem(ParamCount * sizeof(FLDDesc));
pFld := pFields;
pRecBuf := AllocMem(10000);
pRec := pRecBuf;
{Get the node values... }
Check(DbiCfgGetRecord(hCfg
for i := 0 to ParamCount - 1 do
begin
if pFields^.szName = Option then
begin
StrPCopy(PAnsiChar(pRecBuf
P := StrToPAnsiChar(Path);
Check(DbiCfgModifyRecord(h
Found := True;
end;
Inc(pFields);
Inc(pRecBuf, 128);
end;
It seems to me your original question is not exactly what you are after. Your question was if and how to convert a pbyte to pAnsiChar - which I believe I answered.
Just remember that a PByte or a PAnsichar are merely pointers. PByte points to an address and if you dereference it, it will give you the byte value at that address. The same goes for PAnsichar i.e. if you dereference it it will give you the AnsiChar at that address. Regarding your value of 2048, this can't be stored in a single byte (max is 255).
From your code, it looks like DbiCfgGetRecord returns a pointer to the fields (pFields) and its values as a buffer (pRecBuf).
Looking at your loop through the paramcount it seems that the buffer allocates 128 bytes for each field/parameter value (see: Inc(pRecBuf, 128); ).
It looks like what you are trying to do is set the pRecBuf (the parameter value buffer) to contain the value you pass, is this right? What is "Value" defined as? this may be your problem. try: StrPCopy(PAnsiChar(pRecBuf ), AnsiString(Value));
Just remember that a PByte or a PAnsichar are merely pointers. PByte points to an address and if you dereference it, it will give you the byte value at that address. The same goes for PAnsichar i.e. if you dereference it it will give you the AnsiChar at that address. Regarding your value of 2048, this can't be stored in a single byte (max is 255).
From your code, it looks like DbiCfgGetRecord returns a pointer to the fields (pFields) and its values as a buffer (pRecBuf).
Looking at your loop through the paramcount it seems that the buffer allocates 128 bytes for each field/parameter value (see: Inc(pRecBuf, 128); ).
It looks like what you are trying to do is set the pRecBuf (the parameter value buffer) to contain the value you pass, is this right? What is "Value" defined as? this may be your problem. try: StrPCopy(PAnsiChar(pRecBuf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why a b grade?
Thank you
or you could do something like:
var b: byte;
pb: pbyte;
pc: PAnsiChar;
begin
b:= 65;
pb:= @b; //pb^ will be 65
pc:= @b; //pc^ will be 'A'
...