Recent

Author Topic: What is the difference between the new ADVANCED RECORD and the old OBJECT?  (Read 24506 times)

ASerge

  • Hero Member
  • *****
  • Posts: 1904
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #30 on: October 01, 2018, 08:11:52 pm »
FeatureRecordObjectClass
Encapsulation (combining data and methods + hiding visibility)YesYesYes
InheritanceNoYesYes
Class constrcutor and destrutorYesYesYes
Polymorphism (virtual methods)NoYesYes
Memory allocationStackStackHeap
Operator overload (global)YesYesYes
Operator overload (in type only)YesNoNo
Type helpersYesNoYes
Virtual constructors, class referenceNoNoYes
Variant part (case) as c++ unionYesNoNo
Bitpacked (really packing)YesNoNo

Added a variant part and bitpacked. Thanks @howardpc and @JernejL.

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #31 on: October 01, 2018, 08:38:06 pm »
@ASerge
objects can be bitpacked....
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. type
  3.   Ttest = bitpacked object
  4.   end;
  5. begin
  6. end.

objects can contain overloads, but the syntax is different and a constructor is required. You need to use the virtual keyword again, "overload" is for classes post TP era. It does the same, however...
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. type
  3.   Ttest = bitpacked object
  4.     constructor init;
  5.     procedure testme;virtual;
  6.   end;
  7.  
  8.   Ttest2 = bitpacked object
  9.     constructor init;
  10.     procedure testme;virtual;
  11.   end;
  12.  
  13.   constructor TTest.Init;
  14.   begin
  15.   end;
  16.  
  17.   constructor TTest2.Init;
  18.   begin
  19.   end;
  20.  
  21.   procedure TTest.TestMe;
  22.   begin
  23.   end;
  24.  
  25.   procedure TTest2.TestMe;
  26.   begin
  27.   end;
  28.    
  29. begin
  30. end.

Maybe a bit rusty on TP syntax? This code compiles -Sew
Mode delphi is also OK.

« Last Edit: October 01, 2018, 08:49:29 pm by Thaddy »
You have morons, I am one, and you have morons squared.

ASerge

  • Hero Member
  • *****
  • Posts: 1904
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #32 on: October 01, 2018, 10:09:52 pm »
objects can be bitpacked....
Carefully read "really packing". In you example bitpacked the same as packed. Packed supported by objects.

JernejL

  • Jr. Member
  • **
  • Posts: 92
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #33 on: October 02, 2018, 07:32:21 am »
So, are packed and bitpacked supported on objects?

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #34 on: October 02, 2018, 07:57:04 am »
packed is supported.
bitpacked is at least accepted as valid syntax for objects. I have to test if it does more than just packed based on packsettings 1.
« Last Edit: October 02, 2018, 08:12:18 am by Thaddy »
You have morons, I am one, and you have morons squared.

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #35 on: October 02, 2018, 09:27:33 am »
Carefully read "really packing". In you example bitpacked the same as packed. Packed supported by objects.
I can't find any documentation for that, but a test showed you right.
Code: Pascal  [Select][+][-]
  1. {$ifdef fpc}{$mode objfpc}{$endif}
  2. type
  3.   TByteBitsRec = bitpacked record
  4.     Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7: Boolean;
  5.   end;
  6.  
  7.   TByteBitsObj = bitpacked object
  8.     Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7: Boolean;
  9.   end;
  10.  
  11.   TEmptyRec = bitpacked record
  12.   end;
  13.  
  14.   TEmptyObj = bitpacked object
  15.   end;
  16.  
  17. var
  18.   a:TByteBitsRec;
  19.   b:TByteBitsObj;  
  20.   c:TEmptyRec;
  21.   d:TEmptyObj;
  22. begin
  23.   writeln(SizeOf(a)); // 1 byte
  24.   writeln(SizeOf(b)); // 8 bytes
  25.   writeln(SizeOf(c)); // 0 bytes
  26.   writeln(SizeOf(d)); // 0 bytes
  27. end.

Which makes you wonder if that is not a bug (either bitpack objects or do not accept the syntax)
« Last Edit: October 02, 2018, 09:30:03 am by Thaddy »
You have morons, I am one, and you have morons squared.

440bx

  • Hero Member
  • *****
  • Posts: 2623
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #36 on: October 02, 2018, 02:32:56 pm »
Which makes you wonder if that is not a bug (either bitpack objects or do not accept the syntax)
FWIW, it should probably be considered a bug since the Free Pascal Reference Guide, Chapter 5, section 5.1 does _not_ list "bitpacked" as an option when declaring objects, only "packed" is shown as being syntactically acceptable.

Either the compiler should reject "bitpacked" in an object declaration or, the documentation should be updated to show it is acceptable.

