This method is intended to compare two interface objects and return whether they are equal. The comparison can be shallow (compare pointers) or deep (compare data) depending on the implementor. Please refer to the documentation of the objects for more information.
Namespace: CommonInterfaces
Delphi
|
public
function Equals( const AValue: IInterface ): Boolean;
|
Parameters
AValue
Type: IInterface
Return Value
Type: Boolean
The following code implements the Equals method for TFactTemplate from the Inference Engine Component Suite:
Delphi
|
{ Compare two fact templates }
var
FT: IFactTemplate;
SlotName: String;
begin
// Check to see if it is the same object, self must be cast to IFactTemplate
result := Value = IFactTemplate(Self);
// Do we need to check anything else
if not result then
begin
// Ok, not the same object, does Value at least implement IFactTemplate?
result := Value.QueryInterface( IFactTemplate, FT ) <> E_NOINTERFACE;
if result then
with FT do
begin
// Value does implement IFactTemplate, compare the data
result := (FOrdered = Ordered) and
(FTemplateName = TemplateName);
if result then
begin
// Check all the slots, only worry about the current template having
// no slots EXTRA
Self.FSlots.Reset;
while not Self.FSlots.EOT do
begin
SlotName := Self.FSlots.Next;
if (not Slots.ContainsKey( SlotName )) or
(not Self.Slot[Slotname].Equals(Slot[SlotName])) then
begin
result := False;
Break;
end;
end;
end;
end;
end;
end;
|