[fpc-pascal]'record' / 'array' variable types

Dr.Slump senbei at terra.es
Mon Mar 8 15:30:49 CET 2004


> working on some user-defined variable types for a media database project
> i'm working on (slowly, oh so slowly). i've defined types for artist and
> album and track (individual). naturally, there's going to be multiple
> tracks per album, so i'm assuming that an array would be best to store
> the track information. so far i have the following to "declare" the
> record things
> 
>     TArtist = record
>         arName: ansistring;
>         arID: longint;
>     end;
> 
>     TAlbum = record
>         alName: ansistring;
>         alID: longint;
>         alLabel: ansistring;
>         alNumTracks: longint;
>         alYear: longint;
>         alFormat: ansistring;
>     end;
> 
>     TTrack = record
>         trNum: longint;
>         trName: ansistring;
>         trID: longint;
>     end;
> 

Hi,

You can declare the traces statically on an album:
alTracks: array[1..20] of TTrack;
but this way you might get short of available tracks for certain albums and
in most cases you'll be wasting memory with unused tracks.

Another option is to dynamically allocate the tracks array:
alTracks: pTrack;
pTrack = ^TTrack;

However, I'd do it in a different way, using a TList descendant (classes
unit) to keep all the tracks known to the db. Then you set an album and
artist id on each track, the albums and artists could be a TList too.

Hope it makes sense, I haven't programmed in a long time so all this could
sound a bit old :)

Ciao, Ivan





More information about the fpc-pascal mailing list