Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Handling the Delete Shortcut in an Inplace Editor

I have fairly complicated UI with an ELXtree in a frame within a dialog. I have the common Delphi issue that Actions in the main form are stealing the Delete Key Shortcut to the inplace editor. I can trap the Delete Key by adding an action to the frame but I can't figure out a way to get the inplace editor to perform the character deletion. 

Backspace works correctly but I have similar issues with the Cut, Copy and Paste shortcuts.

Mitch Wolberg,
RockWare, Inc.

Comments

  • 8 Comments sorted by Votes Date Added
  • A similar question was asked here: Make the Editor...

  • I looked at that one but it doesn't explain how to actually delete the character. Just triggering the tree's KeyDown event doesn't do it.
  • To make it a bit clearer, here's some code where I delete a character from an inplace editor in a TStringGrid:

             if EditorMode then begin  
               target := InplaceEditor ;
               if target.SelLength = 0 then target.SelLength := 1 ;
               target.SelText := '' ;
               end

    So how do I do this with an inplace editor in an ELXTree? Including code for actually getting the editor and status from a Selected item.


  • I didn't mention that we're using pooled editors.
  • The ProcessCtrlVAction has Ctrl+V as the shortcut.

    Define an Action for your control keys (including default actions for copy,paste, Del, etc.

    Tested and working:

    procedure TForm1.ProcessCtrlVAction(Sender);
    var
      Shift : TShiftState;
      Key   : Word;
    begin
      if InplaceStr.Editing then
      begin
        Key   := Ord('V');
        Shift := [ssCtrl];

        ItemTree.OnKeyDown(Sender, Key, Shift);
      end
      else // not InplaceStr,Editing
      begin
        PasteTextualItems();
      end;
    end;

    Raymond
    (giving something back)
  • A better way:

    if InplaceStr.Editing then
    begin
        SendMessage(InplaceStr.Editor.Handle, WM_PASTE,0,0);
    end
    else // not InplaceStr.Editing
    begin
        ...
    end;
  • Here's my code for the Del action.

    It works for both deleting Selected text and a single character.

    var
      S      : String;
      SelPos : Integer;
    begin
      with InplaceStr do
      begin
        if Editing then
        begin
          with Editor do
          begin
            SelPos := Succ(SelStart);

            if SelLength = 0 then
            begin
              SelLength := 1;
            end;

            S := Text;

            Delete(S, SelPos, SelLength);

            Text := S;

            SelStart := Pred(SelPos);
          end;
        end
        else // not InplaceStrActive
        begin
          DeleteItems(amFocused);
        end;
      end; {with}
    end;

    Raymond
Sign In or Register to comment.