Por: Doychin Bondzhev
Resumo: Article describes how to use an undocumented feature in IntraWeb to create complex controls that require multiple tags.
My name is Doychin Bondzhev. I'm from Bulgaria and I was working for Atozed Software as senior developer on core parts of IntraWeb. Right now I work at my own company called dSoft-Bulgaria where we do J2EE projects, so probably my next article will
be based on my current work on some Java stuff we did here. This is my first article on computer subject
so it will be very short. I will try to show you how to
generate complex HTML code when doing custom
For each of these platforms there is a base control and base component
As you can see there is 2 possibilities for control ancestors for HTML. The
reason these 2 are there is because the versions before
IntraWeb 6 had only one
class for HTML controls and it was TIWControl/TIWControl32 correspondingly.
In version 6 TIWCustomControl and TIWCustomControl32 were introduced as
ancestor classes for HTML based controls and also the methods that were used to
support input functionality were removed from the base classes.
So in order to create an input control you have to descends from
TIWCustomControl and implement IIWInputControl when you control will receive
value from the browser and IIWSubmitControl if it will be submit control.
For example TIWEdit implements both interfaces because it receives value from
the browser and also can trigger submit.
For more information and how to use these interfaces you can check the
So as you can see you can do a lot of things with
IntraWeb but lets talk
about Markup Language generation. For HTML code when you create a descendant
class you have to override RenderHTML method. This method returns result of type
TIWHTMLTag. For WML/XHTMLMP there is another method RenderWAP with result type
TIWWAPTag. In both cases you can use the technique I will describe later. Of
course there must be some reason to do this.
Lets see what happens after we create our HTML tag object and return it as
result. There is few things that happen and they all depend on the way your form
is configured. For example additional attributes are added if your control is
input control. Also it could be placed inside other HTML tags for some reason.
Layout managers also make changes to tag objects. If you use partial update mode all html tags for one control are placed inside
one SPAN tag so they can be later modified by Update code. All these changes and
modifications are applayed to the tag that we return as result from RenderHTML
As you can see you have to have all these things in mind when you create your
own controls. Of course there is one feature in TIWHTMLTag class that is not
documented at all in IntraWeb.
Sometimes we need to create complex controls which cosists from more HTML tags
not from only one. This is not a problem when we create for example non input
control. But for input controls we have to probvide an INPUT tag that will be
used as holder of the value of the control.
For that purpose we need to construct complex HTML tags like this:
and in this case we have to return as result the HTML Tag object that is for
INPUT tag which will receive all additional attributes
In order to achieve this we will use this code in our RenderHTML method:
function TMyTestIWControl.RenderHTML(AContext: TIWBaseHTMLComponentContext): TIWHTMLTag;var ownerTag: TIWHTMLTag;
begin ownerTag := TIWHTMLTag.CreateHTMLTag(''); with ownerTag.Contents.AddTag('SPAN') do begin Contents.AddText('Label value'); end; result := TIWHTMLTag.CreateHTMLTag('INPUT', cbSimpleClose); with result do begin AddStringParam('type', 'hidden'); end; ownerTag.Contents.AddTagAsObject(result, true);
In order to test this create new IntraWeb standalone application for HTML 4.
Append one new Unit and in this unit define new control class that descends from
TIWControl. We choose TIWControl in order to use built in support for submit and value. Override RenderHTML method and into it's body copy code from
Now in Form onCreate event handler add this code:
with TMyTestIWControl.Create(self) do begin Parent := Self;end;
That's it for now. I hope you enjoyed reading this article.
Try Delphi XE4 free for 30 days
New Instant Trial!
Webinars on demand!
More social media choices:
Delphi on Google+
@RADTools on Twitter
Server Response from: ETNASC02