Solved

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

Posted on 2002-04-26
6
171 Views
Last Modified: 2010-04-04
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
Comment
Question by:sudhakar_koundinya
6 Comments
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 6970621
correction:
var tempptr,bytes:PByte;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6970638
look at the move-method
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 50 total points
ID: 6970654
PByte(@aStrBuffer[0]) is what you search for.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Expert Comment

by:ITugay
ID: 6970663
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6971469
I'd do it like kretchmar suggested

GetMem(bytes, aintSize);
Move(astrBuffer[0], bytes^, intsize);
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 6973304
Thanks all
As Robert idea helped me

i am giving points to him

thanks for your co operation


Regards
Koundinya
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now