Author Topic: Error in docs Selection functions example  (Read 4527 times)

Graeme

  • Senior Community Member
  • Posts: 2748
  • Hero Points: 340
Error in docs Selection functions example
« on: April 12, 2008, 12:41:46 pm »
The current slick help file appears to have some errors in the example in the "Selection Functions" topic.  I had to go back to slick V8 help file to get what appears to be a correct version  - here's the V8 help example code, followed by 2008 code, followed by a suggested fix.  Spot the difference.  I count 3 differences plus a semicolon missing from both versions.

Graeme

// slick V8 help
Code: [Select]
//  Duplicate the current line.
mark_id=_alloc_selection();
//
if (mark_id<0) {
   message(get_message(mark_id));
   return(rc);
}
_select_line(mark_id);
_copy_to_cursor(mark_id);
// This selection can be freed because it is not the active selection.
_free_selection(mark_id);

// This code copies selected text and keeps the resulting selection on
//  the source text instead of the destination text.
if (_select_type()==""){
   message(get_message(TEXT_NOT_SELECTED_RC));

   return(1);
}
mark_id=_duplicate_selection()   // Make a copy of the active selection.
_copy_to_cursor();
// Save the active selection id.
old_active_mark_id= _duplicate_selection("");
// Must make another mark active before the old active mark can
// be freed.
_show_selection(mark_id);           // Make copy of visible mark active
_free_selection(old_active_mark_id);


Slick V2008 help
Code: [Select]
    //  Duplicate the current line.
    mark_id=_alloc_selection();
    //
    if (mark_id<0) {
       message(get_message(mark_id));
       return(rc);
    }
    _select_line(mark_id);
    _copy_to_cursor(mark_id);
    // This selection can be freed because it is not the active selection.
    _free_selection(mark_id);
   
    // This code copies selected text and keeps the resulting selection on
    //  the source text instead of the destination text.
    if (_select_type()==""){
       message(get_message(TEXT_NOT_SELECTED_RC));
       return(1);
    }
    mark_id=_duplicate_selection()   // Make a copy of the active selection.
    _copy_to_cursor();
    // Save the selection id.
    old_active_mark_id=
    duplicate_selection();
    // Must make another mark active before the old active mark can
    // be freed.
    show(selection(mark_id));     // Make copy of visible mark active
    free(selection(old_active_mark_id));

Here's what it maybe should be
Code: [Select]
   // Example 1
   // Duplicate the current line.
   int mark_id=_alloc_selection();
   
   if (mark_id<0) {
      message(get_message(mark_id));
      return(rc);
   }
   _select_line(mark_id);
   _copy_to_cursor(mark_id);
   // This selection can be freed because it is not the active selection.
   _free_selection(mark_id);
   return 0;


   // Example 2
   // This code copies selected text and keeps the resulting selection on
   // the source text instead of the destination text.
   if (_select_type()==""){
      message(get_message(TEXT_NOT_SELECTED_RC));
      return(1);
   }
   int mark_id=_duplicate_selection();   // Make a copy of the active selection.
   _copy_to_cursor();
   // Save the active selection id.
   int old_active_mark_id= _duplicate_selection("");
   // Must make another mark active before the old active mark can
   // be freed.
   _show_selection(mark_id);           // Make copy of visible mark active
   _free_selection(old_active_mark_id);
   
   return 0;