суббота, 9 февраля 2013 г.

книга о turbo pascal

The destructure will clean up the memory that the list holds, when destructing the list. If we were just to dispose the ArrayList object, the underlying list would remain and hog up RAM, a so called memory leak.

The constructor is the code that should be run on creation of the ArrayList.

The object declaration looks pretty much like a record declaration, except it contains procedures and functions that belongs to the object.

The ArrayList will contain an underlying linked list. In order to refrain from restricting the list to a specific type we store pointers to memory addresses in the list. This could be pointer to integers, strings, records or other objects.

The interface declaration contains everything in the unit that should be visible to the calling program

It is important that the name of the unit is the same as the name of the file.

function ArrayList.Tail : ArrayListRef;

function ArrayList.Head : Pointer;

function ArrayList.Empty : boolean;

procedure ArrayList.Add(el : Pointer);

Dispose(list); (* Free memory *)

if list <> nil then begin

procedure DisposeAll(list : ListRef);

(* Free all elements from the linked list *)

current : Pointer; (* Some object *)

Yes! Turbo Pascal did have object orienation as of version 5.5 no later than 1989. If we're going to create a record library we should try to use the tools of abstraction available to us. By creating an ArrayList that abstracts the complexity of linked lists we could make the main program less complex. By creating a unit (pascal library) we can keep our abstraction in there, and call to it from our main program. Here's my implementation of the unit that contains the ArrayList.

ArrayList in Pascal by objects and units

The last programming task my father had in store for me was writing a record store library application in Turbo Pascal. I was 14 years old and managed to produce something that would accept new records, artists and store them in a list that could be saved to and loaded from disc. The result didn't corrupt its database much more than SourceSafe corrupts its repository. What if we would try to recreate some of that application.

Contents tagged with turbo-pascal

litemedia - Contents tagged with turbo-pascal - Tags

Комментариев нет:

Отправить комментарий