Recent

Author Topic: HelpNDoc.com and Pascal  (Read 325 times)

paule32

  • Sr. Member
  • ****
  • Posts: 320
HelpNDoc.com and Pascal
« on: February 08, 2025, 05:36:17 pm »
Hello,
currently, I play with the Help authoring Tool www.HelpNDoc.com and its Pascal Script Editor and Pascal Engine.
I can use TStringList, but I would like implement a own Version of this Class.
For this, I have the following Code:

Code: Pascal  [Select][+][-]
  1. unit GenericTemplate;
  2.  
  3. interface
  4.  
  5. type
  6.   TVariantType = (
  7.     vtEmpty,
  8.     vtBoolean,
  9.     vtChar,
  10.     vtInteger,
  11.     vtString );
  12.  
  13.   TVariant = record
  14.     VarType = record
  15.       vtBoolean: Boolean;
  16.       vtChar:    Char;
  17.       vtInteger: Integer;
  18.       vtString:  String;
  19.     end;
  20.   end;
  21.  
  22. type
  23.   TStringNode = class(TObject)
  24.   public
  25.     data: string;
  26.     prev, next: TStringNode;
  27.     constructor Create(const p: TStringNode; const n: TStringNode); overload;
  28.     constructor Create(const p: TStringNode); overload;
  29.     constructor Create; overload;
  30.   end;
  31.  
  32. type
  33.   TStringArray = class(TObject)
  34.   private
  35.       PNode: TStringNode;
  36.       Head: TStringNode;
  37.       FCount: Integer;
  38.   public
  39.     constructor Create(InitialSize: Integer = 0);
  40.     procedure Add(const AValue: String);
  41. (*    function Get(Index: Integer): String;
  42.     procedure SetValue(Index: Integer; const Value: String);*)
  43.     function Count: Integer;
  44.   end;
  45.  
  46. implementation
  47.  
  48. { TStringNode }
  49.  
  50. constructor TStringNode.Create;
  51. begin
  52.   inherited Create;
  53.   prev := nil;
  54.   next := nil;
  55. end;
  56.  
  57. constructor TStringNode.Create(const p: TStringNode);
  58. begin
  59.   inherited Create;
  60.   if p = nil then raise Exception.Create('TStringNode is nil');
  61.   prev := p;
  62.   next := nil;
  63. end;
  64.  
  65. constructor TStringNode.Create(const p: TStringNode; const n: TStringNode);
  66. begin
  67.   inherited Create;
  68.   if p = nil then raise Exception.Create('TStringNode parent is nil.');
  69.   if n = nil then raise Exception.Create('TStringNode next is nil.');
  70.   prev := p;
  71.   next := n;
  72. end;
  73.  
  74. { TStringArray }
  75.  
  76. constructor TStringArray.Create(InitialSize: Integer);
  77. var
  78.   idx: Integer;
  79. begin
  80.   inherited Create;
  81.   for idx := 0 to initialsize do
  82.   begin
  83.     Print(idx);
  84.     Add(IntToStr(idx) + ': 11');
  85.   end;
  86. end;
  87.  
  88. procedure TStringArray.Add(const AValue: String);
  89. var
  90.   n, p: TStringNode;
  91. begin
  92.   if PNode = nil then
  93.   PNode  := TStringNode.Create;
  94.   p      := PNode;
  95.    
  96.   n      := TStringNode.Create;
  97.   n.data := AValue;
  98.  
  99.   PNode.next := n;
  100.   PNode.prev := p;
  101. end;
  102.  
  103. function TStringArray.Count: Integer;
  104. var
  105.   p: TStringNode;
  106. begin
  107.   p := PNode;
  108.   while True do
  109.   begin
  110.     if p.prev = nil then break;
  111.     print(p.data);
  112.     p := PNode.prev;
  113.   end;
  114.  
  115.   result := FCount;
  116. end;
  117.  
  118. initialization
  119. var
  120.   sa: TStringArray;
  121.  
  122.   Print('start...');    
  123.   sa := TStringArray.Create(2);
  124.   try
  125.     sa.count;
  126.   finally
  127.     sa.Free;
  128.     Print('done.');
  129.   end;
  130. end.

But when I try to "add" Strings to the Array Class, I stuck into a infinite loop when I try to read out the Elements.
So, my Question is now: how can I Add and print Elements when I use next and prev ?

The problem is, I can not use records, because I run into problems with:

Code: Pascal  [Select][+][-]
  1. foo = record
  2.   next: foo;
  3. end;

foo will not evulate.
And I can not use Pointers like:

Code: Pascal  [Select][+][-]
  1. Pfoo = ^TFoo;
  2. TFoo = FoFo;

Thanks for helping hands

PascalDragon

  • Hero Member
  • *****
  • Posts: 5904
  • Compiler Developer
Re: HelpNDoc.com and Pascal
« Reply #1 on: February 08, 2025, 06:36:05 pm »
Code: Pascal  [Select][+][-]
  1. procedure TStringArray.Add(const AValue: String);
  2. var
  3.   n, p: TStringNode;
  4. begin
  5.   if PNode = nil then
  6.   PNode  := TStringNode.Create;
  7.   p      := PNode;
  8.    
  9.   n      := TStringNode.Create;
  10.   n.data := AValue;
  11.  
  12.   PNode.next := n;
  13.   PNode.prev := p;
  14. end;
  15.  

But when I try to "add" Strings to the Array Class, I stuck into a infinite loop when I try to read out the Elements.
So, my Question is now: how can I Add and print Elements when I use next and prev ?

Your Add method is incorrect. Also you're not using your Head field at all. Try this (not tested):

Code: Pascal  [Select][+][-]
  1. procedure TStringArray.Add(const AValue: String);
  2. var
  3.   n, p: TStringNode;
  4. begin
  5.   n := TStringNode.Create;
  6.   n.Data := AValue;
  7.  
  8.   n.Prev := PNode;
  9.   if Assigned(PNode) then
  10.     PNode.Next := n;
  11.   PNode := n;
  12.  
  13.   if not Assigned(Head) then
  14.     Head := PNode;
  15. end;


And I can not use Pointers like:

Code: Pascal  [Select][+][-]
  1. Pfoo = ^TFoo;
  2. TFoo = FoFo;

Why can't you?

paule32

  • Sr. Member
  • ****
  • Posts: 320
Re: HelpNDoc.com and Pascal
« Reply #2 on: February 08, 2025, 06:42:02 pm »
Code: Pascal  [Select][+][-]
  1. Pfoo = ^TFoo;
  2. TFoo = FoFo;

Why can't you?
[/quote]

This is by Design from the Authors of HelpNDoc - I had make a Request, but it is Weekend.
And I don't know if they provide Support, because HelpNDoc is commercial.

Maybe I should stay at doxygen ...

 

TinyPortal © 2005-2018