Forum > General

Contradiction in Documentation?!?!?

(1/3) > >>

Zvoni:
Hi Folks,
stumbled across this one:
https://www.freepascal.org/docs-html/current/ref/refse61.html#x120-1440009.1


--- Quote ---Some of the restrictions when compared to classes or objects are obvious from the syntax diagram:

    No inheritance of records.
    No published and protected section exists.
    Constructors or destructors cannot be defined.
    Class methods (if one can name them so) require the static keyword.
    Methods cannot be virtual or abstract – this is a consequence of the fact that there is no inheritance.
--- End quote ---

Further down at the examples:

--- Quote ---TTest4 = record 
 private 
   a : Integer; 
 protected 
   function getp : integer; 
 public 
   b : string; 
   procedure setp (aValue : integer); 
   property p : integer read Getp Write SetP; 
 public 
 case x : integer of 
   1 : (Q : string[10]); 
   2 : (S : String[10]); 
 end;
--- End quote ---

Huh???

VisualLab:
I made a small test with the code provided in the documentation (I supplemented it with the content of the methods). An attempt to compile such a test ends with the compiler message:


--- Quote ---unit1.pas(38,3) Error: Visibility section "PROTECTED" not allowed in records
--- End quote ---


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+}{$modeswitch advancedrecords}//{$mode Delphi}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type  TTest1 = record    A: Integer;    function Test(ARecurse: Boolean): Integer;  end;   TTest2 = record  private    FA, FB: Integer;  public    procedure SetA(AValue : Integer);    property SafeA: Integer read FA write SetA;  end;   TTest3 = packed record  private    FA, FB: Byte;    function GetA: Integer;    procedure SetA(AValue: Integer);  public    property A: Integer read GetA write SetA;  end;   TTest4 = record  private    FA: Integer;  protected    function GetP: Integer;  public    B: string;    procedure SetP(AValue: Integer);    property P: Integer read GetP write SetP;  public  case X: Integer of    1: (Q: string[10]);    2: (S: String[10]);  end;   TForm1 = class(TForm)  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} function TTest1.Test(ARecurse: Boolean): Integer;begin  Result := 0;  if ARecurse   then Result := A;end; procedure TTest2.SetA(AValue : Integer);begin  if FA <> AValue   then FA := AValue;end; function TTest3.GetA: Integer;begin  Result := FA;end; procedure TTest3.SetA(AValue: Integer);begin  if FA <> AValue   then FA := AValue;end; function TTest4.GetP: Integer;begin  Result := FA;end; procedure TTest4.SetP(AValue: Integer);begin  if FA <> AValue   then FA := AValue;end; end.
The compiler reports this for both modes: Delphi and ObjFPC. You can see it in the attachment.

VisualLab:
While we're on the subject of FPC documentation, I found this on 6.6.5 Class constructors and destructors website:


--- Quote ---There are some caveats when using class destructors/constructors:

* There may be only one constructor per class. The name is arbitrary, but it can not have parameters.
* There may be only one destructor per class. The name is arbitrary, but it can not have parameters.
* Neither constructor nor destructor can be virtual.
* The class constructor/destructor is called irrespective of the use of the class: even if a class is never used, the constructor and destructor are called anyway.
--- End quote ---

But after reviewing a few FCL or LCL library files, it is immediately obvious that:

* There can be many constructors and they can be overloaded (which is quite common),
* The constructor can have parameters (arguments) and any number of them (i.e. none, 1 or more),
* Constructors and destructors can be virtual, of course one parameterless (i.e.: without any arguments) destructor per class,
* Is it true that a class constructor/destructor is called independently of the class usage (even if the class is never used)? And if only class methods are used (i.e.: class procedure), then what? Why would a class instance be created then?
Note: This is not documentation on object constructors and destructors. That is provided at 5.5 Constructors and destructors .

Maybe I missed something, or didn't understand something. Or the editing of this part of the documentation was not finished and is incomplete.

AlexTP:
Maybe report both issues to the https://gitlab.com/freepascal.org/fpc/documentation/-/issues ?

Zvoni:

--- Quote from: AlexTP on January 08, 2025, 07:36:17 pm ---Maybe report both issues to the https://gitlab.com/freepascal.org/fpc/documentation/-/issues ?

--- End quote ---
Will do tomorrow, at least my own

EDIT: https://gitlab.com/freepascal.org/fpc/documentation/-/issues/39412

Navigation

[0] Message Index

[#] Next page

Go to full version