Forum > General
Array methods
(1/1)
riwu:
--- 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";}};} ---type PointArr = array of TPoint;function PointArr.contains(x: TPoint): Boolean;Is there a simple way to create routines that operates on arrays?
One way i know of is to declare PointArr as 'object', which allows type routines, but i wouldn't be able to use built-in array routines like Length(), SetLength(), [] property etc, so i would have to keep track of the length and implement these custom methods myself which makes it unnecessarily complicated, but is that the only way to achieve what i want?
Leledumbo:
http://wiki.lazarus.freepascal.org/Helper_types
howardpc:
Note that if you have FPC 3.0 it is now possible to write constructs like 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";}};} --- {$ModeSwitch typehelpers}type PointArr = array of TPoint; PointArrayHelper = type helper for PointArr function Contains(x: TPoint): Boolean; end; ... function PointArrayHelper.Contains(x: TPoint): Boolean;var p: TPoint;begin Result:=False; if (Length(Self) = 0) then Exit else begin for p in Self do if (p.x = x.x) and (p.y = x.y) then Exit(True); end;end; var pa: PointArray; ... if pa.Contains(Point(0, 3)) then ...
Navigation
[0] Message Index