CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Create a TIWCGJQButton at runtime

by Davide » 24 Jan 2014 16:56

Hello,

I'm trying to create a TIWCGJQButton in a TIWCGJQRegion everything at runtime.
Following my code :

Code: Select all

function TMainForm.CreateMyRegion: TIWCGJQRegion;
var
   b: TIWCGJQButton;
   NewName: string;
begin
   if (CGIsCallBackProcessing) then
      CGCallBackDisableAjaxResponse;

   NewName:= CGFindUniqueComponentName(self, 'region');
   Result := TIWCGJQRegion.Create(Self);
   Result.Parent := ForumRegion;
   Result.Height := 100;
   Result.Align := alTop;
   Result.Name := NewName;
   Result.Color := clWebLIGHTCYAN;
   Result.Top := t;

   NewName:= CGFindUniqueComponentName(self, 'button');
   b := TIWCGJQButton.Create(Self);
   b.Parent := Result;
   b.Top := 20;
   b.Left := 8;
   b.Name := NewName;
   b.Caption := 'Press me';
   b.JQButtonOptions.OnClick.OnEvent := OnMyButtonClick;
end;

procedure TMainForm.OnMyButtonClick(Sender: TObject; AParams: TStringList);
begin
  WebApplication.ShowMessage(TIWCGJQButton(Sender).Caption + ' Pressed');
end;


When I try to click the button I receive an "Access violation" message and in fact the Sender parameter of the OnMyButtonClick function is empty.
What am I doing wrong?

I'm using XE5, IW 14.0.22, IWCGJQuery 1.8.0.3232.

Thank you,
Davide
Davide
 
Posts: 150
Joined: 14 Oct 2013 11:33

by Jorge Sousa » 24 Jan 2014 17:22

Hi

TIWCGJQButton(Sender)


The sender is always be the owner of the event

In this case JQButtonOptions

b.JQButtonOptions.OnClick.OnEvent := OnMyButtonClick;


so you must use

( Sender as TIWCGJQButtonOptions).Button
or
TIWCGJQButtonOptions(Sender).Buton

this last form it's not recommend, because while the first raises an EInvalidTypeCast error, the second causes a memory overrun

Regards
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58


Return to JQButton & JQButtonSet

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.