[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Is there any way to to type cast dynamic array to pointer?

Hi all

Is there any way to type cast dynamic array to pointer


In my case problem is like this

procedure convert(astrBuffer:Array of Byte;aintSize:longint)
var tempptrbytes:PByte;
i:longInt;

begin
  GetMem(bytes,aintSize);
   tempptr:=bytes;
   for i:=0 to aintsize-1 do
   begin
     bytes^:=astrBuffer[i];
    inc(bytes);
   end;
  bytes:=tempptr;
end;

which is not acceptable as it takes time to copy the data

i need some thing like
bytes:=pByte(astrbuffer); and giving compilation errors

how to typecast the data, if the situation araises like this

Thanks in advance

Sudhakar
0
sudhakar_koundinya
Asked:
sudhakar_koundinya
1 Solution
 
sudhakar_koundinyaAuthor Commented:
correction:
var tempptr,bytes:PByte;
0
 
kretzschmarCommented:
look at the move-method
0
 
robert_marquardtCommented:
PByte(@aStrBuffer[0]) is what you search for.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ITugayCommented:
Hi sudhakar_koundi,
there is two ways to pass array of bytes:

1. as VAR parameter, in this case you operation will affect original array.
2. as formal paramter (no VAR), in this case you will get the copy of original array.

So, use second way instead of allocate memory and assign array manually, Delphi does it for you.


----
Igor.
0
 
Lee_NoverCommented:
I'd do it like kretchmar suggested

GetMem(bytes, aintSize);
Move(astrBuffer[0], bytes^, intsize);
0
 
sudhakar_koundinyaAuthor Commented:
Thanks all
As Robert idea helped me

i am giving points to him

thanks for your co operation


Regards
Koundinya
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now