How to kill TBannerAd?

  

Situation (Delphi Berlin 10.1):
in my application the main form calls the secondary form. Then the secondary form shows Admob’s banner. The problem is even when I close the secondary form and clear the memory, the banner continues to be displayed. How to hide the banner completely? Thank you in advance.

Here’s the code of the secondary unit:

unit ad_Unit;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Advertising, FMX.Controls.Presentation, FMX.StdCtrls;

type
TAdForm = class(TForm)
OKButton: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FBannerAd: TBannerAd;
public
end;

var
AdForm: TAdForm;

implementation

{$R *.fmx}

procedure TAdForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(FBannerAd) then
begin
FBannerAd.Hide;
FBannerAd.DisposeOf;
FBannerAd := nil;
end;
Action := TCloseAction.caFree;
end;

procedure TAdForm.FormCreate(Sender: TObject);
begin
FBannerAd := TBannerAd.Create(Self);
FBannerAd.Parent := Self;
FBannerAd.AdUnitID := ‘<ID>’;
FBannerAd.Align := TAlignLayout.Top;
FBannerAd.TestMode := True;
end;

procedure TAdForm.FormShow(Sender: TObject);
begin
FBannerAd.LoadAd;
end;

end.

Comments are closed.