CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

IWCGJQFrameHelperUnit

Share your useful code here.

by JohnFSklavounos » 27 Sep 2013 16:15

Hello Everyone,

I find myself creating frames for dynamic inclusion into multiple forms so I've created this helper unit to make life a bit easier. Please feel free to use and improve it. If you make it better, please add your name, date and re-post it.

All my best,
John

delphi code
unit IWCGJQFrameHelperUnit;

/// =================================================================================================
///
/// Author: John F. Sklavounos
/// Date: 2013-09-26
///
/// Ownership:
/// You are free to use and distribute this code as you see fit. I only ask that improvements be
/// returned to the community at http://www.cgdevtools.com/cgforum/viewforum.php?f=109
///
/// Abstract:
/// This helper routine helps me keep the code straightforward for creating and destroying custom
/// frames that live inside a TIWCGJQRegion.
///
/// The idea for this came from the CG Developer Team in response to this post:
/// http://www.cgdevtools.com/cgforum/viewtopic.php?f=3&t=723
///
/// Basically I didn't want to rewrite or copy/paste this code into more than one place. I also
/// cleaned it up so there is only one function call to create a frame, regardless of whether or
/// not it's called from an OnCreate or a fired event.
///
/// Notes:
/// I would like to modify the CreateCGJQFrame so the Owner could be the common ancestor for
/// all possible components that can contain a frame. In other words, call the create using a
/// TIWAppForm, TIWCGJQRegion, TIWCGJQTab, TIWRegion, etc... I can't seem to find a common
/// ancestorso it may be that I'll have to create an override for each, but I'm hoping someone
/// will know, modify the code and return it to the community.
/// =================================================================================================

interface

uses
SysUtils, Classes, IWCGJQRegion, IWCGFrame, IWHTMLContainer, IWCGJQCommon, IWCGAsyncRender;

type TIWCGJQFrameHelper = class
class procedure CreateCGJQFrame(pOwner: TIWCGJQRegion; pFrameClass: TIWCGFrameClass; pParams: TStringList; var pFrame: TIWCGJQFrame);
class procedure DestroyCGJQFrame(var pIWCGJQFrame: TIWCGJQFrame);
end;

implementation

class procedure TIWCGJQFrameHelper.CreateCGJQFrame(pOwner: TIWCGJQRegion; pFrameClass: TIWCGFrameClass; pParams: TStringList; var pFrame: TIWCGJQFrame);
begin
///
/// Always destroy the existing frame when creating a new one. If the programmer wants more than one,
/// then there should be multiple frame variables and creates/destroys or an array of frames.
///
if Assigned(pFrame) then DestroyCGJQFrame(pFrame);
///
if CGIsCallBackProcessing then CGCallBackDisableAjaxResponse;
///
pFrame := pFrameClass.Create(pOwner);
///
pFrame.Name := pOwner.Name + '_' + pFrame.Name;
pFrame.Parent := pOwner;
///
/// If pParams is assigned (not nil) then we must complete the Ajax processing
///
if Assigned(pParams) then begin
pFrame.ProcessCommand(0, pParams);
if pOwner.WebApplication.CallBackProcessing then CGCallBackEnableAjaxResponse;
RenderRegionAsync(pOwner, False, True);
end;
end;

class procedure TIWCGJQFrameHelper.DestroyCGJQFrame(var pIWCGJQFrame: TIWCGJQFrame);
begin
FreeAndNil(pIWCGJQFrame);
end;

end.
John F. Sklavounos
Software Developer
Always learning

XE7: Update 1
FireDAC: 20.0.16277 (Build 1276)
IW: 14.0.41
CG : 2.6.0.100
JohnFSklavounos
 
Posts: 109
Joined: 14 Aug 2013 00:35
Location: Miami, FL

by Jorge Sousa » 27 Sep 2013 21:45

Johnny

WOW!!!

This is awesome!

Can we use it internally right?

Thanks a lot!

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

by JohnFSklavounos » 27 Sep 2013 22:29

Of course, I would be honored if you incorporated it somehow... :D

Best,
John
John F. Sklavounos
Software Developer
Always learning

XE7: Update 1
FireDAC: 20.0.16277 (Build 1276)
IW: 14.0.41
CG : 2.6.0.100
JohnFSklavounos
 
Posts: 109
Joined: 14 Aug 2013 00:35
Location: Miami, FL

by Jorge Sousa » 27 Sep 2013 23:36

Hi John

The common ancestor is TIWBaseContainer or TIWContainer? the same in ARegion parameter in RenderAnsyncRegion, I can't check right now, I'm cloning a Samsung SSD PRO 512 GB yay!

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