NOTE: Free Pascal Reference Guide for version 3.0.2 (February 2017)

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #37 on: October 02, 2018, 02:40:53 pm »
I already filed a bug against the issue. I drew the same conclusion and there really aren't any docs about it (including trunk docs). Unless you count ASerge observation as documentation. 8-) Which some do. Anyway he was right and it was easy to prove.

That leaves management operators to be filled in to the matrix.
And that classes are a pointer-to-structure and not a structure itself.
And that objects can mimic virtual constructors (for that reason) with constructing functions returning a pointer to object. (Like in KOL)
And some memory management oversights for classes like initinstance
« Last Edit: October 02, 2018, 02:52:23 pm by Thaddy »
You have morons, I am one, and you have morons squared.

440bx

  • Hero Member
  • *****
  • Posts: 2623
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #38 on: October 02, 2018, 06:41:00 pm »
and there really aren't any docs about it (including trunk docs)
There are no docs about it... other than the Free Pascal Reference Guide (of course... for you, that's not documentation.)
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #39 on: October 02, 2018, 07:24:32 pm »
and there really aren't any docs about it (including trunk docs)
There are no docs about it... other than the Free Pascal Reference Guide (of course... for you, that's not documentation.)
If I refer to documentation it is always the true documentation, but there is no reference to bitpacked objects in the reference guide.
That does not mean that would not exist.....
I almost monthly report on omissions, unclear or wrong fragments of documentation. This is usually very quickly repaired or explained.
"There are more things in heaven and earth, Horatio,  Than are dreamt of in your philosophy." read: documentation can cover...
- Hamlet (1.5.167-8), Hamlet to Horatio
You have morons, I am one, and you have morons squared.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2720
    • havefunsoft.com
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #40 on: October 02, 2018, 07:50:35 pm »
If I refer to documentation it is always the true documentation, but there is no reference to bitpacked objects in the reference guide.
FreePascal Reference Guide - 3.3 Structured Types
Quote
However, Free Pascal allows controlling the layout with the Packed and Bitpacked keywords. The meaning of these words depends on the context:
...
When using the bit packing mechanism, the compiler calculates for each ordinal type how many bits are needed to store it. The next ordinal type is then stored on the next free bit. Non-ordinal types - which include but are not limited to - sets, floats, strings, (bitpacked) records, (bitpacked) arrays, pointers, classes, objects, and procedural variables, are stored on the first available byte boundary.
« Last Edit: October 02, 2018, 07:53:15 pm by skalogryz »

Thaddy

  • Hero Member
  • *****
  • Posts: 11136
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #41 on: October 02, 2018, 08:50:08 pm »
Which is - by all means - incorrect, or at least imprecise - for the issue at hand.
An object can not be / is not bitpacked.
There is still an open issue regarding this on Mantis from 8 years ago.

Doc fix is OK with me, but it should be a compiler fix.

That said: for most this will remain a minor issue. To me it is not.(KOL, although I do not use that much, let alone are involved anymore)
« Last Edit: October 02, 2018, 08:56:21 pm by Thaddy »
You have morons, I am one, and you have morons squared.

440bx

  • Hero Member
  • *****
  • Posts: 2623
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #42 on: October 02, 2018, 09:57:57 pm »
It's unfortunate that the compiler allows "bitpacked" in an object declaration as it may lead a programmer to believe the object is actually bitpacked when it isn't.

If the compiler allows the use of "bitpacked" when declaring an object then the documentation, i.e, the Free Pascal Reference Guide, should clearly state that its presence has no effect on the object's fields.  In that case, the documentation should also be updated to reflect that the use of "bitpacked" is allowed in an object declaration (it currently doesn't.)




FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1195
    • formatio reticularis
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #43 on: February 17, 2021, 09:35:27 pm »
First there were record, procedures and functions.
Next, with the emergence of OOP, there were objects.
Next, Borland has introduced classes in which there are additional opportunities. And to force everyone to switch to a new way of declaration, a objects was sign as deprecated.
Later, when it was necessary to merge fields and methods again, it was already inconvenient to revive objects declared as deprecated. And decided to expand records.
And, accordingly, all the new features have tried to do only for records, skipping the implementation for objects, so that they correspond to the previously established policy. And either intentionally made mistakes in the support of old objects, or rather greatly inflated random errors to convince not to use objects.

The classes concept already existed in the Clascal language for Apple's Lisa computer (the earliest object-oriented Pascal dialect), but it was abandoned by Larry Tesler after being advised by Niklaus Wirth. Later, classes were reintroduced by Borland for Delphi.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.0.12 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

egsuh

  • Hero Member
  • *****
  • Posts: 869
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #44 on: February 20, 2021, 02:19:29 am »
Quote
Feature                                    Record     Object        Class
Class constrcutor and destrutor   Yes           Yes            Yes

The constructor for record is not really constructor. Memory is allocated by the definition of a record variable, and its constructor does only the initializing functions.

Destructors are not allowed for record.

 

TinyPortal © 2005-2018