Thread View: borland.public.cppbuilder.migration
2 messages
2 total messages
Started by Rolf Fankhauser
Thu, 03 Feb 2005 09:01
problem with delphi function which returns array of byte
Author: Rolf Fankhauser
Date: Thu, 03 Feb 2005 09:01
Date: Thu, 03 Feb 2005 09:01
38 lines
2282 bytes
2282 bytes
I have problems to use some functions in CBuilder which I wrote in Delphi:
function ConvertCodeToKey(Code: string): TKey;
function CheckRegistration(Name: string; Key: TKey) : boolean;
function ConvertNameToKey(Name: string): TKey;
function ConvertKeyToCode(Key: TKey): string;
TKey is defined as follows:
type
TKey = array [0..15] of Byte;
These functions are converted by CBuilder to:
extern PACKAGE Byte __fastcall ConvertCodeToKey(AnsiString Code);
extern PACKAGE bool __fastcall CheckRegistration(AnsiString Name, const
Byte * Key);
extern PACKAGE Byte __fastcall ConvertNameToKey(AnsiString Name);
PACKAGE AnsiString __fastcall ConvertKeyToCode(const Byte * Key);
My problem is how to access the array of bytes in CBuilder. It returns
only one byte and not the whole array. Or is this the pointer to the array?
I tried it by the following code but CheckRegistration is always false
even with a matching pair of user name and key:
bool Regd = false;
AnsiString RegKey = "2LTNRVJRYSN:][aM";
Byte Key = ConvertCodeToKey(RegKey);
ShowMessage(IntToStr(Key));
if (!CheckRegistration("Rolf Fankhauser",&Key))
Regd = FormRegistration->InputRegistration("REBEKA","TestReg.ini",15);
if (Regd)
ShowMessage("Registered!");
else
ShowMessage("Not registered!");
Any idea how to get the whole array of byte?
Re: problem with delphi function which returns array of byte
Author: Alisdair Meredith [TeamB]
Date: Thu, 03 Feb 2005 09:14
Date: Thu, 03 Feb 2005 09:14
28 lines
1897 bytes
1897 bytes
Rolf Fankhauser wrote: > My problem is how to access the array of bytes in CBuilder. It > returns only one byte and not the whole array. Or is this the pointer > to the array? Correct, that is how arrays work in C, and so in C++. In C you would normally pass an extra integer to know how long the array is. Obviously that is not necessary for Delphi where the array type contains more information and is bounds-checked at runtime. So yes, assume the rest of the array is there and you can access the elements with the syntax : Key[3] = 5; and so on. But now you have 2 choices to make: i/ Accept the fact you know the array size is fixed, but not communicated to the software. Run the risk of the Delphi definition changing and maybe breaking your program. ii/ Add an extra integer parameter to the function calls that is redundant and useless in Delphi, to tell C++ code the size of the array. AlisdairM(TeamB)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads