My first (failed) attempt at understanding and creating a class having read the Class documentation. My code compiles but on running in Lazarus IDE fails on any attempt to reference a private var, a Sigsegv error, when running without IDE Access Violation error. Please can someone tell me where I am going wrong.
My Class Unit
unit ClsChartSettings;
{$mode objfpc}{$H+}
interface
Type
TChSet = Class
Private
PageHt: Single; //Private var to hold Page Height
Procedure SetHt(PgHt: Single); //Private proc to set Page Height
Public
constructor Create(ChId : String);
Property PageH: Single Read PageHt Write SetHt; //Public property read from private var
//Write with proc SetHt
End;
implementation
uses
Classes, SysUtils, Dialogs;
constructor TChSet.Create(ChId: String);
//Initialise class variable
begin
PageHt:=0;
ShowMessage('Class Created ' + ChId);
End;
Procedure TChSet.SetHt(PgHt: Single);
//This proc to set private var
Begin
PageHt:=PgHt;
End;
end.
My Test program
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
ClsChartSettings;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
x: TChSet;
begin
x.Create('Test');
x.PageH:=297;
ShowMessage(x.PageH.ToString);
end;
end.