Few days ago, I began work on a Windows Firewall component in Delphi, and my work is currently up on Github.
The name of the unit containing the Windows Firewall component is called System.Win.Firewall, and the component is called TWindowsFirewall. The example project has 2 functions. 1 function lists all the firewall rules, and the other creates a rule, blocking a list of addresses.
The function that lists all the firewall rules, look like so:
procedure ShowRule(const ARule: TWindowsFirewall.TWindowsFirewallRule); begin WriteLn('Name: ', ARule.Name); WriteLn('Action: ', ARule.Action.ToString); WriteLn('Description: ', ARule.Description); WriteLn('Direction: ', ARule.Direction.ToString); WriteLn('Enabled: ', ARule.Enabled); WriteLn('Profile: ', ARule.Profile.ToString); WriteLn('Interface Types: ', ARule.InterfaceTypes.ToString); WriteLn('-----------------------------------'); end; procedure EnumRules; var LFirewall: TWindowsFirewall; LRule: TWindowsFirewall.TWindowsFirewallRule; LRuleName, LInterface: string; begin LFirewall := TWindowsFirewall.Create; try for LRuleName in TArray<string>.Create('Doesn''t exist', 'Test rule using TWindowsFirewall') do if LFirewall.Rules.FindRule(LRuleName) then begin LRule := LFirewall.Rules[LRuleName]; ShowRule(LRule); LRule.Free; end; for LRule in LFirewall.Rules do ShowRule(LRule); finally LFirewall.Free; end; end; begin EnumRules; end.
Feel free to check out the repository, or if you're interested in extending/enhancing the component further, or collaborate with me.
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes