Results 1 to 4 of 4

Thread: return objectlist

  1. #1
    Senior Member EricLang's Avatar
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,206

    return objectlist

    Soms vind ik het best onhandig zonder garbage collection. Voorbeeldje:

    manier (a) het liefst zo
    Code:
    for var error: TError in MyObject.GetErrorList do log(error.message);
    manier (b) safe
    Code:
    var list: TObjectList<TError> := MyObject.GetErrorList;
    try
      for var error: TError in list do log(error.message);
    finally
      list.Free;
    end;
    Zijn er goede manieren om e.e.a op manier (a) te kunnen doen? Zonder expliciet dedicated code te hoeven gebruiken?
    Al die try finally's wordt ik weleens moe van. Liever lui...

  2. #2
    mov rax,marcov; push rax marcov's Avatar
    Join Date
    Apr 2004
    Location
    Ehv, Nl
    Posts
    9,926
    Errorlist een interface maken ?

  3. #3
    Senior Member EricLang's Avatar
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,206
    Dat kan. Maar dat is niet generiek.

  4. #4
    Waarom niet? Spring kan het in ieder geval:

    Delphi Code:
    1. TCollections.CreateObjectList<T: class>(...): IList<T>;

    http://www.devjetsoftware.com/docs/s...)(Boolean).htm
    https://stackoverflow.com/a/22680202/511529
    1+1=b

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •