BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Not an OPF question <g>: Find&Replace classes for text edito

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Andrea Raimondi
Guest





PostPosted: Thu Dec 04, 2003 9:35 am    Post subject: Not an OPF question <g>: Find&Replace classes for text edito Reply with quote



Yes,

I'm doing another OS program <g>.
This time it's a programming editor with some goodies Smile
( you'll have to wait to know what they are <g>).

Anyone can show me a good class interface for Find&Replace so that it
integrates in a good way with Delphi Find & Replace dialogs?

I was thinking, for Find, to something like this:

Type

TSearchDirection = ( sd_Up,sd_Down );
TTextSearch = class
protected
procedure DoFind;virtual;abstract;
public
constructor Create;virtual;
procedure Find;
property FindText : String;
property SearchDirection : TSearchDirection;
end;

TFind = class( TTextSearch )
private
FTextPositions : array of integer;
FPositionCursor : Integer; // Holds the index in current array
protected
procedure DoFind;override;
public
constructor Create;override;
property AvailableNext : Boolean;
property GlobalPosition : Integer;
end;

TReplace = class( TFind )
end;

Something like this... comments?

TIA,

Andrew


Back to top
Marc Rohloff
Guest





PostPosted: Thu Dec 04, 2003 1:42 pm    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote



Andrea Raimondi wrote on Thu, 4 Dec 2003 10:35:11 +0100 ...
<3fceff7d (AT) newsgroups (DOT) borland.com>

Hi Andrew,

Quote:
I'm doing another OS program <g>.
Ah, another OPF?


I think you might be better off using interfaces.

You will land up with:
TTextSearch = class
TTextReplace = class(TTextSearch)

TFind = class(TTextSearch).
Now where do you derive TReplace from? TFind or TTextReplace.

Using interfaces would allow you to do both, assuming you can manage the
object reference issues.

DO you really need to use base classes? Unless you are going to have
more than a couple of 'finders' this may not give you much benefit.

Marc Rohloff
marc rohloff at bigfoot dot com

Back to top
Andrea Raimondi
Guest





PostPosted: Thu Dec 04, 2003 3:09 pm    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote



Marc Rohloff wrote:
Quote:
Hi Andrew,

Hi Marc,

Quote:
Ah, another OPF?

LOL!

NOPE! <g>

Quote:
I think you might be better off using interfaces.

You will land up with:
TTextSearch = class
TTextReplace = class(TTextSearch)

TFind = class(TTextSearch).
Now where do you derive TReplace from? TFind or TTextReplace.

The idea, instead, was to inherit TReplace directly from TFind, since you
need to "find" something before replacing it, right? <g> :-)

Quote:
Using interfaces would allow you to do both, assuming you can manage
the object reference issues.

I can use TInterfacedObject and live happy :-)

Quote:
DO you really need to use base classes? Unless you are going to have
more than a couple of 'finders' this may not give you much benefit.

The idea is that you'd be able to substitute basically each part of it
with your own custom part, so a base class would help a lot in
this respect.

As I said before, it's full of goodies, and one of them is that you can
derive your own classes and plug them seamlessly.

Using interfaces for novices can be quite complex and less compatible.
I was also thinking that maybe I should create my own container
classes for this project so that I mantain the highest possible
compatibility
( till at least D4 ).

Quote:
Marc Rohloff

Andrew



Back to top
Jim Cooper
Guest





PostPosted: Fri Dec 05, 2003 9:00 am    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote


Quote:
The idea is that you'd be able to substitute basically each part of it
with your own custom part, so a base class would help a lot in
this respect.

The Template Method and Strategy patterns come immediately come to mind
(especially Strategy).

Cheers,
Jim Cooper

____________________________________________

Jim Cooper [email]jcooper (AT) tabdee (DOT) ltd.uk[/email]
Tabdee Ltd http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi with your Palm
____________________________________________

Back to top
Andrea Raimondi
Guest





PostPosted: Fri Dec 05, 2003 10:31 am    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote

Jim Cooper wrote:
Quote:
The Template Method and Strategy patterns come immediately come to
mind (especially Strategy).

Some explaining code please? <g>

Quote:
Cheers,

Rgds,

Quote:
Jim Cooper

Andrew



Back to top
Ritchie
Guest





