Recent

Author Topic: Records and class name  (Read 6523 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Records and class name
« on: October 16, 2010, 10:39:33 am »
Hi,

Are records store information of own class name? I mean, in standard object I have such functions as ClassName, ClassType, InheritsFrom. Can I somehow read this information from the records?

Regards

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1937
Re: Records and class name
« Reply #1 on: October 16, 2010, 10:50:45 am »
How can a record have a classname?
A record is not a class.

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Records and class name
« Reply #2 on: October 16, 2010, 11:12:20 am »
Yes, but I was wondering if there is any way to check type of record

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12209
  • Debugger - SynEdit - and more
    • wiki
Re: Records and class name
« Reply #3 on: October 16, 2010, 11:30:39 am »
No there isn't.

And there is (should be) no need.

You know the type.
  var a: TFooRecord;
"a" will always contain a TFooRecord, never anything else

var a: TFooClass
"a" could contain TInheritedFromFooClass., so you do not know.

There is of course a case: if you use untyped pointers, then you may not know what your pointer points too.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Records and class name
« Reply #4 on: October 18, 2010, 04:47:47 am »
There is actually, through RTTI. But that's not necessary in most cases. For classes, ClassType, ClassName, InheritsFrom etc. exist due to dynamic behavior of a class. The case is not the same with record since record doesn't have inheritance.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12209
  • Debugger - SynEdit - and more
    • wiki
Re: Records and class name
« Reply #5 on: October 18, 2010, 10:20:11 am »
There is actually, through RTTI.

You are referring to classes, records, or both?

That there is for classes was never disputed, but neither in question.

If you refer to Records, then that's news to me...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Records and class name
« Reply #6 on: October 19, 2010, 04:06:18 am »
Quote
If you refer to Records, then that's news to me...
Yes, I'm referring to records. AFAIK RTTI works for ANY type.

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Records and class name
« Reply #7 on: October 19, 2010, 07:13:53 am »
Something like this?

//Class;
type
  TTemplate = class
    public
      tpt:        Pchar;
      size:       Integer;
      id:         Integer;
      constructor Create;
      destructor Destroy; override;
  end;

  TDBClass = class
  private
    dsTemplates: TSQLQuery;
    connection: TODBCConnection;
    SQLTransact: TSQLTransaction;
    tptBlob: TTemplate;
  public
    function openDB(): boolean;
    procedure closeDB();
  end;



//Record;
type
  TCars = record
  name: string[30];
  price: Integer;
end;
ShowRoom = array of TCars; 

var
CarRoom: ShowRoom;

 

TinyPortal © 2005-2018