Although I haven't worked on this in some time and I'm not
even sure it still works, try this. I was going to rewrite it
to use TObjectList so they'd be freed automatically but haven't
gotten aroudn to it. If you modify it, I'd appreciate it if you
send me a copy.
unit EXSJPEGImageList;
{
ImageList-like component that holds JPEG images of any size.
Some code courtesy Borkand Newsgroups.
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
JPEG; {imglist}
type
TCustomJPEGImageList = class(TComponent)
private
{ Private declarations }
FOnChange: TNotifyEvent;
FJPEGList: TList;
FUpdateCount: Integer;
FChanged: Boolean;
function GetCount: Integer;
protected
{ Protected declarations }
procedure BeginUpdate;
procedure EndUpdate;
procedure Change; dynamic;
procedure Initialize; virtual;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Add(Image: TJPEGImage): Integer;
procedure Clear;
procedure Delete(Index: Integer);
procedure GetJPEG(Index: Integer; Image: TJPEGImage);
procedure Insert(Index: Integer; Image: TJPEGImage);
procedure Move(CurIndex, NewIndex: Integer);
procedure Replace(Index: Integer; Image: TJPEGImage);
property Count: Integer read GetCount;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
published
{ Published declarations }
end;
TJPEGImageList = class(TCustomJPEGImageList)
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('EXS', [TJPEGImageList]);
end;
constructor TCustomJPEGImageList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Initialize;
end;
destructor TCustomJPEGImageList.Destroy;
begin
Clear;
FJPEGList.Free;
inherited Destroy;
end;
procedure TCustomJPEGImageList.Initialize;
begin
FJPEGList := TList.Create;
end;
function TCustomJPEGImageList.Add(Image: TJPEGImage): Integer;
var
jpg: TJpegImage;
begin
jpg := TJpegImage.Create;
jpg.Assign(Image); //do a content copy
FJPEGList.Add(jpg);
Result := FJPEGList.Count;
Change;
end;
(*
function TCustomJPEGImageList.Add(Image: TJPEGImage): Integer;
begin
FJPEGList.Add(Image);
Result := FJPEGList.Count;
Change;
end;
*)
procedure TCustomJPEGImageList.Clear;
var
i: Integer;
begin
for i := Pred(FJPEGList.Count) downto 0 do
if FJPEGList.Items[i] <> nil then
TJpegImage(FJPEGList.Items[i]).Free;
FJPEGList.Clear;
Change;
end;
procedure TCustomJPEGImageList.Delete(Index: Integer);
begin
if FJPEGList.Items[Index] <> nil then
TJpegImage(FJPEGList.Items[Index]).Free;
FJPEGList.Delete(Index);
Change;
end;
(*
procedure TCustomJPEGImageList.Delete(Index: Integer);
begin
FJPEGList.Delete(Index);
Change;
end;
*)
procedure TCustomJPEGImageList.GetJPEG(Index: Integer; Image: TJPEGImage);
begin
Image.Assign(TJPEGImage(FJPEGList.Items[Index]));
end;
procedure TCustomJPEGImageList.Insert(Index: Integer; Image: TJPEGImage);
var
jpg: TJpegImage;
begin
jpg := TJpegImage.Create;
jpg.Assign(Image); //do a content copy
FJPEGList.Insert(Index, jpg);
Change;
end;
(*
procedure TCustomJPEGImageList.Insert(Index: Integer; Image: TJPEGImage);
begin
FJPEGList.Insert(Index, Image);
Change;
end;
*)
procedure TCustomJPEGImageList.Move(CurIndex, NewIndex: Integer);
begin
FJPEGList.Move(CurIndex, NewIndex);
Change;
end;
procedure TCustomJPEGImageList.Replace(Index: Integer; Image: TJPEGImage);
begin
TJpegImage(FJPEGList.Items[index]).Assign(Image); //replace content
Change;
end;
(*
procedure TCustomJPEGImageList.Replace(Index: Integer; Image: TJPEGImage);
begin
FJPEGList.Delete(Index);
FJPEGList.Insert(Index, Image);
Change;
end;
*)
function TCustomJPEGImageList.GetCount: Integer;
begin
Result := FJPEGList.Count;
end;
procedure TCustomJPEGImageList.Change;
begin
FChanged := True;
if FUpdateCount > 0 then Exit;
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TCustomJPEGImageList.BeginUpdate;
begin
Inc(FUpdateCount);
end;
procedure TCustomJPEGImageList.EndUpdate;
begin
if FUpdateCount > 0 then Dec(FUpdateCount);
if FChanged then
begin
FChanged := False;
Change;
end;
end;
end.
--- Eric Daniels <[EMAIL PROTECTED]> wrote:
> Does anyone know of a component that is similar to delphi's imagelist that
> supports jpeg files...
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi