Results 1 to 6 of 6

Thread: Does pascal have reflection?

  1. #1

    Does pascal have reflection?

    I like to use reflection to make save game files with serialization. does this exist for pascal?

  2. #2
    In a way it does. You have RTTI for published properties of persistent objects(classes inheriting from TPersistent). Normal component streaming with the TStream makes serialization possible, but it's somewhat rigid. It'll do a lot, but not everything, and you have to be very careful about your design

    So in conclusion; I wouldn't use it for anything complicated
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3
    thanks I found this http://wiki.freepascal.org/tiOPF
    I may try to save objects in CSV format

    If I had a Type called Car and some other types that extend it e.g. (ford ,honda,chevy)

    could I use RTTI to get the names of the types(ford, honda etc.)
    then create buttons with the names

    then when the user clicks on a button use RTTI to create an instance of the selected car (ford, honda)?

  4. #4
    Quote Originally Posted by slenkar View Post
    If I had a Type called Car and some other types that extend it e.g. (ford ,honda,chevy)

    could I use RTTI to get the names of the types(ford, honda etc.)
    Yes.
    Code:
    type
      Car = class(TObject)
      end;
    
      Honda = class(Car)
      end;
    
    var
      HondaCar: Honda;
    begin
      HondaCar := Honda.Create();
      try
        ShowMessage(HondaCar.ClassName); 
      finally
        FreeAndNil(HondaCar);
      end;
    end;

  5. #5
    thanks, could i get a list of all the types that extend car?

    I want to put a menu on the screen to let the player choose a car to drive

    then when the player chooses a car, could i use the text (e.g. Ford, Honda) to create an instance of that type of car?

  6. #6
    can I create an object with a text string of its name?

    if not, could i have a little example program of turning an object into a stream and vice-versa?
    Last edited by slenkar; 24-11-2010 at 04:40 AM.

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
  •