TPicture.LoadFromFile not working lazarus / 39-Graphics ---------------------------------------------------------------------- lainz · 2010-09-11 22:14 Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     Image1: TImage;     procedure Image1MouseEnter(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   picture1: TPicture;   bitmap1: TBitmap; implementation {$R *.lfm} { TForm1 } procedure TForm1.Image1MouseEnter(Sender: TObject); begin   Image1.Picture:=picture1; end; initialization picture1.Create; picture1.LoadFromFile('1.bmp'); end. Error: External SIGSEGV; and load "picture.inc" at line 730 " NewGraphic.OnProgress := @Progress;" also the same error on bitmap.LoadFromFile What i'm doing wrong? ---------------------------------------------------------------------- jhvhs · 2010-09-12 07:35 This should do the trick: Code: [Select]procedure TForm1.Image1MouseEnter(Sender: TObject); begin   Image1.Picture.Assign(picture1); end; ... Picture1 := TPicture.Create; ---------------------------------------------------------------------- theo · 2010-09-12 09:23 It doesn't have to do with Picture but with the way you're creating objects. picture1.Create; Should be: picture1:=TPicture.create; ---------------------------------------------------------------------- lainz · 2010-09-12 14:27 Thanks! Now i have an image button with 3 pictures (normal, mouse over, mouse down) Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     Image1: TImage;     procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;       Shift: TShiftState; X, Y: Integer);     procedure Image1MouseEnter(Sender: TObject);     procedure Image1MouseLeave(Sender: TObject);     procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;       Shift: TShiftState; X, Y: Integer);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   picture1: TPicture;   picture2: TPicture;   picture3: TPicture; implementation {$R *.lfm} { TForm1 } procedure TForm1.Image1MouseEnter(Sender: TObject); begin   Image1.Picture.Assign(picture2); end; procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   Image1.Picture.Assign(picture3); end; procedure TForm1.Image1MouseLeave(Sender: TObject); begin   Image1.Picture.Assign(picture1); end; procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   Image1.Picture.Assign(picture2); end; initialization {normal} picture1:=TPicture.Create; picture1.LoadFromFile('1.png'); {mouse over} picture2:=TPicture.Create; picture2.LoadFromFile('2.png'); {mouse down} picture3:=TPicture.Create; picture3.LoadFromFile('3.png'); end. ---------------------------------------------------------------------- wotanica · 2010-09-21 13:36 Not to sound harsh but you should be carefull where you create objects. I for one would not setup picture-objects during unit initialization (unless they are global and have proper access methods). You are bound to get access violation errors sooner or later. If the pictures are part of a form, or being used by a component, you should keep them within the scope of that parent rather than on unit level: Code: [Select](* override constructor *) Constructor TForm1.Create(AOwner:TComponent); Begin   Inherited Create(AOwner);   FPicture1:=TPicture.Create(NIL);   (.. etc ..) end; Destructor TForm1.Destroy; Begin   if assigned(FPicture1) then   FreeAndNIL(FPicture1);   Inherited; end; The reason this is better is twofold: 1. You dont have to look for bizare errors outside the class (if something goes wrong with "picture1" the exception might turn up inside a form method, but it's actually on unit level. Better to keep these things seperated). 2. You have little control over how lazarus unloads units. If you initialize pictures this way - you at least have to take height of application.termination. Just a friendly heads up, you are going to experience problems if you go down that road of programming.