Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Assingning pointers to records

I need to create a pointer to a self-defined record and then add the pointer to a List. When I attempt the code below it gives me a "Invalid typecast" Error. Can any one help me?

private
RecordList : TList;

...

TSongs = Record
Artist,
Albumn,
Track,
Title,
CdTitle,
TrackLength : String;
end;

TMp3 = Record
SongList : Array[0..MaxSongs - 1] of TSongs;
NoSongs : integer;
end;

var
ProgramForm : TProgramForm;
List : TMp3;

type
TPointer = ^TSongs;

...

RecordList.Add(TPointer(List.SongList[List.NoSongs]));*

*The error is on this line.


Comments

  • kurvlakurvla Member Posts: 20
    [b][red]This message was edited by kurvla at 2002-10-18 4:7:15[/red][/b][hr]
    : I need to create a pointer to a self-defined record and then add the pointer to a List. When I attempt the code below it gives me a "Invalid typecast" Error. Can any one help me?
    :
    : private
    : RecordList : TList;
    :
    : ...
    :
    : TSongs = Record
    : Artist,
    : Albumn,
    : Track,
    : Title,
    : CdTitle,
    : TrackLength : String;
    : end;
    :
    : TMp3 = Record
    : SongList : Array[0..MaxSongs - 1] of TSongs;
    : NoSongs : integer;
    : end;
    :
    : var
    : ProgramForm : TProgramForm;
    : List : TMp3;
    :
    : type
    : TPointer = ^TSongs;
    :
    : ...
    :
    : RecordList.Add(TPointer(List.SongList[List.NoSongs]));*
    :
    : *The error is on this line.
    :
    :
    : Hi,
    the problem is that you cannot cast a record to a pointer.
    Because you can pass only pointers to TList.Add(...) you can do this:

    RecordList.Add(TPointer(@List.SongList[List.NoSongs])); (@=address of)

    I just hope you don't alloc the list on the stack, if you do this won't help you (you alloc a variable on the stack implicitly if it's a lcal variable). Could you tell me anyway why you need an array of songs from which you are coping them into a list?



  • Andre YoungAndre Young USAMember Posts: 0

    ________ | http://forcoder.org | free ebooks and video tutorials about / Visual Basic .NET C JavaScript Visual Basic Go R Delphi C# Perl C++ Scratch Objective-C Swift PL/SQL Ruby PHP Assembly Python MATLAB Java Crystal Apex Lisp Dart Lua Erlang F# Kotlin Fortran SAS Julia Alice Awk Bash VBScript Rust Hack Scala Clojure Ada Prolog D ABAP Logo LabVIEW COBOL ML Scheme FoxPro Transact-SQL / __________

Sign In or Register to comment.