Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a TDate element to a TList object 1

Status
Not open for further replies.

rewdee

Programmer
Aug 17, 2001
295
0
0
US
If I have created a TList object and I want to add a list of dates (similiar to using a dynamic array) do I have to create a class for the date as MyDate class and then add a MyDate object to my TList ojbect. If so, this seems like a lot of work and code to write (I'm used to VBA Collections) or is there another way of adding a TDate to a TList object that I'm not aware of?

Thanks,
Rewdee
 
Another option is to use, for example, the source of the TStringList as a basis, replacing the Strings property with Dates. Just remember to check and verify the lookup functions, sorting functions, etc.

I have created a TLongList this way, and it works very well. Only, such a class can not be published on the web, since you are reusing the Borland source code, and the class is therefore not a "new" class, but merely a "derivative".
Cheers,
Nico
 
Since TList stores pointers you can always resort to so some dirty code and get pointers to your TDate

function GetTDateTimePointer(aDate: TDateTime): Pointer;
var
xPointer: ^TDateTime;
begin
New(xPointer);
xPointer^:= aDate;
Result:= xPointer;
end;

you should always be careful with the clean up of your list:

procedure CleanUpList(MyList: TList);
var
i: integer;
xPointer: Pointer;
begin
for i := 0 to MyList.Count - 1 do
begin
xPointer := MyList.Items;
Dispose(xPointer);
end;
MyList.Clear;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top