Recent

Author Topic: Create CheckBox on runtime, with Event. (Resolved)  (Read 3128 times)

pclevy

  • Newbie
  • Posts: 4
Create CheckBox on runtime, with Event. (Resolved)
« on: November 05, 2015, 07:13:12 am »
I do this code, but the error "unit1.pas(65,18) Error: Identifier not found 'OnArrClick' ", still apears!!
I need help.

------------------------
unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);

  private
    { private declarations }
    procedure OnArrClick( Sender: TObject );
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }
procedure CriarChkBox(); forward;

procedure TForm1.OnArrClick(Sender: TObject);
begin
  ShowMessage(Sender.ClassName);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     CriarChkBox;
end;

procedure CriarChkBox();
var
  xLeft,yTop: integer; ChkBx:TCheckBox;
begin
  xLeft:=2; yTop:=2;
  ChkBx:=TCheckBox.Create(Form1);
  ChkBx.parent:=Form1;
  ChkBx.Top:= yTop;
  ChkBx.Left:= xLeft;
  ChkBx.Caption := 'ChkBx New';
  ChkBx.Checked := True;
  ChkBx.OnClick:=OnArrClick;
end;

end.
« Last Edit: November 06, 2015, 07:54:28 am by pclevy »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Create CheckBox on runtime, with Event.
« Reply #1 on: November 05, 2015, 07:16:05 am »
was
Code: Pascal  [Select][+][-]
  1. ChkBx.OnClick:=OnArrClick
  2.  
should read:
Code: Pascal  [Select][+][-]
  1. ChkBx.OnClick:=@Form1.OnArrClick
  2.  

pclevy

  • Newbie
  • Posts: 4
Re: Create CheckBox on runtime, with Event.
« Reply #2 on: November 05, 2015, 07:49:35 am »
Thank you, Molly.
Thats ok now!!

pclevy

  • Newbie
  • Posts: 4
Re: Create CheckBox on runtime, with Event.
« Reply #3 on: November 06, 2015, 07:11:24 am »
I have one more problem:
this error:
unit1.pas(37,22) Error: identifier idents no member "Tag"

for the code down:

unit Unit1;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);

  private
    { private declarations }
    procedure OnArrClick( Sender: TObject );
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }
procedure CriarChkBox(); forward;

procedure TForm1.OnArrClick(Sender: TObject);
begin
  ShowMessage(Sender.Tag);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     CriarChkBox;
end;

procedure CriarChkBox();
var
  xLeft,yTop: integer; ChkBx:TCheckBox;
begin
  xLeft:=2; yTop:=2;
  ChkBx:=TCheckBox.Create(Form1);
  ChkBx.parent:=Form1;
  ChkBx.Top:= yTop;
  ChkBx.Left:= xLeft;
  ChkBx.Caption := 'ChkBx New';
  ChkBx.Checked := True;
  ChkBx.Tag := 1;
  ChkBx.OnClick:=@Form1.OnArrClick;
end;

end.

pclevy

  • Newbie
  • Posts: 4
Re: Create CheckBox on runtime, with Event.
« Reply #4 on: November 06, 2015, 07:53:48 am »
Thanks to all.
I have found the soluction.

change  "Sender.Tag "  by  "TCheckBox(Sender).Tag "


 

TinyPortal © 2005-2018