Uses
  scrnio;
var
  AllFamNum:      integer;
  AllFamDue:      Currency;
  AllFamPaid:     Currency;
  AllFamBalance:  Currency;
  AllFamCredit:   Currency;
  AllFamGifts:    Currency;
	PageLabel:			 TLabel;
	ParishID:				 TLabel;
	ParishName:			 TLabel;
  ParishIDEdit:		Tedit;
	ParishNameEdit:	Tedit;
  FieldsRead:			Boolean;

procedure AfterLoadReport;
begin
	NewScreenPage;
	AddHeading('Parish Information for Report:',PageLabel);
	ParishID:='xyz';
	ParishName:='ABC';
  AddEdit('Archdiocesan Parish ID #:',ParishID,ParishIDedit,3);
  AddBlank;
	AddEdit('Parish Name:',ParishName,ParishNameEdit,50);

	// Read Ini File to set the initial values
	IniFile:=TIniFile.Create(trim(DMReport.MainRepName)+'.ini');
	try
		ParishIDEdit.text:=IniFile.ReadString('LastInfo','ParishIDEdit','');
		ParishNameEdit.text:=IniFile.ReadString('LastInfo','ParishNameEdit','');
		Fieldsread:=true;
	finally
		IniFile.Free;
		IniFile:=nil;
	end;
end;
Procedure AfterCreateReport;
begin
	Fieldsread:=false;
end;

Procedure BeforeDestroyReport;
var
	IniFile: TIniFile;
begin
	if fieldsread then
		begin
			//Access Ini File and save the values
			IniFile:=Tinifile.create(trim(DMReport.MainRepName)+'.ini');
			try
				IniFile.WriteString('LastInfo','ParishIDEdit',ParishIDedit.text);
				IniFile.WriteString('LastInfo','ParishNameEdit',ParishNameEdit.text);
			finally
				IniFile.Free;
				IniFile:=nil;
			end;
		end;
end;

procedure BeforeSelectionsBuilt;
var
  OldFilter:        string;
  OldFiltered:      boolean;
  OldMasterFields:  String;
  OldMasterSource:  TwwDataSource;
  Prg:              TProgress;
begin
  AllFamNum:=0;
  AllFamDue:=0;
  AllFamPaid:=0;
  AllFamBalance:=0;
  AllFamCredit:=0;
  AllFamGifts:=0;
  with PDSDMData, PDSDMCalc, FamTbl do
    begin
      Prg:=TProgress.Create(Application,'Gathering Totals:',0{RecordCount});
      try
        PDSFixupDlg(Prg);
        Prg.ShowCancelBtn;
        Prg.Show;
        Application.ProcessMessages;

        OldFilter:=Filter; 
        OldFiltered:=Filtered;
        OldMasterFields:=MasterFields;
        OldMasterSource:=MasterSource;

        if MainFamFilter<>'' then
          begin 
            Filter:=MainFamFilter; 
            Filtered:=true;
          end
        else
          begin
            Filtered:=false;
          end;
        MasterFields:='';
        MasterSource:=nil;
        First;
        while not eof do
          begin
            Application.ProcessMessages;
            Prg.Step;
            if not Prg.Visible then
              begin
                DMReport.MainRepeatPrint:=true;
                exit;
              end;

            PDSDMCalc.BuildFundTbl;
            PDSDMCalc.BuildFundInfoTbl;

            if Not PDSDMCalc.CalcFundTbl.IsEmpty then
              begin
                AllFamNum:=AllFamNum+1;
                AllFamDue:=AllFamDue+FundTotalsTblGrandTotalDue.AsCurrency;
                AllFamPaid:=AllFamPaid+FundTotalsTblGrandTotalPaid.AsCurrency;
                AllFamBalance:=AllFamBalance+FundTotalsTblGrandTotalBalance.AsCurrency;
                AllFamCredit:=AllFamCredit+FundTotalsTblGrandTotalCredit.AsCurrency;
                AllFamGifts:=AllFamGifts+FundTotalsTblGrandTotalGifts.AsCurrency;
              end;
            Next;
          end;
        MasterSource:=OldMasterSource;
        MasterFields:=OldMasterFields;
        Filtered:=false;
        Filter:=OldFilter;
        Filtered:=OldFiltered;
      finally;
        Prg.Free;
        Prg:=nil;
      end;
    end;
  PDSSetParam(1,IntToStr(AllFamNum));
  PDSSetParam(2,FloatToStr(AllFamDue));
  PDSSetParam(3,FloatToStr(AllFamPaid));
  PDSSetParam(4,FloatToStr(AllFamBalance));
  PDSSetParam(5,FloatToStr(AllFamCredit));
  PDSSetParam(6,FloatToStr(AllFamGifts));
  PDSSetParam(7,ParishIDedit.text);
  PDSSetParam(8,ParishNameEdit.text);
;
end;
