Solved

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

Posted on 2002-04-26
6
174 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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