Forum > General

Create CheckBox on runtime, with Event. (Resolved)

(1/1)

pclevy:
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.

molly:
was

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ChkBx.OnClick:=OnArrClick should read:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ChkBx.OnClick:=@Form1.OnArrClick 

pclevy:
Thank you, Molly.
Thats ok now!!

pclevy:
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:
Thanks to all.
I have found the soluction.

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

Navigation

[0] Message Index

Go to full version