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 

Where can I find a SIMPLE example of...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing
View previous topic :: View next topic  
Author Message
Lee Parker
Guest





PostPosted: Tue Nov 04, 2003 4:35 pm    Post subject: Where can I find a SIMPLE example of... Reply with quote




I'm doing some examples comparing linked lists and arrays...

I want to do something like:

type
TMyClass = class(TObject)
protected
fDesc :String;
fCreated :TDateTime;
published
property Description :string read fDesc write fDesc;
property Created :TDateTime read fCreated write FCreated;
end;

TMyClassList = class(TObject)
fList :Array Of TMyClass;
private
function GetIt(Index :Integer) :TMyClass;
procedure SetIt(Index :Integer; Value :TMyClass);
public
function Count :Integer;
property Item[Index :Integer] :TMyClass read GetIt write SetIt;
end;

My question is: Since this would be a poor implementation, is there a
SIMPLE example of the above and if so, where can I find it?

Thanks,
Lee
Back to top
Kurt Barthelmess
Guest





PostPosted: Tue Nov 04, 2003 7:47 pm    Post subject: Re: Where can I find a SIMPLE example of... Reply with quote



"Lee Parker" <lparker (AT) mountville (DOT) com> wrote:

Quote:
I'm doing some examples comparing linked lists and arrays...

I want to do something like:
[clip]


ok, but what does that have to do with "comparing linked lists and
arrays"?

Quote:
My question is: Since this would be a poor implementation, is there a
SIMPLE example of the above and if so, where can I find it?

I don't see anything "poor" with the implementation. I might have used
a record instead of an object for TMyClass, but there's probably a
whole bunch of other "smart" code not shown that would make that a bad
choice.

fwiw, I just looked at a unit I used to implement a "sparse" doubly
dimensioned array of items similar to those you are managing. It took
200+ lines to implement, so I'm not sure there is such a thing as a
"simple" example.

Good luck.

Kurt


Back to top
John Leavey
Guest





PostPosted: Wed Nov 05, 2003 11:55 am    Post subject: Re: Where can I find a SIMPLE example of... Reply with quote



On 4 Nov 2003 09:35:44 -0700, "Lee Parker" <lparker (AT) mountville (DOT) com> wrote:

Quote:

I'm doing some examples comparing linked lists and arrays...

I want to do something like:

type
TMyClass = class(TObject)
protected
fDesc :String;
fCreated :TDateTime;
published
property Description :string read fDesc write fDesc;
property Created :TDateTime read fCreated write FCreated;
end;

TMyClassList = class(TObject)
fList :Array Of TMyClass;
private
function GetIt(Index :Integer) :TMyClass;
procedure SetIt(Index :Integer; Value :TMyClass);
public
function Count :Integer;
property Item[Index :Integer] :TMyClass read GetIt write SetIt;
end;

My question is: Since this would be a poor implementation, is there a
SIMPLE example of the above and if so, where can I find it?

You could base your list class on TList, just wrapping the various methods to make them
type safe. TList does use an internal array to hold the data, but is more efficient in how
it resizes the array when items are added - see TList.Grow in Classes.Pas.

e.g.

TMyItemList = Class( TList )
protected
procedure Put( Index: Integer; Item: TMyItem);
function Get( Index: Integer ): TMyItem;
public
property Items[ Index: Integer ]: TMyItemread Get write Put; Default;
procedure Add( Item: TMyItem);
end;



procedure TMyItemList .Add( Item: TMyItem);
begin
inherited Add( Item );
end;

function TMyItemList .Get( Index: Integer ): TMyItem;
begin
Result := inherited Get( Index );
end;

procedure TMyItemList .Put( Index: Integer; Item: TMyItem);
begin
inherited Put( Index, Item );
end;


You could then add your own methods to clear the items in the list when it is destroyed
(if the list owns the items it contains) or to provide custom sorting.



For a utility to generate code for a more complete type safe list, look at
http://www.delphi32.com/vcl/4435/



John Leavey

Back to top
Raoul Snyman
Guest





PostPosted: Sat Nov 08, 2003 6:07 pm    Post subject: Re: Where can I find a SIMPLE example of... Reply with quote

Lee Parker wrote:

Quote:
I'm doing some examples comparing linked lists and arrays...

snip

My question is: Since this would be a poor implementation, is there a
SIMPLE example of the above and if so, where can I find it?

snip


you could also create a TStrings or TStringList object, and use it's
Objects property in conjunction with AddObject() and other functions. if
you're using classes or objects of course.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Writing 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.