Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-03

'record' / 'array' variable types

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

kractor

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;

not sure what to do now, to get that "array" structure working for the track information (the artist / album things working ok as far as i can tell so far). any suggestions or pointers to documentation would be appreciated.

Dr.Slump
to kractor
Show quoted text 27 lines
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

kractor
to Dr.Slump
Dr.Slump wrote 57 lines
>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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

i had forgot to set the size of the array, which was causing the problem ... some ppl on #fpc pointed that out to me ... :)

hehe, thanks everyone for the assistance once again