•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 401,680 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,521 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 3356 | Replies: 6
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Rep Power: 4
Solved Threads: 0
Hi I have a delphi object to store some music information (note, start time, duratrion...) problem is I always get memory addressing error when I run the code,can someone please tell me where I'm going wrong!
I declare it in a seperate unit, with all my other declerations as follows:
type
SongClass = class
public
//Properties of SongClass
title : String; // Song title for user reference
tempo : integer; //tempo of the song
top : integer;
track : array[1..max_notes] of rNote; //musical data that is the song.
//Methods of SongClass
procedure addNote(inNote : rNote);
procedure sortSong;
constructor create;
end;
When it crashes it ends up with an acces violation.
It wont let me assign a value to any of the properties. I dont want it complicated, I know its kinda simple but it has to be!
I declare the variable just after the decleration of the class, its literally the next line of code:
var
song : songClass;
And when in the other forms I can see song as a variable with all the methods and properties I have made.
I have filled out the methods in rough but none of them do anything and it crashes before they can run anyway.
I do this to set up the object, even tho the constructor is empty:
procedure TForm1.FormCreate(Sender: TObject);
begin
song := song.create;
end;
If i put anything in the constructor, like top :=0; then it crashes there with the access violation!
Have i missed anything really simple out???
Thanks for any help anyone can give me! Its driving me mad!
JOsh :lol:
I declare it in a seperate unit, with all my other declerations as follows:
type
SongClass = class
public
//Properties of SongClass
title : String; // Song title for user reference
tempo : integer; //tempo of the song
top : integer;
track : array[1..max_notes] of rNote; //musical data that is the song.
//Methods of SongClass
procedure addNote(inNote : rNote);
procedure sortSong;
constructor create;
end;
When it crashes it ends up with an acces violation.
It wont let me assign a value to any of the properties. I dont want it complicated, I know its kinda simple but it has to be!
I declare the variable just after the decleration of the class, its literally the next line of code:
var
song : songClass;
And when in the other forms I can see song as a variable with all the methods and properties I have made.
I have filled out the methods in rough but none of them do anything and it crashes before they can run anyway.
I do this to set up the object, even tho the constructor is empty:
procedure TForm1.FormCreate(Sender: TObject);
begin
song := song.create;
end;
If i put anything in the constructor, like top :=0; then it crashes there with the access violation!
Have i missed anything really simple out???
Thanks for any help anyone can give me! Its driving me mad!
JOsh :lol:
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation:
Rep Power: 18
Solved Threads: 195
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Rep Power: 4
Solved Threads: 0
I tried that and it still wont work! thanks any way!
Ive tried compiling it in delphi 8 as in 6 it didnt give any error msg. Now it says an inherited constructor must be called. but i dont use inheritance! i would if i was doing a component but i thought this should be a stand alone class, in it own right.
Is there some default thing i can inherit from prehaps????
Ive tried compiling it in delphi 8 as in 6 it didnt give any error msg. Now it says an inherited constructor must be called. but i dont use inheritance! i would if i was doing a component but i thought this should be a stand alone class, in it own right.
Is there some default thing i can inherit from prehaps????
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,693
Reputation:
Rep Power: 18
Solved Threads: 195
what does your constructor look like?
In it you should call the superclass constructor if I'm not mistaken (been a while since I've used Delphi...).
Every class you create inherits from TObject if memory serves...
If you don't want a dynamic object, don't call create. Create creates a new object of the class on the heap.
In it you should call the superclass constructor if I'm not mistaken (been a while since I've used Delphi...).
Every class you create inherits from TObject if memory serves...
If you don't want a dynamic object, don't call create. Create creates a new object of the class on the heap.
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Rep Power: 4
Solved Threads: 0
I found out what i did wrong.
I needed to do a line
inherit Create;
and when i called the constructor it should of been
song := songClass.Create;
Hope that helps someone if they ever get stuck with this!
Thanks for you help guys!
And sorry, I did mean object, not onjects. They're something completely different....
I needed to do a line
inherit Create;
and when i called the constructor it should of been
song := songClass.Create;
Hope that helps someone if they ever get stuck with this!
Thanks for you help guys!
And sorry, I did mean object, not onjects. They're something completely different....
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
The only problem was that you used
You don't have to write the inherit create.
If you want to do some special things in constructor then you MUST write something like this
I hope that will be helpful
song := song.Create; and the right way issong := songClass.Create;You don't have to write the inherit create.
If you want to do some special things in constructor then you MUST write something like this
type
SongClass = class(TObject)
private
//Properties of SongClass
public
//Methods of SongClass
constructor Create; override;
end;
implementation
constructor SongClass.Create;
begin
inherited Create;
//any initialization or whatever you want
end;
end.I hope that will be helpful
Last edited by badMF : Aug 27th, 2007 at 6:03 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Cscgal wouldja add a Delphi forum here? (Software Developers' Lounge)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: mswinsocklib_tlb
- Next Thread: Open windows logon dialog



Linear Mode