unit Unit1;
{$mode objfpc}{$H+}
{$IFDEF Darwin}
{$modeswitch objectivec1}
{$ENDIF}
interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, Buttons, ExtCtrls,
{$IFDEF Darwin}
CocoaAll, // Needed for NSBundle
CocoaUtils // Needed for NSStringToString
{$ENDIF}
;
type
{ TForm1 }
TForm1 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
{$IFDEF Darwin}
// Images are located in the application bundle's Resources directory
Function GetPathForImageResource(Image: NSString) : string;
begin
Result := NSStringToString(NSBundle.mainBundle.pathForImageResource(Image));
end;
{$ENDIF}
procedure TForm1.Button1Click(Sender: TObject);
var
anImageList: TImageList;
anImage: TImage;
begin
Button1.Enabled := False;
anImageList := TImageList.Create(Self); // Let the form free it
anImage := TImage.Create(nil);
anImageList.Width := 60;
anImageList.Height := 67;
// Load pictures into image list
{$IFDEF Darwin}
anImage.Picture.LoadFromFile(GetPathForImageResource(NSStr('gloves.png')));
{$ELSE}
anImage.Picture.LoadFromFile('gloves.png');
{$ENDIF}
anImageList.Add(anImage.Picture.Bitmap, nil);
{$IFDEF Darwin}
anImage.Picture.LoadFromFile(GetPathForImageResource(NSStr('hood.png')));
{$ELSE}
anImage.Picture.LoadFromFile('hood.png') ;
{$ENDIF}
anImageList.Add(anImage.Picture.Bitmap, nil);
{$IFDEF Darwin}
anImage.Picture.LoadFromFile(GetPathForImageResource(NSStr('robe.png')));
{$ELSE}
anImage.Picture.LoadFromFile('robe.png') ;
{$ENDIF}
anImageList.Add(anImage.Picture.Bitmap, nil);
{$IFDEF Darwin}
anImage.Picture.LoadFromFile(GetPathForImageResource(NSStr('sandals.png')));
{$ELSE}
anImage.Picture.LoadFromFile('sandals.png') ;
{$ENDIF}
anImageList.Add(anImage.Picture.Bitmap, nil);
// Button1
BitBtn1.Images := anImageList;
BitBtn1.ImageIndex := 0;
BitBtn1.Caption := '';
// Button2
BitBtn2.Images := anImageList;
BitBtn2.ImageIndex := 1;
BitBtn2.Caption := '';
// Button3
BitBtn3.Images := anImageList;
BitBtn3.ImageIndex := 2;
BitBtn3.Caption := '';
// Button4
BitBtn4.Images := anImageList;
BitBtn4.ImageIndex := 3;
BitBtn4.Caption := '';
// Cleaning up
anImage.Free;
{anImageList.Free;} // <--- Do not free the imagelist
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
BitBtn1.Caption := 'nothing';
BitBtn2.Caption := 'nothing';
BitBtn3.Caption := 'nothing';
BitBtn4.Caption := 'nothing';
end;
end.