Re: Delphi.NET



Hi Rob,

Could I get you to please give me an example that demonstrates this?

I tried today using Marshal.Copy and setting up an IntPtr but for some reason the source buffer
was getting wiped out which I could not understand why?

If you could show a basic example of its use that would be greatly appreciated.

TIA

Regards

Daniel.


"Rob Kennedy" <me3@xxxxxxxxxxx> wrote in message news:5ednsrF37djhqU1@xxxxxxxxxxxxxxxxxxxxx
Daniel Hobson wrote:
I was wondering if anybody is out there who uses Delphi.NET. We seem to be having a few problems in knowning
about the new requirements of DotNET. The main one that has us really stumped is how do you
convert from one data type to another different data type?

For example:-

Type
TTestRec = record
t1: array [1..32] of char;
t2: array [1..28] of char;
end;

MyBuffer : TidBytes;
MyActType : TTestRec;

I read in the information via TCP/IP into MyBuffer (Have no choice in the matter)

The question is now .. how can I say that MyBuffer is type TTestRec ????

You don't. That would by lying. You've clearly declared MyBuffer as a completely different type.

What you're trying to do is get the contents of the MyBuffer array into the MyActType record. That task is really trivial, so I suppose the unwritten part of your question is that you want to get the array contents into the record without actually having to write a loop yourself.

For that, you can use the System.Runtime.InteropServices.Marshal class. It has a Copy method overloaded to take lots of different parameter types.

--
Rob

.


Quantcast