Results 1 to 9 of 9

Thread: Pointers to records in Delphi .NET

  1. #1

    Pointers to records in Delphi .NET

    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? :?

  2. #2

    Pointers to records in Delphi .NET

    To my knowledge, Delphi 7 tells me using pointers in normal executables is unsafe too. So i've had it disabled in compiler hints.

  3. #3

    Pointers to records in Delphi .NET

    Quote Originally Posted by User137
    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.

  4. #4

    Pointers to records in Delphi .NET

    Well then, i guess indexes and object oriented approaches work for the problem

  5. #5

    Pointers to records in Delphi .NET

    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.

  6. #6
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Pointers to records in Delphi .NET

    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...)
    NecroSOFT - End of line -

  7. #7

    Pointers to records in Delphi .NET

    I'll check that thanks!

  8. #8

    Pointers to records in Delphi .NET

    Quote Originally Posted by cronodragon
    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.

  9. #9

    Pointers to records in Delphi .NET

    Well, I finally solved the problem using operator overloading. Haven't had any more problems with that.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •