Solved

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

Posted on 2002-04-26
6
172 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 70
System restore point 4 91
Tembedded WB animatid gifs not animated on some pcs 2 73
Base1 Encode/Decode 3 68
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

21 Experts available now in Live!

Get 1:1 Help Now