Code sample for Inplace Editor

I need to create a "special" Inplace Editor to edit custom properties of my Blox Shapes. Could you provide a "simple" code snippet how to create such an editor ???

Hello,

This is a small example of how to use the different events for the inplace editor.

In GetInplaceEditorClass, you can set the type of edit item that needs to be created.

procedure TForm2.TMSFNCBloxControl1GetInplaceEditorClass(Sender: TObject;
  AElement: TTMSFNCBloxElement;
  var AInplaceEditorClass: TTMSFNCBloxInplaceEditorClass);
begin
  AInplaceEditorClass := TComboBox;
end;

With SetInplaceEditorData, you can customize the editor based on the element type and retrieve the text that is already in the block.

procedure TForm2.TMSFNCBloxControl1SetInplaceEditorData(Sender: TObject;
  AElement: TTMSFNCBloxElement; AInplaceEditor: TControl; var AText: string);
begin
  if AText <> '' then
  begin
    TComboBox(AInplaceEditor).Items.Add(AText);
    TComboBox(AInplaceEditor).ItemIndex := 0;
  end;
  TComboBox(AInplaceEditor).Items.Add('One');
  TComboBox(AInplaceEditor).Items.Add('Two');
end;

SetInplaceEditorElementData is to retrieve the settings of the editor object and change the element if necessary, with the AText or the AElement parameter. You can also block the editor from closing or not allow the new value.

procedure TForm2.TMSFNCBloxControl1SetInplaceEditorElementData(Sender: TObject; AElement: TTMSFNCBloxElement; AInplaceEditor: TControl; var AText: string; var AAllow, AClose: Boolean);
var
  txt: string;
begin
  if (TComboBox(AInplaceEditor).ItemIndex >= 0) then
    AText := TComboBox(AInplaceEditor).Items[TComboBox(AInplaceEditor).ItemIndex]
  else
    AClose := False;
end;

By default the editor is shown full-size on the block, but you can customize this as well.

procedure TForm2.TMSFNCBloxControl1SetInplaceEditorSize(Sender: TObject;
  AElement: TTMSFNCBloxElement; AInplaceEditor: TControl; var ARect: TRect;
  var AAllow: Boolean);
begin
  ARect.Width := AInplaceEditor.Width;
end;