Jump to content


Photo

How to impliment undo.

undo

  • Please log in to reply
5 replies to this topic

#1 lsquez

lsquez
  • Members
  • 18 posts

Posted 30 July 2017 - 09:09 PM

Hello,

 

I'm at the end of my development cycle with this new component. I am having difficulty implementing an undo feature. Basically I need to save the contents of several columns to an undo variable.

 

I need a suggestion of what event I could place the save code in.

 

I’ve tried using the TNxButtonEdit6.OnEnter event with some success. The only problem is it works if the end user presses enter with the change, or if they move to a column without an inplace editor. If they move up or down in the same column, the event fires again and my undo is lost.

 

Do you have a suggestion of what event I can use so that the save would work correctly?

 

Thanks,

 



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 31 July 2017 - 11:44 PM

Hi,

Maybe article on this page may help you:

http://developer.ber...=683&lang=en-us

Maybe in your case OnAcceptEdit or OnAfterEdit is best fit. I definitely recommend reading this page.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 lsquez

lsquez
  • Members
  • 18 posts

Posted 09 August 2017 - 02:42 AM

I thought I give you and update. The suggestion worked perfectly. I also thought I'd supply some code as an example as other users have asked about implementing an undo.

 

{Add the following variable to your form's variables, after the form variable}
{This is needed to check and see if the NextGrid has changed between the }
{NextGrid1BeforeEdit and the NextGrid1AcceptEdit events}

var
  Form1: TForm1;
  LastValue: WideString;

{Use the following events...}

procedure TForm1.NextGrid1BeforeEdit(Sender: TObject; ACol, ARow: Integer;
  var Accept: Boolean; var Text: WideString);
begin
  {Set to accept changes to the NextGrid by default}
  Accept := True;

  {Save the value of the cell to the variable before any changes.}

  {This is for testing for saving an undo AND to test for a change to the Grid}
  LastValue := Text;

  {Place other tests before the editing of the NextGrid here...}
  {Example}
  {This example prevents editing if the user selects Col1 and there is no text in the Row on Col2}

  if (NextGrid1.SelectedCol = 1) AND (NextGrid1.Cells[2, NextGrid1.SelectedRow] = '') then
  begin
    Accept := False;
  end
  else
  begin
    Accept := True;
  end;

End;

procedure TForm1.NextGrid1AcceptEdit(Sender: TObject; ACol, ARow: Integer;
  var Text: WideString; var Accept, CanLeave: Boolean);
begin
  {Here we save the undo if the user accepts the change}

  {Here we test to see if there was a change using the 'LastValue' variable}
  If (LastValue <> Text) Then
  begin

    {Here you call your save undo procedure, or place the code here}
    SaveUndo;

    {Reset the 'LastValue' variable for the next time}
    LastValue := '';
  end;

end;

procedure TForm1.NextGrid1AfterEdit(Sender: TObject; ACol, ARow: Integer;
  Value: WideString);
begin

  {Here you place whatever the code you want that is changing the NextGrid}
  {Since this event fires AFTER the 'NextGrid1AcceptEdit' event, you can undo or revert back by calling a REDO procedure}

  {Example}
  {This tests to see if the user has selected Col2 AND there is a value in the Row of Col2, then it places a check in Col0}

  If (NextGrid1.SelectedCol = 2) AND (NextGrid1.Cells[2, NextGrid1.SelectedRow] <> '') then
  begin
     NextGrid1.Cell[0, NextGrid1.SelectedRow].AsBoolean := True;
  end;

end;



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 August 2017 - 10:10 AM

Great and thanks :)
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 lsquez

lsquez
  • Members
  • 18 posts

Posted 18 August 2017 - 04:49 AM

Found this component to implement a multi-level undo-redo. When I try to use NextGrid1.SaveToStream(variable); I get a 'Undeclared identifier: 'SaveToStream' when compiling.

 

What am I doing wrong?

 

http://torry.net/vcl...llaUndoRedo.zip

 

Thanks,



#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 18 August 2017 - 11:43 PM

Hi,

It's not exist in my control. I have it in v5, but not yet in v6 (will probably re-use code).

I will need to implement probably Cells.SaveToStream method.

If you want you can copy/paste code from v5 and use it in your project until I implement it inside NextGrid6.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users