Using custom inplace editors is possible with the Parameter controls but require some preparing of the inplace editor to be used correct. The custom inplace editor is invoked with the style ‘CUSTOM’, ie:
Parameter control events
When the custom inplace editor is about to be edited, the event OnParamCustomEdit is triggered with parameters:
For TParamLabel:
TParamCustomEditEvent = procedure(Sender: TObject; href, value, props: string; EditRect: TRect) of object;
For TParamListBox and TParamCheckList:
TParamCustomEditEvent = procedure(Sender: TObject; idx: Integer; href, value, props: string; EditRect: TRect) of object;
For TParamTreeView:
TParamCustomEditEvent = procedure(Sender: TObject; Node: TTreeNode; href, value, props: string; EditRect: TRect) of object;
The href parameter is the unique ID of the parameter in the control. The value parameter contains the current value of the parameter, the props parameter the value of the PROPS attribute. Last parameter is the rectangle where the inplace editor should be positioned. For the TParamListBox and TParamCheckList, an additional idx parameter refers to the item in the list where the parameter is located, for the TParamTreeView, the Node parameter refers to the node where the parameter is located.
From this event, following code can be used to show the custom inplace edit control:
mycustomcontrol.Parent := Sender;
mycustomcontrol.left := EditRect.Left;
mycustomcontrol.Top := EditRect.Top;
mycustomcontrol.Text := value;
mycustomcontrol.Param := href;
mycustomcontrol.OnUpdate := (Sender as TParamlabel).ControlUpdate;
mycustomcontrol.Visible := true;
mycustomcontrol.SetFocus;
The ControlUpdate procedure is defined in the parameter component and will set the new parameter value when the editing is done. ControlUpdate is defined as:
procedure ControlUpdate(Sender: TObject; Param,Text:string);
with Param the unique parameter identifier and Text the parameter value to set.
Preparing the inplace edit control
Create a descendent component of the inplace edit control with following properties and events:
TParamUpdateEvent = procedure(Sender: TObject; Param, Text: string) of object;
TMyCustomControl = class(TMyControl)
private
FParam: string;
FOnUpdate: TParamUpdateEvent;
procedure WMActivate(var Message: TWMActivate); message WM_ACTIVATE;
protected
procedure DoExit; override;
procedure CreateParams(var Params: TCreateParams); override;
public
property Param: string read FParam write FParam;
property OnUpdate: TParamUpdateEvent read FOnUpdate write FOnUpdate;
end;
The implementation for this descendent control is then:
{ TMyCustomControl }
procedure TMyCustomControl.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do
Style := Style AND NOT WS_CHILD OR WS_POPUP;
end;
procedure TMyCustomControl.DoExit;
begin
inherited;
if Assigned(OnUpdate) then
OnUpdate(Self,Param,Text);
end;
procedure TMyCustomControl.WMActivate(var Message: TWMActivate);
begin
inherited;
if Message.Active = 0 then
Hide;
end;
Using the custom inplace editor can be done by putting a component on the form where the parameter control is used and set its visible property to False. The inplace editor will then be displayed when the OnParamCustomEdit event is triggered.