Re: Delphi.NET
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Sat, 30 Jun 2007 02:21:35 -0500
Daniel Hobson wrote:
kennedyri@xxxxxxxxx wrote:On Jun 27, 3:41 am, "Daniel Hobson" <djhob1...@xxxxxxxxxxxx> wrote:
The source buffer? Are you sure you had the parameters in the right
order? Show your code.
Here is the code that we tried.
{$UNSAFECODE ON}
procedure TMainForm.Button1Click(Sender: TObject); unsafe;
type
TTestRec = record
t1: array [1 .. 38] of char;
t2: array [1 .. 22] of char;
end;
var
inputMsg : TBytes;
MyTest : TTestRec;
MySrcPtr : IntPtr;
begin
try
try
{ hostclient is an TidTCPClient component }
hostclient.Connect;
MySrcPtr := IntPtr.Create(@MyTest);
SetLength (inputMsg, 60);
hostclient.IOHandler.ReadBytes (inputMsg, 60, false);
Marshal.Copy(inputMsg, 0, MySrcPtr, 60);
There you're writing 60 bytes into an eight-byte buffer. I suspect at least some of those bytes end up being written onto the stack position of inputMsg.
hostclient.IOHandler.Writeln ('Reply');
except
end;
Get rid of that empty exception handler. It's not helping anything.
finally
{
Cleanup before exiting.
}
SetLength (inputMsg, 0);
end;
That's not necessary. Never has been. In Win32, inputMsg is a dynamic array that gets cleaned up automatically when it goes out of scope. In ..Net, inputMsg is a System.Array object that gets cleaned up by the garbage collector, just like all other objects.
end;
You're reading 60 bytes of input. Your record has two arrays for storing 120 bytes. How do you wish to distribute that?
Here's one way:
x := 0;
for i := 1 to 38 do begin
MyTest.t1[i] := Chr(inputMsg[x]);
Inc(x);
end;
for i := 1 to 22 do begin
MyTest.t2[i] := Chr(inputMsg[x]);
Inc(x);
end;
--
Rob
.
- References:
- Delphi.NET
- From: Daniel Hobson
- Re: Delphi.NET
- From: Rob Kennedy
- Re: Delphi.NET
- From: Daniel Hobson
- Re: Delphi.NET
- From: kennedyri
- Re: Delphi.NET
- From: Daniel Hobson
- Delphi.NET
- Prev by Date: Re: TWebbrowser plugin support
- Next by Date: Re: Datatype checking in DotNET
- Previous by thread: Re: Delphi.NET
- Next by thread: Re: minimize button on a delphi created mainwindow not working on an XP system
- Index(es):