Re: Delphi.NET



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


.



Relevant Pages

  • Re: Initializing variables
    ... Static tempHiWater As Variant ... Rick (MVP - Excel) ... always use another variable as an initialization switch too, ...
    (microsoft.public.excel)
  • Re: Initializing variables
    ... Rick ... If you still wanted to try the approach, and didn't mind using a Variant, then you could do it this way... ... On second thought maybe it's easier just to have another variable as an initialization switch. ... As long as MyVariable is never reset to 0, it will retain the last value assigned to it whenever the function is called (the Static rather than Dim statement sees to that). ...
    (microsoft.public.excel)
  • Re: Initializing variables
    ... If you still wanted to try the approach, and didn't mind using a Variant, then you could do it this way... ... On second thought maybe it's easier just to have another variable as an initialization switch. ... As long as MyVariable is never reset to 0, it will retain the last value assigned to it whenever the function is called (the Static rather than Dim statement sees to that). ...
    (microsoft.public.excel)
  • Re: Initializing variables
    ... Function FooAs Variant ... another variable as an initialization switch too, ... Dim statement sees to that). ...
    (microsoft.public.excel)
  • Re: Initializing variables
    ... Function FooAs Variant ... another variable as an initialization switch too, ... Dim statement sees to that). ...
    (microsoft.public.excel)