// Compare TIcons example. // efg, www.efg2.com/Lab // September 2000 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} FUNCTION AreIconsEqual(CONST Icon1, Icon2: TIcon): BOOLEAN; VAR m1: TMemoryStream; m2: TMemoryStream; BEGIN RESULT := FALSE; m1 := TMemoryStream.Create; TRY Icon1.SaveToStream(m1); m2 := TMemoryStream.Create; TRY Icon2.SaveToStream(m2); IF m1.Size = m2.Size THEN RESULT := CompareMem(m1.Memory, m2.Memory, m1.Size) FINALLY m2.Free END FINALLY m1.Free END END {AreTIconsEqual}; procedure TForm1.Button1Click(Sender: TObject); VAR iconA: TIcon; iconB: TIcon; iconC: Ticon; begin iconA := TIcon.Create; iconB := TIcon.Create; iconC := TIcon.Create; TRY iconA.LoadFromFile('A.ICO'); iconB.LoadFromFile('B.ICO'); // A <> B iconC.LoadFromFile('C.ICO'); // A = C IF AreIconsEqual(iconA, iconB) THEN ShowMessage('A and B match') ELSE ShowMessage('A and B do not match'); IF AreIconsEqual(iconA, iconC) THEN ShowMessage('A and C match') ELSE ShowMessage('A and C do not match'); IF AreIconsEqual(iconB, iconC) THEN ShowMessage('B and C match') ELSE ShowMessage('B and C do not match'); FINALLY iconA.Free; iconB.Free; iconC.Free END end; end.