Recent

Author Topic: property write method implement go sigsevg error  (Read 5210 times)

vkhoa

  • New Member
  • *
  • Posts: 47
property write method implement go sigsevg error
« on: May 26, 2014, 01:11:15 pm »
this is my code of unit1, contain form, place a label1,edit1,button1
it thrown sigsevg error at line "if not (txt=avalue) then"
if comment it then other sigsevg error occur at line 403b00
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }
  valueeventhandler =procedure (newvalue:string) of object;
  type varb=class(tobject)
     procedure setvalue(avalue:string);
     function getvalue:string;
  private
    txt:string;
    valchange:valueeventhandler;
  public
     property value:string read getvalue write setvalue;
     property valuechange:valueeventhandler read valchange write valchange;
  end ;
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure varbchange(txt:string) ;//of object;
  private
    { private declarations }
  public
    { public declarations }
    myvar:varb;
  end;


var
  Form1: TForm1;

implementation

{$R *.lfm}

    { TForm1 }

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      myvar.value:='is first value and assign manual to label,then add value change event';
      label1.Caption:=myvar.value;
      myvar.valuechange:=@varbchange;
    end;
    procedure tform1.varbchange(txt:string);
    begin
        label1.caption:=myvar.value;
    end;

    procedure varb.setvalue(avalue:string);
    begin
         if not (txt=avalue) then//<-------------------------------error at this line
          begin
          txt:=avalue;
          if assigned(valuechange) then
             valuechange(avalue);
          end;
    end;
    function varb.getvalue:string;
    begin
        result:=txt;
    end;
end.
                             
please help

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: property write method implement go sigsevg error
« Reply #1 on: May 26, 2014, 01:23:59 pm »
Because you never created "myvar".
You need to add somewhere:
Code: [Select]
myvar:=Varb.Create;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: property write method implement go sigsevg error
« Reply #2 on: May 26, 2014, 01:27:25 pm »
this is my code of unit1, contain form, place a label1,edit1,button1
it thrown sigsevg error at line "if not (txt=avalue) then"
if comment it then other sigsevg error occur at line 403b00
please help

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }
  valueeventhandler =procedure (newvalue:string) of object;
  type varb=class(tobject)
     procedure setvalue(avalue:string);
     function getvalue:string;
  private
    txt:string;
    valchange:valueeventhandler;
  public
     property value:string read getvalue write setvalue;
     property valuechange:valueeventhandler read valchange write valchange;
  end ;
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure varbchange(txt:string) ;//of object;
  private
    { private declarations }
  public
    { public declarations }
    myvar:varb;
    constructor Create(aOwner:Tcomponent);override;//<-------------------------------Fix
  end;


var
  Form1: TForm1;

implementation

{$R *.lfm}

    { TForm1 }

    constructor TForm1.Create(aOwner:Tcomponent);override;
    begin
        Inherited Create(aOwner);
        myvar := varb.Create;//<-------------------------------Fixed,
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      myvar.value:='is first value and assign manual to label,then add value change event';
      label1.Caption:=myvar.value;
      myvar.valuechange:=@varbchange;
    end;
    procedure tform1.varbchange(txt:string);
    begin
        label1.caption:=myvar.value;
    end;

    procedure varb.setvalue(avalue:string);
    begin
         if not (txt=avalue) then
          begin
          txt:=avalue;
          if assigned(valuechange) then
             valuechange(avalue);
          end;
    end;
    function varb.getvalue:string;
    begin
        result:=txt;
    end;
end.
                             
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

vkhoa

  • New Member
  • *
  • Posts: 47
Re: property write method implement go sigsevg error
« Reply #3 on: May 26, 2014, 01:40:19 pm »
thanks blaazen so much
I forgot doing that, perhap all class must be created before using
« Last Edit: May 26, 2014, 01:55:28 pm by vkhoa »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8774
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: property write method implement go sigsevg error
« Reply #4 on: May 26, 2014, 05:49:15 pm »
Quote
I forgot doing that, perhap all class must be created before using
Except for class var, class const, class type and class method, you must create the instance first.

vkhoa

  • New Member
  • *
  • Posts: 47
Re: property write method implement go sigsevg error
« Reply #5 on: June 04, 2014, 10:31:30 am »
that is new for me, thanks

 

TinyPortal © 2005-2018