I am learning how to build a Lazarus package.Here is my unit file:
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(FTextToSlide),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(FTextToSlide),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),@FSlideRect,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:
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:
...
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?