PDA

View Full Version : Pointers to records in Delphi .NET



cronodragon
03-10-2007, 03:40 PM
Sometimes I used to pass pointers to records, so I could test them with nil like this:

procedure doSomething(aRec: PRec);
begin

if aRec = nil then
begin
// the record is not present, do something in this case
end else
begin
// the record is present, use it!
end;

end;

But now in .NET pointers to records are unsafe. I want to produce safe code only. What can I do instead? :?

User137
03-10-2007, 03:55 PM
To my knowledge, Delphi 7 tells me using pointers in normal executables is unsafe too. So i've had it disabled in compiler hints.

cronodragon
03-10-2007, 04:13 PM
To my knowledge, Delphi 7 tells me using pointers in normal executables is unsafe too. So i've had it disabled in compiler hints.

That's right, but in Win32 it doesn't matter, in .NET is does, for example when you publish for the XBox... at least that's what I have read. :)

User137
03-10-2007, 11:15 PM
Well then, i guess indexes and object oriented approaches work for the problem :)

cronodragon
04-10-2007, 02:25 PM
Yes, it's a solution, but not very compatible with Win32, since objects are still created only in heap memory, not in the stack like records. Using objects instead of records would require adding lots of {$IFDEF Win32} and {$IFDEF CLR}, and one should avoid that to keep the code readable.

NecroDOME
04-10-2007, 07:13 PM
I think you can directly use TRec as pointer. Internally most things are handled as pointer? Not sure...

(I work as C# (.NET) programmer now for 4 weeks, so I'm also learning...)

cronodragon
04-10-2007, 07:37 PM
I'll check that thanks! :D

marcov
28-10-2007, 12:21 PM
Yes, it's a solution, but not very compatible with Win32, since objects are still created only in heap memory, not in the stack like records. Using objects instead of records would require adding lots of {$IFDEF Win32} and {$IFDEF CLR}, and one should avoid that to keep the code readable.

Yes, but you can't simply escape the fact that a VM and GC is totally different from a native language.

IMHO Delphi and Delphi.NET should have a separate group. The biggest thing they have in common is their name.

cronodragon
29-10-2007, 08:19 PM
Well, I finally solved the problem using operator overloading. :D Haven't had any more problems with that.