my adventure on making a markdown renderer with slightly more function continues

.. I have this linked list and class definition :
unit TDocument;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, TRenderObjects, TBlockIdentifierEngine;
type
SectionNodePTR = ^NodeStruct;
NodeStruct = packed record
rendObj : Variant;
ID : Integer;
Parent : SectionNodePTR;
Children : Array of SectionNodePTR;
objType : TBlockIdentifierEngine.classificationEnum;
end;
TNodeArray = Array of NodeStruct;
{ markedDocument }
markedDocument = class
// Sections : Array of TRenderObjects.Section;
public
nodeTree : NodeStruct;
constructor Create();
procedure AppendNode(var ChildObj : NodeStruct);
procedure AppendObject_asNode(var insertionObject : variant; var ID : integer; var objType : TBlockIdentifierEngine.classificationEnum);
end;
The
classificationEnum is defined as :
classificationEnum = (localCommand, globalCommand, renderTarget, unknown, highLightCommand);
- this definition is in a different file:
tblockidentifierengine.pas . This works.
I want to add every block of renderable text (starting and ending with a newline) as well as every command block (starting with a . or period and ending with a ; or semicolon) as document nodes. The nodes will be marked either as renderTarget or as various commands. So The function is defined as:
procedure markedDocument.AppendObject_asNode(var insertionObject: variant;
var ID: integer; var objType: TBlockIdentifierEngine.classificationEnum);
var
newNode : NodeStruct;
currNode : NodeStruct;
begin
newNode.rendObj := insertionObject;
newNode.ID := ID;
newNode.objType := objType;
if nodeTree = nil then
begin
nodeTree := newNode;
end
else
begin
currNode := nodeTree;
while length(currNode.Children) <> 0 do
begin
currNode := currNode.Children[0];
end;
SetLength(currNode.Children, length(currNode.Children) + 1);
currNode.Children[length(currNode.Children) -1] := newNode;
end;
end;
This is called as:
classInstance.AppendObject_asNode("some text",0,a tesst enum value); But this does not compile. It tells me:
In the line:
Error: Operator is not overloaded: "NodeStruct" = "Pointer"I was hoping that, I can find out if the root
NodeStruct in the class instance is populated or not via comparing it with
nil. My plan is to add every block (text or command as described above) as a node in a linked list. In this list, each element is a
Nodestruct. The first element of the linked list is denoted as
nodeTree in the class. So if I see that the
nodeTree is not set in an instance of the class, it will mean that that first element of the linked list is not set. So we can set the newly created
NodeStruct with the incoming block directly as the
nodeTree.
Moreover, I also tried with:
if markedDocument.nodeTree = nil then
In that case, It tells me, that in the same line:
Only class methods, class properties and class variables can be referred with class referencesAlso, in this line:
currNode := currNode.Children[0];
I get an error:
Error: Incompatible types: got "SectionNodePTR" expected "NodeStruct".
I read that objects are already pointers, so there is no need to dereference them. But seems that is not the case?
I have a similar error in this line.
currNode.Children[length(currNode.Children) -1] := newNode;
But I will be able to address that as soon as I have addressed the #2 error.
Please help. Thank you.