Forum > General

how to add a ForEach call to TFPGList

(1/2) > >>

mas steindorff:
I see the TFPList has a .ForEachCall() procedure
is it hard to add this to a TFPGList?

I'm looking for a cleaner way to loop though each item I've defined as a class and call it's .ClearHand() procedure without a for loop.

cdbc:
Hi
  1)
--- 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";}};} ---TListCallback = procedure(data,arg:pointer) of object;  // TFPList1.1)
--- 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";}};} ---TGListCallback = procedure(data,arg:<T>) of object;  // TFPGList 

  2)
--- 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";}};} ---procedure ForEachCall(proc2call:TListCallback;arg:pointer);2.1)
--- 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";}};} ---procedure ForEachCall(proc2call:TGListCallback;arg:<T>);  3)
--- 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";}};} ---procedure TFPGList.ForEachCall(proc2call:TGListCallback;arg:<T>);var  i : integer;  p : T;begin  For I:=0 To Count-1 Do    begin      p:=FList^[i];      if assigned(pointer(p)) then        proc2call(p,arg);    end;end; Maybe something like the above :: It is untested code, just my first stab at it... Perhaps you can implement it in a descendant class...
Regards Benny

jamie:
There is already a enumerator in that generics, just encase it with a inline function.
Jamie

mas steindorff:
Thank you Benny,
I'll give the code you posted a try

Jamie, I'm afraid your post is over my head so I've been looking around at your other post for more info. I also looked into the header of TFPGList but did not find any ForEach... calls to "inline"??
can you point me to a code example you are recommending I try?
 

Thank you both for your post. This project goal is for me to learn and both post are firing the brain cells.
Mas

cdbc:
Hi Mas
I think jamie means something 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";}};} ---generic procedure FPGList_ForEachCall(aList: TFPGList;   proc2call:TGListCallback;  arg:<T>); inline;var  i : integer;  p : T;begin  For I:=0 To aList.Count-1 Do    begin      p:=aList^[i];      if assigned(pointer(p)) then        proc2call(p,arg);    end;end;I could ofc. be mistaken...
Regards Benny

Navigation

[0] Message Index

[#] Next page

Go to full version