Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

An example of undo/redo

339 views
Skip to first unread message

Ed Wilson

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
Anyone out there know where I can find an example of how to implement an
undo/redo system for an application? I know that undo for an edit is a
Windows message and the actual code is kept within Microspot's secret
archives... I just want an example of how one would go about implmenting
an undo/redo setup in a program.

Thanks

Ed Wilson
Training Technologies, Inc.


Rick Rogers (TeamB)

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
> I know that undo for an edit is a Windows message and the actual
> code is kept within Microspot's secret archives...

EM_UNDO

> I just want an example of how one would go about implmenting
> an undo/redo

Delphi encapsulates this for you:

if Screen.ActiveControl is TCustomEdit then
TCustomEdit(Screen.ActiveControl).Undo;

If you want undo/redo to work with more than just edit controls, you'll need
to implement appropriate logic in your application, such as a command stack.

- Rick

Rene Tschaggelar

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
You make a stack of commands, where each push has sufficinent
information to undo the operation. A pop retrieves this command
and reverses the action.

Insert char into text : push position+char
..

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com


Ed Wilson wrote:
>
> Anyone out there know where I can find an example of how to implement an

> undo/redo system for an application? I know that undo for an edit is a


> Windows message and the actual code is kept within Microspot's secret

Ed Wilson

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
Ok... guess I'll have to actually use my braincells... was looking for an
example of the "wheel" rather than to have to re-invent it again... :)
vcard.vcf

Ed Wilson

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
Actually Rick... if you delve deep into the VCL... TCustomEdit.Undo actually
posts a WM_UNDO message to the subclassed Windows Edit control... so Delphi
doesn't really do a thing other than make it a method call... what I'm LOOKING
for is an example of how to do multiple undo/redo commands within an
application... something that, for example, Microsoft Word does... but the basic
Edit control doesn't.

Ed Wilson
Training Technologies, Inc.

Rick Rogers (TeamB) wrote:

> > I know that undo for an edit is a Windows message and the actual
> > code is kept within Microspot's secret archives...
>

> EM_UNDO


>
> > I just want an example of how one would go about implmenting
> > an undo/redo
>

Rick Rogers (TeamB)

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
> so Delphi doesn't really do a thing other than make it a method call...

Yes, this is manifestly obvious.

> what I'm LOOKING for is an example of how to do multiple
> undo/redo commands

I gave you the general approach in the last paragraph of my previous message
(please re-read). You could also see the book _Design Patterns_ by Gamma et
al. which documents a design for a command stack.

- Rick

Rene Tschaggelar

unread,
Sep 29, 1999, 3:00:00 AM9/29/99
to
It is not that difficult. You can use a stack as listed on
one of my delphi pages. The point is that you have to be able
to reverse some actions. Therefore you have to think before
you implement the actions itself. How do you reverse :

replace all 'A' by 'B' ..

The less actions you allow, the less you have to reverse.
You may understand why there is no such component.

Good luck.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Ed Wilson wrote:
>
> Ok... guess I'll have to actually use my braincells... was looking for an
> example of the "wheel" rather than to have to re-invent it again... :)
>
> Rene Tschaggelar wrote:
>
> > You make a stack of commands, where each push has sufficinent
> > information to undo the operation. A pop retrieves this command
> > and reverses the action.
> >
> > Insert char into text : push position+char
> > ..
> >
> > Rene
> > --
> > Ing.Buero R.Tschaggelar - http://www.ibrtses.com
> >
> > Ed Wilson wrote:
> > >
> > > Anyone out there know where I can find an example of how to implement an

> > > undo/redo system for an application? I know that undo for an edit is a


> > > Windows message and the actual code is kept within Microspot's secret

> > > archives... I just want an example of how one would go about implmenting
> > > an undo/redo setup in a program.
> > >
> > > Thanks
> > >

oz

unread,
Sep 30, 1999, 3:00:00 AM9/30/99
to
Rene Tschaggelar <tscha...@access.ch> wrote:

>It is not that difficult. You can use a stack as listed on
>one of my delphi pages. The point is that you have to be able
>to reverse some actions. Therefore you have to think before
>you implement the actions itself. How do you reverse :

>replace all 'A' by 'B' ..

<snip>
Rene...
is what you are trying to illustrate by your example above that
the equivalent "undo" operation is -not- a simple
Replace All 'B' by 'A'
because that will change pre-existing B's to A's that were not
A's in the first place?

Just askin'
Oz

Ed Wilson

unread,
Oct 1, 1999, 3:00:00 AM10/1/99
to
It's ok oz... I understood what she actually meant. Perfection in
conversation isn't a required item when both parties are capable of
understanding the concepts.

Ed Wilson
Training Technologies, Inc.

vcard.vcf

Barry Brown

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to
Ed,
I did this, and it was a heap of work. If you like, I'll email to you
my "HistoryList" component, which does part of the job. It comes with
no help file, no example project, and most importantly, no support
from me. I figure that someday I'll finish up some of these niceties
and stick it in Code Central, when I have the time (whenever that is).

The Design Patterns book discusses an Undo/Redo list under the Command
Pattern (sec 2.7).

Barry Brown
ba...@vnahelp.com

Ed Wilson wrote in message <37F0CFCF...@traintech.com>...

0 new messages