diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-24 11:07:50 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-04-24 11:07:50 +0000 |
commit | 05e0c788f2e59cfe03651c1a356442f304c81317 (patch) | |
tree | 3d087928595e47ee25d50dc3667c162bcc6e4e21 /src/corelib | |
parent | a2d2d040852cd300dfecc24fe1cde38633c95e10 (diff) | |
download | fpGUI-05e0c788f2e59cfe03651c1a356442f304c81317.tar.xz |
* Sanity check added in ImageList.
* Minor improvement to image index handling.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/gfx_imagelist.pas | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/corelib/gfx_imagelist.pas b/src/corelib/gfx_imagelist.pas index 97282b62..74260eef 100644 --- a/src/corelib/gfx_imagelist.pas +++ b/src/corelib/gfx_imagelist.pas @@ -66,8 +66,8 @@ type public constructor Create; destructor Destroy; override; - procedure AddItemFromFile(AFileName: String; AIndex: word); - procedure AddImage(AImage: TfpgImage; AIndex: word); + procedure AddItemFromFile(AFileName: String; AIndex: word = -1); + procedure AddImage(AImage: TfpgImage; AIndex: word = -1); procedure RemoveIndex(AIndex: integer); function GetMaxItem: word; property Item[AIndex: integer]: TfpgImageItem read GetItem write SetItem; @@ -146,9 +146,19 @@ begin {$IFDEF DEBUG} writeln('TfpgImageList.AddItemFromFile'); {$ENDIF} + + if not FileExists(AFileName) then + Exit; + AImageItem := TfpgImageItem.Create; AImageItem.LoadFromFile(AFileName); - Item[AIndex] := AImageItem; + if AIndex > -1 then + Item[AIndex] := AImageItem + else + begin + FList.Add(AImageItem); + AImageItem.Index := GetMaxItem+1; + end; end; procedure TfpgImageList.AddImage(AImage: TfpgImage; AIndex: word); @@ -157,7 +167,13 @@ var begin AImageItem := TfpgImageItem.Create; AImageItem.Image := AImage; - Item[AIndex] := AImageItem; + if AIndex > -1 then + Item[AIndex] := AImageItem + else + begin + FList.Add(AImageItem); + AImageItem.Index := GetMaxItem+1; + end; end; procedure TfpgImageList.RemoveIndex(AIndex: integer); @@ -177,7 +193,7 @@ function TfpgImageList.GetMaxItem: word; var ACounter: integer; begin - result := 0; + result := -1; for ACounter := 0 to FList.Count - 1 do if TfpgImageItem(FList[ACounter]).Index > result then result := TfpgImageItem(FList[ACounter]).Index; |