What am I doing wrong? lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- Guest · 2005-12-20 08:03 I am learning how to build a Lazarus package.Here is my unit file: Code: [Select]unit MySlidePan; interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,Windows; type TSlidePanel = class(TPanel)   private     FSlideTextFile : string;     FTextToSlide : Ansistring;     FSlideRect : Rect ;     function GetTextFileName : string;     procedure SetTextFileName(ATextFileName:string);     procedure SetSlideRect;   public     constructor Create;     Destructor Destroy;     procedure SetUp;     procedure ScrollText(ScrollingStep:integer;Orientation:boolean);   published     property SlideTextFile : string read GetTextFileName write SetTextFileName;   end;   procedure Register; implementation constructor TSlidePanel.Create; var ii          : integer; OpenFileDlg : TOpenDialog; Strs        : TStringList; begin   inherited Create(self);   if SlideTextFile='' then begin     OpenFileDlg := TOpenDialog.Create(self);     OpenFileDlg.Execute;     SlideTextFile := OpenFileDlg.FileName;   end;   SetSlideRect;   Strs := TStringList.Create;   Strs.LoadFromFile(SlideTextFile);   for ii :=0 to Strs.Count-1 do FTextToSlide := FTextToSlide+Strs.Strings[ii]+#13#10;   Canvas.Font.Color := clBlack;    DrawText(Canvas.Handle,PChar(FTextT oSlide),Length(FTextToSlide),@FSlideRect,DT_CENTER); end; Destructor TSlidePanel.Destroy; begin   inherited; end; procedure TSlidePanel.SetUp; var ii          : integer; OpenFileDlg : TOpenDialog; Strs        : TStringList; begin   inherited Create(self);   if SlideTextFile='' then begin     OpenFileDlg := TOpenDialog.Create(self);     OpenFileDlg.Execute;     SlideTextFile := OpenFileDlg.FileName;   end;   SetSlideRect;   Strs := TStringList.Create;   Strs.LoadFromFile(SlideTextFile);   for ii :=0 to Strs.Count-1 do FTextToSlide := FTextToSlide+Strs.Strings[ii]+#13#10;   Canvas.Font.Color := clBlack;    DrawText(Canvas.Handle,PChar(FTextT oSlide),Length(FTextToSlide),@FSlideRect,DT_CENTER); end; function TSlidePanel.GetTextFileName:string; begin   Result := FSlideTextFile; end; procedure TSlidePanel.SetTextFileName(ATextFileName:string); begin   FSlideTextFile := ATextFileName; end; procedure TSlidePanel.SetSlideRect; begin   FSlideRect.Left := Left;   FSlideRect.Top :=Top;   FSlideRect.Right := Left+Width;   FSlideRect.Bottom := Top+Height; end; procedure TSlidePanel.ScrollText(ScrollingStep:integer;Orientation:boolean); begin   if SlideTextFile='' then begin     if Orientation then FSlideRect.Top :=Top-ScrollingStep     else FSlideRect.Top :=Top+ScrollingStep;     drawtext(Canvas.Handle,PChar(FTextToSlide),Length(FTextToSlide),@F SlideRect,DT_CENTER);   end; end; procedure Register; begin   RegisterComponents('TPanel', [TSlidePanel]); end; end. I added it to a new package and saved it as 'SlidePanelPackage.lpk',compiled and installed it.Now there apears a new component(TSlidPanel) on the 'standard' panel. I then create a new project,the following is the code of its main form: Code: [Select]unit scrolpan; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, MySlidePan,   ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     SlidePanel1: TSlidePanel;     Timer1: TTimer;     procedure FormCreate(Sender: TObject);     procedure Timer1Timer(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   SlidePanel1.SetUp; end; procedure TForm1.Timer1Timer(Sender: TObject); begin   SlidePanel1.ScrollText(1,True); end; initialization   {$I scrolpan.lrs} end. Now problem comes.When I press F9 to run the application,the compiler says: Project raise exception class 'External:SIGSEGV' and the code editor opens the file compon.inc and the cursor stops at line 229, here is the code between line 224 and line 237: Code: [Select]... Procedure TComponent.Notification(AComponent: TComponent;   Operation: TOperation); Var Runner : Longint; begin   If (Operation=opRemove) and Assigned(FFreeNotifies) then     begin     FFreeNotifies.Remove(AComponent);             If FFreeNotifies.Count=0 then ... I am novice to pascal and Lazarus.Anyone can help me,please? ---------------------------------------------------------------------- Guest · 2005-12-20 08:14 Oh,I forgot to tell you:I am using Lazarus0.9.10 under win2k ---------------------------------------------------------------------- mattias · 2005-12-20 14:01 A component's constructor is not 'Create', but constructor Create(TheOwner: TComponent); override and it must call inherited Create(TheOwner); Never use 'Self' as its owner. You create a circle. A destructor must be 'destructor Destroy; override;' and must call inherited. ---------------------------------------------------------------------- Anonymous · 2005-12-21 01:27 Quote from: "mattias"A component's constructor is not 'Create', but constructor Create(TheOwner: TComponent); override and it must call inherited Create(TheOwner); Never use 'Self' as its owner. You create a circle. A destructor must be 'destructor Destroy; override;' and must call inherited. I modified the code as you told me: Code: [Select]constructor TSlidePanel.Create; ...   inherited Create(nil);// this was: inherited Create(self); and Code: [Select]Destructor Destroy;override;// this was: Destructor Destroy; and delete the wrong line Code: [Select]procedure TSlidePanel.SetUp; ... begin   inherited Create(self);     //this line should be deleted   if SlideTextFile='' then begin ... but the same problem still exists.I am confused about the instance of class:when I create the TSlidePanel,I don't know about it's owner,so I pass the value 'nil' to the constructor.And is this the problem? ---------------------------------------------------------------------- Anonymous · 2005-12-21 01:43 Ok,I found the problem:After I modified and compiled the source code of the package,the previous compiled *.ppu file was still used in the project. So I must also modifiy the file in my project and re-compile it again.   The modified code works OK now.Much thanks to Mattias! ---------------------------------------------------------------------- Marc · 2005-12-21 09:24 To use this as a component on forms in a way that they can be saved, then change your constructor to:Code: [Select] constructor Create(TheOwner: TComponent); override;Code: [Select] TSlidePanel.Create(TheOwner: TComponent); begin   inherited;   ... end; this is the only way you can stream your components. You cannot introduce your own constructor