Funcao - fazer uso de callback para chamar procedure e funcion |
Top Previous Next |
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TFiltrar = function(vl :integer):Bool of object;
TForm1 = class(TForm) Memo1: TMemo; RadioGroup1: TRadioGroup; Button1: TButton; procedure Button1Click(Sender: TObject); private procedure PercorrerRegistros(add: TFiltrar); function AddPares(Vl: integer): bool; function AddImpares(Vl: integer): bool; function AddTodos(Vl: integer): bool; end;
var Form1: TForm1;
implementation
{$R *.DFM}
Procedure TForm1.PercorrerRegistros(add : TFiltrar); var x: integer; begin Memo1.clear; for x:=0 to 100 do If Add(x) then Memo1.lines.add(inttostr(x)); end;
Function TForm1.AddPares(Vl : integer):bool; begin result := (Vl mod 2)=0; end;
Function TForm1.AddImpares(Vl : integer):bool; begin result := (Vl mod 2)<>0; end;
Function TForm1.AddTodos(Vl : integer):bool; begin result := true; end;
procedure TForm1.Button1Click(Sender: TObject); Var Add : Tfiltrar; begin Case Radiogroup1.itemindex of 0 : add := addPares; 1 : add := addImpares; 2 : add := addTodos; end; PercorrerRegistros(add); end;
end. |