Solved

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

Posted on 2002-04-26
6
173 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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