Results 1 to 9 of 9

Thread: class of TMyObject

  1. #1

    class of TMyObject

    I'm working to switch fully to FPC, and I need to know something I'm struggling to find in the documentation. In Delphi I can declare the following type:
    Code:
    type
      TTypeOfMyStuff = class of TMyObject;
    When I assign a variable this type I can point it at any descendant class, and from there even call a constructor and anonymously create that object. How do I do this in FPC? I want to be able to serialize my game, for saving it of course, and in doing so specify the types of objects and let them unserialize themselves. Of course I must first be able to recognize and point at the class itself.

    Thanks in advance.

  2. #2

    class of TMyObject

    In FPC this work just as in Delphi.

  3. #3

    class of TMyObject

    Okay, thanks. I couldn't find anything on it.

    Does it work in OBJFPC mode and/or Delphi compatibility? And does the object/class difference cause any problems, to the best of your knowledge?

  4. #4

    class of TMyObject

    From the FPC programmer's manual (Agoust 2006):
    D.3 Delphi mode
    This mode is selected by the $MODE DELPHI switch. It tries to emulate, as closely as possible, the behavior of Delphi 4. On the command-line, this mode is selected by the -Mdelpih switch.

    1. You can not use the address operator to assign procedural variables.
    2. A forward declaration must not be repeated exactly the same by the implementation of a function/procedure. In particular, you not omit the parameters when implementing the function or procedure.
    3. Overloading of functions is not allowed.
    4. Nested comments are not allowed.
    5. The Objpas unit is loaded right after the system unit. One of the consequences of this is that the type Integer is redefined as Longint.
    6. Parameters in class methods can have the same names as class properties (although it is bad programming practice).


    D.5 OBJFPC mode
    This mode is selected by the $MODE OBJFPC switch. On the command-line, this mode is selected by the -Mobjfpc switch.

    1. You must use the address operator to assign procedural variables.
    2. A forward declaration must be repeated exactly the same by the implementation of a function/procedure. In particular, you can not omit the parameters when implementing the function or procedure.
    3. Overloading of functions is allowed.
    4. Nested comments are allowed.
    5. The Objpas unit is loaded right after the system unit. One of the consequences of this is that the type Integer is redefined as Longint.
    6. You can use the cvar type.
    7. PChars are converted to strings automatically.
    8. Parameters in class methods cannot have the same names as class properties.
    I never used the OBJECT style. I've read the documentation but I find it a bit confusing (the documentation not the OBJECT style) and I'm comfortable with CLASS.
    No signature provided yet.

  5. #5

    class of TMyObject

    Which manual are you getting that from? I have the PDF documentation for FPC, but I can't seem to find the section you're referencing.

    It seems that is referencing procedural variables, but I'm talking more about a "objective" variables. AKA, a pointer to a type. For instance all types descend from the base type, and the standard base constructor is called by a lookup table. That's pretty much what I'm after.

    But I guess I could achieve something similar through a case statement and a class-type integer. :?

  6. #6

    class of TMyObject

    You can read it on-line from here: http://www.freepascal.org/docs-html/

    I downloaded all documentation from here: http://www.freepascal.org/down/docs/docs.var

    I hope it helps you.
    No signature provided yet.

  7. #7

    class of TMyObject

    Yes, I said it twice, but I have the documentation. Anyway, those sections are helpful with what mode restrictions there are, but not with this problem in particular.

  8. #8

    class of TMyObject

    I use the "class of ..." construction for serialization/deserialization as well and it works under Delphi and FPC. For FPC I used both DELPHI and OBJFPC modes. In OBJFPC DirectX 8 headers which I use won't compile, but my own code compiles. With DELPHI mode it compiles and runs.
    "class of ..." is working only for classes not for objects.
    Actually there are some strange bugs in my application compiled with FPC but serialization/deserialization works well.

  9. #9

    class of TMyObject

    Class of works fine, I use it every day.

    Ported Delphi software often is buggy on FPC/Lazarus, but usually they are simply bugs in the app that are not noticable on Delphi. It is similar with the move to Kylix in the Borland scene, where the same happened.

    A _very_ important point for gamers , is that you should only draw in a components onpaint event, and never outside of it.

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
  •