You are not logged in.
Hello,
Was using successfully TDynArray and saving and loading the data
from a file. Since the file generated was a bit large, tried
switching to TDynarrayHashed instead..
However, keep getting an access violation at the
line:
DynArray(TypeInfo(TStudents),MyStudents).LoadFromStream(MStream_);
when trying to load data from the file into hashed array.
Any comments/hints would be much appreciated.
P.S. Am using an older version of the framework, released in Feb '17.
// simple student DB
type
TStudent = packed record
sEmail: string;
sGPA,sTotalCredits:Currency;
sStudentId: string;
sGender,sFullName: string;
end;
TStudents = array of TStudent;
Var
MyStudents: TStudents;
aStudent : TStudent;
aDynArray: TDynArrayHashed;
MStream_ : TMemoryStream;
StudentsCount: Integer;
BEGIN
MStream_ := TMemoryStream.Create;
MStream_.LoadFromFile(GG_STUD_DIR + GG_S_
+ 'Stud_Info' + GG_TXT);
aDynArray.Init(TypeInfo(TStudents),MyStudents, nil, nil, nil, @StudentsCount);
aDynArray.Capacity := 1200000; // should be enough
DynArray(TypeInfo(TStudents),MyStudents).LoadFromStream(MStream_); // access violation
MStream_.Free;
END;
Offline
Try first with a new revision of the framework, to check if there is not already a fixed issue.
Also don't use TMemoryStream + LoadFromFile, but call directly StringFromFile() function.
Offline
Change
DynArray(TypeInfo(TStudents),MyStudents).LoadFromStream(MStream_); // access violation
to
aDynArray(TypeInfo(TStudents),MyStudents).LoadFromStream(MStream_);
Offline
Hello,
Thanks a lot for both your help.
Using:
aDynArray(TypeInfo(TStudents),MyStudents).LoadFromStream(MStream_)
would not compile, perhaps the error is elsewhere..
Anyhow, got rid of the memory streams and using the following
code no longer produces an access error,
but now fails to find the given student (which should be in the file).
Still need to try this with a new framework...
Var
Raw_: RawByteString;
indx_,StudentsCount:Integer;
BEGIN
Raw_ := BinToBase64(StringFromFile(GG_STUD_DIR + GG_S_
+ 'Stud_Info' + GG_TXT));
StudentsCount := 0;
aDynArray.Init(TypeInfo(TStudents),MyStudents, nil, nil, nil, @StudentsCount);
aDynArray.Capacity := 120000;
DynArray(TypeInfo(TStudents),MyStudents).LoadFrom(Pointer(Raw_));
aStudent.sStudentId := '296380'; // student actually is in file...
indx_ := aDynArray.FindHashed(aStudent); // indx_ returns -1
END;
Offline