01-24-2024, 06:36 AM
(01-24-2024, 05:57 AM)Alexandre Machado Wrote: Hi Ren,
when using a template you can still create controls at runtime but you need to specify the parent Id of the HTML element that will be the parent of the control. In this case you must use the event OnFindParentId of the TIWTemplateProcessorHTML component.
Have a look at this simple code that reflects your example above:
Code:procedure TIWForm1.IWTemplateProcessorHTML1FindParentId(Sender: TIWTemplateProcessorHTML; AContainerContext: TIWContainerContext;
const AComponent: TComponent; out AParentId: string);
begin
if (AComponent is TIWButton) and SameText(AComponent.Name, 'IWButton1') then
begin
AParentId := 'SOME_DIV_ID';
end;
end;
Here I'm telling IW to put the newly created TIWButton parented to a DIV (an HTML element) named 'SOME_DIV_ID'
Let's say you want to the button parented to an IWRegion, named IWRegion1, then you will have:
Code:procedure TIWForm1.IWTemplateProcessorHTML1FindParentId(Sender: TIWTemplateProcessorHTML; AContainerContext: TIWContainerContext;
const AComponent: TComponent; out AParentId: string);
begin
if (AComponent is TIWButton) and SameText(AComponent.Name, 'IWButton1') then
begin
AParentId := 'IWREGION1';
end;
end;
Can you please give it a try and let me know if it worked?
I tried it can add to even a <div> that only exist on html templates,
but my main concern is, on page refresh its gone, although the component still exist.
TestFindParentId.zip (Size: 1.6 KB / Downloads: 6)