I have a (probably) very simple question regarding SmallTalk that I am not able to solve for few hours.
So, I am trying to create a simple app for managing students and exams - therefore I have classes Student (attributes: name, surname) and Exam (attributes: date, student, mark). Moreover, I have 2 datasets in GUI to show students (DatasetStudents) and exams (DatasetExams).
What I'm trying to do with following method is create a new exam when there is a student selected in the dataset. Then I try to set the selected student object as a value of exam's attribute student. However, the problem occurs on the ex student: selected. line. When I try ex student: selected name. to set value to selected student's name, which is string, it works like charm.
Is there any way how to assign whole object to variable?
newExam
| selected ex |
selected := DatasetStudents selection.
selected isNil
ifTrue: [^Dialog warn: ‘Select student before adding exam!’]
ifFalse : [ nil ].
ex := Exam new.
ex student: selected.
DatasetExams list add: ex.
What I'm trying to achieve overall is to automatically show relevant exams in second dataset for a student selected in first dataset, but I'm currently stuck at assigning students to exams...
Thank you in advance!