You would need to create your data module first. You are trying to use an object that doesn't yet exist. That is why you are seeing access violation. You also don't have a value in filename. What you should be doing is something like this:
procedure loadfile; stdcall;
var
studentDataModule: TStudentModule;
fileToLoad: string;
begin
studentDataModule := TStudentModule.Create(nil);
try
// Set filename to something
fileToLoad := 'Myfile.dat';
// Load the file
StudentModule.StudentSet.LoadFromFile(fileToLoad);
// Do something else
...
finally
studentDataModule.Free;
end;
end;
I didn't use your two global variables on purpose. There is nothing to initialize these.