Re: Delphi.NET
- From: Daniel Hobson <daniel@xxxxxxxxxxxxxx>
- Date: Tue, 26 Jun 2007 22:40:38 GMT
Tom,
You cannot do this either in Turbo Delphi.NET.
Since arrays need initialization, .NET will not allow this in a variant type record.
Borland help states on the error:-
Type '%s' needs initialization - not allowed in variant record (E2418)
Type needs initialization - not allowed in variant record. Variant records do not allow types that need initialization in their variant field list since each variant field references the same memory location. As an example, the following code will not compile because the array type needs to be initialized.
program Project3;
{$APPTYPE CONSOLE}
type
TFoo = record
case Boolean of
True: (bar: Integer);
False: (baz: array [0..2] of Integer);
end;
end.
Any other ideas?
Thanks
Daniel.
Tom de Neef wrote:
"Daniel Hobson" <djhob1972@xxxxxxxxxxxx> schreef in bericht news:tI3gi.91$iq2.28@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.Hi All,
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 ????
In a traditional Pascal sense you could use a variant record:
TTestRec = record
case proper: boolean of
true: ( t1: array [1..32] of char; t2: array [1..28] of char);
false: (test : array[1..60] of byte);
end;
Since you cannot use a fixed length array in the TCP/IP routine, combine this with:
move(MyBuffer[0],MyActType.test[1],60);
MyActType.t1 and .t2 are accessible in the normal way and will contain the respective parts of the buffer.
Tom
- Follow-Ups:
- Re: Delphi.NET
- From: Hans-Peter Diettrich
- Re: Delphi.NET
- References:
- Delphi.NET
- From: Daniel Hobson
- Re: Delphi.NET
- From: Tom de Neef
- Delphi.NET
- Prev by Date: Re: Delphi.NET
- Next by Date: Re: Accessing the sectors of an harddisk
- Previous by thread: Re: Delphi.NET
- Next by thread: Re: Delphi.NET
- Index(es):
Relevant Pages
|