On the Getting started page, while discussing the Codolex.Activity.PlaySound.Pluggable.pas File, we mentioned something about implementing tags. Now that we have our component defined, we can add tags to complete the plugin definition.
An example of this can be found in the create variable activity of Codolex. This activity can also be found in the palette by searching for boolean. When you drag the activity into the flow while searching for "boolean", the variable type boolean is automatically selected.
We could implement this in our plugin for the Playmode selection.
We need to add IFlowPluggableComponentWithTags to the pluggable class interfaces, and add the functions GetTags and Initialize.
function GetTags: TArray<string>; procedure Initialize(const FlowComponent: IFlowComponent; const WithTag: string); |
In the GetTags function, we can define a string array that contains all the tags the activity can be found on. I will add "Async" and "Loop" in this section.
function TPlaySoundPluggableComponent.GetTags: TArray<string>; begin Result := ['Async', 'Loop']; end; |
In the Initialize procedure, we need to set the value based on the selected tag. The WithTag parameter contains the selected tag. We can check if that tag was async or loop, and then assign the correct playmode.
procedure TPlaySoundPluggableComponent.Initialize(const FlowComponent: IFlowComponent; const WithTag: string); var Activity: IFlowActivityPlaySound; begin if not Supports(FlowComponent, IFlowActivityPlaySound, Activity) then raise EInvalidOpException.CreateFmt(ValidationNotAvailableForActivity, [FlowComponent.ComponentName]); if WithTag = 'Loop' then Activity.PlayMode := TPlayMode.SND_LOOP else if WithTag = 'Async' then Activity.PlayMode := TPlayMode.SND_ASYNC; end; |
With this, it is easier for the user of this activity to directly select the right Playmode.