by Jorge Sousa » 27 Sep 2013 23:53

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

by JohnFSklavounos » 28 Sep 2013 15:45

I'll make the mods in a bit and test with the ancestor class. Thanks! :D
John F. Sklavounos
Software Developer
Always learning

XE7: Update 1
FireDAC: 20.0.16277 (Build 1276)
IW: 14.0.41
CG : 2.6.0.100
JohnFSklavounos
 
Posts: 109
Joined: 14 Aug 2013 00:35
Location: Miami, FL

by JohnFSklavounos » 28 Sep 2013 22:03

OK, Here's the updated code and we're looking good... :D We can now dynamically create and destroy frames in a bunch more containers than before. Thanks to CGDevTools for the insight into the ancestor classes.

delphi code
unit IWCGJQFrameHelperUnit;

/// =================================================================================================
///
/// Author: John F. Sklavounos, CGDevTools
/// Date: 2013-09-26
///
/// Ownership:
/// You are free to use and distribute this code as you see fit. I only ask that improvements be
/// returned to the community at http://www.cgdevtools.com/cgforum/viewforum.php?f=109
///
/// Abstract:
/// This helper routine helps me keep the code straightforward for creating and destroying custom
/// frames that live inside a TIWCGJQRegion.
///
/// The idea for this came from the CG Developer Team in response to this post:
/// http://www.cgdevtools.com/cgforum/viewtopic.php?f=3&t=723
///
/// Basically I didn't want to rewrite or copy/paste this code into more than one place. I also
/// cleaned it up so there is only one function call to create a frame, regardless of whether or
/// not it's called from an OnCreate or a fired event.
/// =================================================================================================

interface

uses
SysUtils, Classes, IWCGJQRegion, IWCGFrame, IWHTMLContainer, IWCGJQCommon, IWCGAsyncRender;

type TIWCGJQFrameHelper = class
class procedure CreateCGJQFrame(pContainer: TIWHTMLContainer; pFrameClass: TIWCGFrameClass; pParams: TStringList; var pFrame: TIWCGJQFrame);
class procedure DestroyCGJQFrame(var pIWCGJQFrame: TIWCGJQFrame);
end;

implementation

class procedure TIWCGJQFrameHelper.CreateCGJQFrame(pContainer: TIWHTMLContainer; pFrameClass: TIWCGFrameClass; pParams: TStringList; var pFrame: TIWCGJQFrame);
begin
///
/// Always destroy the existing frame when creating a new one. If the programmer wants more than one,
/// then there should be multiple frame variables and creates/destroys or an array of frames.
///
if Assigned(pFrame) then DestroyCGJQFrame(pFrame);
///
if CGIsCallBackProcessing then CGCallBackDisableAjaxResponse;
///
pFrame := pFrameClass.Create(pContainer.Owner);
///
pFrame.Parent := pContainer;
///
/// If pParams is assigned (not nil) then we must complete the Ajax processing
///
if Assigned(pParams) then begin
pFrame.ProcessCommand(0, pParams);
if pContainer.OwnerForm.WebApplication.CallBackProcessing then CGCallBackEnableAjaxResponse;
RenderRegionAsync(pContainer, False, True);
end;
end;

class procedure TIWCGJQFrameHelper.DestroyCGJQFrame(var pIWCGJQFrame: TIWCGJQFrame);
begin
FreeAndNil(pIWCGJQFrame);
end;

end.
John F. Sklavounos
Software Developer
Always learning

XE7: Update 1
FireDAC: 20.0.16277 (Build 1276)
IW: 14.0.41
CG : 2.6.0.100
JohnFSklavounos
 
Posts: 109
Joined: 14 Aug 2013 00:35
Location: Miami, FL

by cleversonviana » 25 Feb 2016 20:08

How to do this using the Mobile components ?

I mean, I want to create a Mobile Frame dynamic inside another frame in my main page.
cleversonviana
 
Posts: 19
Joined: 25 Feb 2016 19:56

by Alexander Bulei » 26 Feb 2016 10:00

Hi cleversonviana,

You need use the same method as in desktop.
Search for RenderRegionAsync or AjaxReRender methods in our forum.
Also, check the code of JohnFSklavounos.

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by scoluccia » 20 Apr 2016 23:19

Hi
if I write your code I get "webapplication.isCallBack must be False Error!"
it works only if I write:
if CGIsCallBackProcessing then CGCallBackEnableAjaxResponse;
instead of
if pContainer.OwnerForm.WebApplication.CallBackProcessing then CGCallBackEnableAjaxResponse;
scoluccia
 
Posts: 61
Joined: 11 Mar 2015 15:10

Next

Return to Community Code

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.