GiovanniCiurleoKing
Programmer
Hello,
I am trying to write a class in Delphi 7. The class definition looks like this:
unit Unit6;
interface
type TModule = class
StudentName: string;
CourseName: string;
YearsInCourse: integer;
CurrentYear: integer;
CurrentModule: integer;
Code: array [1..12] of string;
Title: array [1..12] of string;
Leader: array [1..12] of string;
Credits: array [1..12] of integer;
CWWeight: array [1..12] of integer;
ExamWeight: array [1..12] of integer;
CWMark: array [1..12] of integer;
ExamMark: array [1..12] of integer;
public
// modifier methods
procedure SetStudentName(sName: string);
end;
implementation
procedure TModule.SetStudentName(sName: string);
begin
StudentName := sName;
end;
etc
The unit (Unit2) for the form that uses this class has Unit6 in the 'uses' section and declares a global instance of the TModule class called Modules.
In one of the form's event handlers, it tries to call Modules.SetStudentName(edit1.text) the program crashes saying there has been an access violation.
If I set a breakpoint in Unit2 where it calls Modules.SetStudentName and trace into it, the access violation is thrown within Unit6 - TModule.SetStudentName itself where it tries to set StudentName.
If I use the watch tool to try and view the class variable StudentName it says its an inaccesable value, which is of course the problem.
The confusing thing is, I have seen a program (which does something else) which looks identical to mine. This runs fine but mine does not.
I'm completely stumped as to the cause of the problem. I'm sure it's something really silly I've missed. If it is, please don't laugh I'm new to Delphi lol
Any advice would be appreciated.
Thanks
Giovanni Ciurleo
I am trying to write a class in Delphi 7. The class definition looks like this:
unit Unit6;
interface
type TModule = class
StudentName: string;
CourseName: string;
YearsInCourse: integer;
CurrentYear: integer;
CurrentModule: integer;
Code: array [1..12] of string;
Title: array [1..12] of string;
Leader: array [1..12] of string;
Credits: array [1..12] of integer;
CWWeight: array [1..12] of integer;
ExamWeight: array [1..12] of integer;
CWMark: array [1..12] of integer;
ExamMark: array [1..12] of integer;
public
// modifier methods
procedure SetStudentName(sName: string);
end;
implementation
procedure TModule.SetStudentName(sName: string);
begin
StudentName := sName;
end;
etc
The unit (Unit2) for the form that uses this class has Unit6 in the 'uses' section and declares a global instance of the TModule class called Modules.
In one of the form's event handlers, it tries to call Modules.SetStudentName(edit1.text) the program crashes saying there has been an access violation.
If I set a breakpoint in Unit2 where it calls Modules.SetStudentName and trace into it, the access violation is thrown within Unit6 - TModule.SetStudentName itself where it tries to set StudentName.
If I use the watch tool to try and view the class variable StudentName it says its an inaccesable value, which is of course the problem.
The confusing thing is, I have seen a program (which does something else) which looks identical to mine. This runs fine but mine does not.
I'm completely stumped as to the cause of the problem. I'm sure it's something really silly I've missed. If it is, please don't laugh I'm new to Delphi lol
Any advice would be appreciated.
Thanks
Giovanni Ciurleo