From ad6266815d87772126c33b581027e115139fa1c7 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 25 Nov 2009 13:08:41 +0000 Subject: [PATCH] LCL: TCustomImageList: added Equals and comparing data with Ancestor git-svn-id: trunk@22766 - --- lcl/imglist.pp | 1 + lcl/include/imglist.inc | 33 +++++++++++++++++++++++++++------ lcl/lresources.pp | 28 ++++++++++++++++------------ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/lcl/imglist.pp b/lcl/imglist.pp index aef0a442cf..18e53da23c 100644 --- a/lcl/imglist.pp +++ b/lcl/imglist.pp @@ -157,6 +157,7 @@ type procedure Assign(Source: TPersistent); override; procedure WriteData(AStream: TStream); virtual; procedure ReadData(AStream: TStream); virtual; + function Equals(Obj: TObject): boolean; override; procedure BeginUpdate; procedure EndUpdate; diff --git a/lcl/include/imglist.inc b/lcl/include/imglist.inc index 2f8bc36a89..d8f22b0dda 100644 --- a/lcl/include/imglist.inc +++ b/lcl/include/imglist.inc @@ -386,13 +386,9 @@ procedure TCustomImageList.DefineProperties(Filer: TFiler); function DoWrite: Boolean; begin - { if Filer.Ancestor <> nil then - begin - Result := (not (Filer.Ancestor is TCustomImageList) or - not Equal(TCustomImageList(Filer.Ancestor))); - end + if (Filer.Ancestor <> nil) and (Filer.Ancestor is TCustomImageList) then + Result := not Equals(Filer.Ancestor) else - } Result := Count > 0; end; @@ -1180,6 +1176,31 @@ begin end; end; +function TCustomImageList.Equals(Obj: TObject): boolean; +var + SrcList: TCustomImageList; + CurStream: TMemoryStream; + SrcStream: TMemoryStream; +begin + if Obj is TCustomImageList then begin + SrcList:=TCustomImageList(Obj); + Result:=false; + if SrcList.Count<>Count then exit; + if Count=0 then exit(true); + CurStream:=TMemoryStream.Create; + SrcStream:=TMemoryStream.Create; + try + WriteData(CurStream); + SrcList.WriteData(SrcStream); + Result:=CompareMemStreams(CurStream,SrcStream); + finally + SrcStream.Free; + CurStream.Free; + end; + end else + Result:=inherited Equals(Obj); +end; + {------------------------------------------------------------------------------ Method: TCustomImageList.RegisterChanges Params: Value: a reference to changelink object diff --git a/lcl/lresources.pp b/lcl/lresources.pp index fb1a57e60f..cf7c79b1fe 100644 --- a/lcl/lresources.pp +++ b/lcl/lresources.pp @@ -1060,23 +1060,27 @@ end; function CompareMemStreams(Stream1, Stream2: TCustomMemoryStream ): boolean; var - Buffer1, Buffer2: array[1..1024] of byte; - BufLength: Integer; - Count: LongInt; + p1: Pointer; + p2: Pointer; + Cnt: Int64; + CurCnt: cardinal; begin if Stream1=Stream2 then exit(true); Result:=false; if (Stream1=nil) or (Stream2=nil) then exit; if Stream1.Size<>Stream2.Size then exit; - Stream1.Position:=0; - Stream2.Position:=0; - BufLength:=High(Buffer1)-Low(Buffer1)+1; - repeat - Count:=Stream1.Read(Buffer1[1],BufLength); - if Count=0 then exit(true); - Stream2.Read(Buffer2[1],BufLength); - if not CompareMem(@Buffer1[1],@Buffer2[1],Count) then exit; - until false; + Cnt:=Stream1.Size; + p1:=Stream1.Memory; + p2:=Stream2.Memory; + while Cnt>0 do begin + CurCnt:=Cnt; + if CurCnt>=High(Cardinal) then CurCnt:=High(Cardinal); + if not CompareMem(p1,p2,CurCnt) then exit; + inc(p1,CurCnt); + inc(p2,CurCnt); + dec(Cnt,CurCnt); + end; + Result:=true; end; procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;