Forum > General
Enumerator in mode Delphi
SymbolicFrank:
I have this:
--- 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";}};} ---{$mode Delphi}{$H+} TSEnumerator = class private MyNode: TSNode; MyIndex: SizeInt; public constructor Create(ThisNode: TSNode); function GetCurrent: TSNode; function MoveNext: Boolean; procedure Reset; property Current: TSNode read GetCurrent; end; TSNode = class public class operator Enumerator(const ThisNode: TSNode): TSEnumerator; end;
But that gives the following errors:
Error: Procedure or Function expected
Fatal: Syntax error, ":" expected but "identifier ENUMERATOR" found
What am I doing wrong? I couldn't find a better explanation.
bytebites:
--- 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";}};} --- TSNode = class public function GetEnumerator: TSEnumerator; end;
PascalDragon:
--- Quote from: SymbolicFrank on May 02, 2022, 12:39:43 pm ---What am I doing wrong? I couldn't find a better explanation.
--- End quote ---
You can't have operators inside classes (no matter the mode). As bytebites wrote use a normal method with the name GetEnumerator or declare your operator as a global one.
SymbolicFrank:
Thanks. I saw it in Generics.Collections. It works now :)
The documentation first tells you to make an "operator Enumerator" and then links to the Delphi page about operator overloading for mode Delphi. It wasn't very clear.
PascalDragon:
--- Quote from: SymbolicFrank on May 02, 2022, 01:21:28 pm ---The documentation first tells you to make an "operator Enumerator" and then links to the Delphi page about operator overloading for mode Delphi. It wasn't very clear.
--- End quote ---
Do you have a link?
Navigation
[0] Message Index
[#] Next page