[fpc-pascal] WHY compiler should be public?
Xiangrong Fang
xrfang at gmail.com
Sun Oct 27 03:05:59 CET 2013
2013/10/25 Michael Van Canneyt <michael at freepascal.org>
> Why not simply make it a procedure that is called by ver-2 and ver-3.
>
> If it cannot be called directly from external code, and will called only
> from inside a visible consructor, there is simply no reason to make this
> procedure a constructor. A simple procedure will do.
Because I don't know how to make it non-constructor. See the following
code:
1 unit wtree;
2 {$mode objfpc}{$H+}
3 interface
4 uses tree;
5 type
6 TQWordTree = specialize TTree<QWord>;
7 TWTree = class(TQWordTree)
8 private
9 FModel: string;
10 public
11 property Model: string read FModel;
12 constructor Create(AData: QWord; AParent: TWTree; AModel: string);
13 constructor Create(HeadNode, TailNode: QWord);
14 end;
15 implementation
16
17 constructor TWTree.Create(AData: QWord; AParent: TWTree; AModel:
string);
18 begin
19 inherited Create(AData, AParent);
20 FModel := AModel;
21 end;
22
23 constructor TWTree.Create(HeadNode, TailNode: QWord);
24 begin
25 inherited Create(0, nil);
26 Data := HeadNode;
27 with TWTree do Create(TailNode, Create(HeadNode, Self, 'h'), 't');
28 FModel := 'R';
29 end;
30
31 end.
Please tell me how to deal with line 27, which called the should-be-private
constructor.
BTW, this code uses TTree class, which is here:
https://github.com/xrfang/fpcollection/blob/master/src/units/tree.pas
Also,
I don't understand why this does not work:
f := TFileStream.Create;
I know that TFileStream's Create require a file name parameter, but as
TFileStream is inherited from TObject, which has a Create without
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20131027/154f5755/attachment.html>
More information about the fpc-pascal
mailing list