Robert Meek wrote:
> I've been trying to write a simple code editor that allows for
> multiple files to be opened at the same time, and using only one TMemo or
> TRichedit to do so.

Go write a program using Notepad or Wordpad, and then reconsider whether 
a TMemo or a TRichEdit is really an appropriate environment for editing 
code.

> My intention was to create an object like so:
> 
> type
> TMainObject  =  Class(TObject)
>     FName : String;
>     FFileName : String;
>     FLines : TStrings;
>     FEnc : Boolean; // for Encryption
>     FROnly : Boolean; // for ReadOnly
>     FTag : Integer; // ?
> End;  
>       As well as some simple local to the unit variables:

Make them fields of the form class that managers the files.

> Var
>     MyObj : TMainObject;
>     ObjList : TObjectList;
>     ObjCount : Integer;

TObjectList maintains its own count, you know.

> And as the editor is created or one clicked on "New", or "Open" an
> instance of MyObj would be created and added to a TObjectList so as to keep
> track of them.  At the same time a new TAB would be added to the tabcontrol
> so the user could move from tab to tab, with each move storing the current
> lines of the editor in the former tab's object and then loading the lines of
> the editor from the property of the new tab's object.

So far, so good. I did the same thing a few years ago.

> In the case of a
> "New" instance all properties would be '' or False except for the FName
> which would be "Untitled", and the FTag which would equal the index of the
> ObjectList Item it is added as, and which also would equal the tabIndex of
> the Tab it belongs to..  Another var would keep track of the count from
> outside the Object.

Under what circumstances would the count from outside the object be any 
different from the count inside the object? Why keep track of the same 
information in two places?

Making the objects keep track of their own indices may get complicated. 
When you close a file, you'll need to go back and re-index all the 
remaining files. But why bother? The lost object already has an IndexOf 
method, so you can ask it what the index of any object is. Why keep 
track of the same information in two places?

> The one rule I wanted to follow while doing this is that I use NO
> pointers whatsoever.  But I cannot seem to find the correct syntax for
> working with the object in the ObjectList I need at any particular time
> without them,

The list has an Items property. Give it the index you want, and it gives 
you back a TObject. Type-cast that to the class you want.

-- 
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to