Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 35

Thread: New Delphi features since Delphi 7

  1. #21

    New Delphi features since Delphi 7

    Ohhh... If only FPC had class vars... :roll: Then I'd avoid headache with hacking the vmt to store the class-specific indexes when I wrote my persistency system.

    Anyone knows if the said aboveapplies to Turbo Explorer? I'm too lazy to reboot my system to WinXP and check for myself. ops:

  2. #22

    New Delphi features since Delphi 7

    I found most of them to work in the win32 edition of turbo explorer
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #23

    New Delphi features since Delphi 7

    Quote Originally Posted by Chebmaster
    Ohhh... If only FPC had class vars... :roll: Then I'd avoid headache with hacking the vmt to store the class-specific indexes when I wrote my persistency system.
    class vars are not virtual that is, not every derived class has its own field, they are shared...it's just a form of a global variable tied to the class type and accessible in other classes when declared as public or protected....what you would need is a "virtual class var" which would be class-type specific....such a thing does not exist and I do not even know any language which implements a construct like that....

  4. #24

    New Delphi features since Delphi 7

    class vars are not virtual that is, not every derived class has its own field, they are shared...it's just a form of a global variable
    Crap. :evil: I just discovered that by myself. So much for idea to free my prog from the hacks.

  5. #25

    New Delphi features since Delphi 7

    Well, there's one idea that *might* work without hacks... All your classes are placed in a solid block of memory, right? It's not that big, they all fit in approx. 100 Kbytes. So if you aren't short of memory, you can create a dynamic array of pointers to your *real* class vars, and treat the classes as integers, substract some offset and use them directly to index the array. Of course, you need some additional code to correct the array size and the offset on the fly if some class doesn't fit.

    [pascal]
    type
    PCVData = ^CVData;
    CVData = record
    ...//your class vars
    Fruits: TOranges;
    end;
    TMyClass = class
    ...
    class function Oranges: TOranges;
    end;

    var
    CVOffset: dword;
    CVData: array of PCVData;

    ...

    class function Oranges: TOranges;
    begin
    <code to check boundaries and grow the array if necessary>
    Result:=CVData[(dword(ClassType()) shr 4) - CVOffset]^.Fruits;
    end;
    [/pascal]

    -- and no any hacks ^_^

  6. #26

    New Delphi features since Delphi 7

    yes, this is possible, you could hash the class reference pointer into the array, it would not be that hard you just cannot access "inherited virtual fields" this way

  7. #27

    New Delphi features since Delphi 7

    A virtual class variables implementation. With hacks, of course.

    http://hallvards.blogspot.com/2007/0...es-part-i.html

  8. #28

    New Delphi features since Delphi 7

    Almost exactly what I did. Except two facts:
    1). in FreePascal VMT is not write-protected, so I didn't stumble to the problem until I ported my stuff to Delphi.
    2). VirtualProtect I know, but what the hell does FlushInstructionCache(GetCurrentProcess, Code, SizeOf(Code^)); do? :shock:

  9. #29

    New Delphi features since Delphi 7

    It removes cached code from the instruction cache. The snippet just modified the code at runtime. If the cache isn't flushed the old code might be executed
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #30

    New Delphi features since Delphi 7

    Do records with methods work in the same way as classes in C++, in the way that they are disposed automatically? :?

Page 3 of 4 FirstFirst 1234 LastLast

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
  •