Extended or New TurboVision Objects


Q. 403 How do my inputlines get Cut/Paste capabilities?
The standard inputline doesn't provide this, but it is not difficult to create one. The following code was posted more or less by Michael Charles Carney to the TurboVision mailinglist and implements the Paste capability. I probably add the Cut/Copy facilities in the next release of this FAQ.
   type
     PLayoffInputLine = ^TLayoffInputLine;
     TLayoffInputLine = object(TInputLine)
       procedure HandleEvent(var event: TEvent);  virtual;
     end;

   procedure TLayoffInputLine.HandleEvent (var Event: TEvent);

     procedure ClipPaste(var Buf : PEditBuffer;
                         Offset, Length : word);
     var
       rec : string;
     begin
        rec := '';
        {--- Check to make sure we don't exceed field length ---}
        if Length > MaxLen then
          Length := MaxLen;

        {--- Copy contents of clipboard to input line ---}
        Move(Buf^[Offset], Rec[1], Length);

        {--- Set the length of the string ---}
        Rec[0] := Char(Length);

        {--- Set the data in the dialog ---}
        SetData(rec);
     end;

   begin
     inherited HandleEvent(Event);
     if (Event.What and evCommand <> 0) and
        (Event.Command = cmPaste) then  begin
       with ClipBoard^ do
         ClipPaste(Buffer, BufPtr(SelStart), SelEnd - SelStart);
       ClearEvent(Event);
     end;
   end;
Note: cmShiftIns should be defined to return cmPaste. Another option is to check for (Event.What = evKeyBoard) and (Event.KeyCode = kbShiftIns).

Next question


B de Boer Last modified: Tuesday 18 April 1995 - 10:20