PostPosted: Sat Dec 06, 2003 2:08 am    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote

In article <3fd05e41 (AT) newsgroups (DOT) borland.com>, [email]rainaple (AT) tin (DOT) it[/email] says...
Quote:
Jim Cooper wrote:
The Template Method and Strategy patterns come immediately come to
mind (especially Strategy).

Some explaining code please?

I have something a little like this for my script editors, as the
editors are 'plug-ins' with an interface like this:

IEditorProxy = interface
['{D4DAC8FB-032A-4D97-A408-F4B3D6830069}']
function GetLines: IStringsContainer;
function GetCaretCoord: TCaretCoord;
function GetSelCoord: TCaretCoord;
function GetSelLength: Integer;
function GetSelText: String;
procedure SetCaretCoord(Value: TCaretCoord);
procedure SetSelCoord(Value: TCaretCoord);
procedure SetSelLength(Value: Integer);
procedure SetSelText(const Value: String);
function CoordToPos(Value: TCaretCoord): Integer;
function PosToCoord(Value: Integer): TCaretCoord;
property CaretCoord: TCaretCoord read GetCaretCoord write
SetCaretCoord;
property Lines: IStringsContainer read GetLines;
property SelCoord: TCaretCoord read GetSelCoord write SetSelCoord;
property SelLength: Integer read GetSelLength write SetSelLength;
property SelText: String read GetSelText write SetSelText;
end;

For the Find/Replace functionality, I have a SearchController, a la:

ISearchController = interface
['{3CC0F8C5-5425-4716-8726-771446EB23E9}']
function Execute: Boolean;
function GetOption(const AOptionName: String): String;
procedure SetOption(const AOptionName, AOption: String);
property Options[const AOption: String]: String
read GetOption write SetOption;
end;

There's a form that hosts all these bits and pieces together (script
editor is in a panel). It creates either a FindController or
ReplaceController and passes it the IEditorProxy for the script editor,
then creates the appropriate dialog (I only have Find and Replace
buttons at the moment, so I don't really need to make any sort of
"search form factory" Smile, and passes it the ISearchController.

In the Find dialog (or wherever you do the search from), you set all
your options on the SearchController (ISearchController.Options
['FindText'] := 'bla', ISearchController.Options['CaseSensitive'] :=
'true'; etc.), then go SearchController.Execute. The FindController will
hunt down a match in IEditorProxy.Lines and set the
IEditorProxy.SelCoords and .SelLength.

I inherit the ReplaceController from the FindController (you can mix and
match instead if you have a lot of different search/replace routines)
and override the .Execute so that it will first Find, then ask whether
you wish to replace the search text (ISearchController.Options
['FindText']) with the replacement text (ISearchController.Options
['ReplaceText']) with the typical Yes/No/All/None question, then (if you
said Yes/All) replaces the IEditorProxy.SelText and (if you said
Yes/No/All) loops around to do it again.

....

The "ISearchController" is your "Strategy", as you can replace it with a
different strategy (FindBiggestNumbersController,
TranslateToChineseController) whenever you need to. In practice, it's
not quite a "pure" Strategy because of the different informational needs
some of the search controllers might have.

If you do it in objects-only instead of interfaces/objects, all the
above applies; just make sure to have your base classes (e.g. a
TSearchController) filled with the appropriate methods, but as empty of
actual 'functionality' as possible, so that your strategies don't start
fighting with one another.

Quote:
Rgds,

Andrew

Hope that helps :)

-- Ritchie Annand
Senior Software Architect
http://www.malibugroup.com
http://nimble.nimblebrain.net
http://wiki.nimblebrain.net

Back to top
Jim Cooper
Guest





PostPosted: Sun Dec 07, 2003 6:56 pm    Post subject: Re: Not an OPF question <g>: Find&Replace classes for text e Reply with quote


Quote:
Some explaining code please?

These might actually be the subject of a TDM article soon, but I'll try
and put something small together for you. It's a busy time at the moment
though.

Cheers,
Jim Cooper

____________________________________________

Jim Cooper [email]jcooper (AT) tabdee (DOT) ltd.uk[/email]
Tabdee Ltd http://www.tabdee.ltd.uk

TurboSync - Connecting Delphi with your Palm
____________________________________________

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.