Libraries
WebHub
ZaphodsMap
TPack
NativeXml
ldiRegEx
|
|
| | Class | Overview | Properties | Methods | Events | Variables | Verbs | Inheritance | | |
Declaration
Unit
Description
Web Action component with save-state property and behavior.
See also: TwhWebAction which was added in v2.019.All web action components can be invoked by name from WebHub HTML, e.g. (~WebAction1.execute~).
Use TwhWebActionEx as-is, or base your own custom classes on it.
When you call an action component by name using WebHub macro syntax, you are calling its Execute method. Performance is faster if you say (~webaction1.execute~) than if you omit the .execute method name. Regardless, this gives you an extremely powerful way to extend WebHub's capabilities. Any action that you want to call from the web can be triggered in this way. You can start your testing by using the TwhWebActionEx component on the palette, and if/when you want to take the next step, you can build your own custom component. There are many examples with source code in the webhub\lib directory that you may model.
An action component has a tpUpdated property which tells you whether it is ready, and a Test property which invokes the doUpdate method -- enabling full functionality in the Delphi IDE as well as at run-time. These verbs of Test and Update also appear within the TtpActionList associated with the component, and on the TtpVerbBar.
Simple 'hello' Example
procedure TfmAppSendStr.webAction1Execute(Sender: TObject);
begin
inherited;
// this code will run when (~webaction1.execute~) is called.
with TwhWebAction(Sender).Response do
begin
SendHdr('2','Welcome');
Send('Enter any string here...'); // It is ok to use parentils to reference droplets here.
end;
end;
Working with Parameters
WebHub syntax allows you to pass parameters to web action components. This is how the hello world component could be called with a parameter: %=webaction1.execute|hello=% (recommended) or %=webaction1.execute;hello=% (also supported).WebHub v1.49+ stores the parameter in the HtmlParam property. Here is how you would access the data within the OnExecute event handler, in this case to print the data in uppercase and bold.
procedure TfmAppSendStr.webAction1Execute(Sender: TObject);
var
a1:string;
begin
inherited;
with TwhWebAction(Sender).Response do
begin
a1:=uppercase(HtmlParam);
Send('<b>'+a1+'</b>');
end;
end;
Working with Command Strings
WebHub also supports command strings (as opposed to parameters stored in HtmlParam). If you are using v1.49+ you should use the syntax above instead.The following list itemizes how a command string can be made available to a TwhWebActionEx component:
- Any command string on the URL will be stored in TwhApplication.Command. (Advanced note: to handle multiple command
strings passed to multiple executions of the same TwhWebActionEx component within a page, see
the TtpAction.RemoveCommandPortion method.)
- Any command string on the URL that has the component name as a prefix, e.g. ?AppID:PageID:Session:ComponentName.Command, will
be included in TwhApplication.Command and will be set as TwhWebActionEx.Command. The TwhWebActionEx.OnSetCommand event handler is called in this case.
- Any command string on the URL that has no component name prefix is considered global to all TwhWebActions executed within the page, e.g. ?AppID:PageID:Session:Command. Such a command string will be stored in TwhApplication.Command and in TwhWebActionEx.Command, and the OnSetCommand event handlers will be called accordingly.
- Any command string passed to the component in W-HTML using this syntax: %=webaction1.command=% where the dot ('.') separates the name of the component from the command string.
When to use a TwhWebActionEx component
Use a web action component to trigger any custom action. Your other alternative would be using a custom event macro. Using a web action component gives you a few advantages over event macros:- You have a place to put initialization code (onUpdate), independent of the action code (onExecute)
- If you later decide to make the functionality generic by building your own web action component, you will be much closer to the correct coding style
- You do not have to itemize anything under TwhApplication.events
Events
All action components have these events of interest:- onUpdate -- called at least once when the components update themselves when the WebApp starts
- onSetCommand -- called when the Command property is set
- onExecute -- called just before the component executes
Running DynHelp.exe v1.2.0.9 on WebHub-v2.167 built by d16_win32
Calc time: 171 ms

TwhWebActionEx Class