WriteLog('PDFLetter.CreateRechnung: Error: Person not found!');
Exit;
end;
MyAdresse := Person.Adresse;
// << here OR
MyAdresse :=
FRepository.GetAdresse(Person.Adresse.uid); // << same here
If I compile in debug mode without
code optimization it runs without any problem, but when I run it in release mode
with the code optimization switch on, I get a access violation during runtime in the last
line.
The access to the object in Person.Adresse
is the reason for the problem which I found out with logging. No matter how I try to access the
Person.Adresse object I get this error:
Exception in class $C0000005 with message 'access violation at
0x01329c4c: read of address 0x00000005'
Very weird is that I can access
the Person.Kunde object with no problem in both modes, which is very similar and all options
are identical:
The relation between Person
and Address is a 1:n bound with a TGuid field.
Adresse.uid = Person.Adresse with no action for delete and update.
The association fetch mode is set
to ?Lazy? and the cascade type is ?None?.
I use Delphi Seattle 10 with
FireDAC on MSSQL DB. This behaviour is with Aurelius 2.9 and 3.0 the same. I
just updated it.
Is this code 100% correct? Because you are setting a variable MyPerson and then trying to read a variable named Person. Just from the code you posted, the reason is just because Person variable isn't initialized.
Have you destroyed the object manager you used to retrieve the list of Person? Does GetPersonList creates and destroys the manager? If that's the case it will fail, when lazy-loading associations, the original manager needs to stay alive so it can perform the remaining fetch actions (SQL statements) to retrieve the associated data.
FCriteria := Manager.CreateCriteria<TPerson>.Where(TLinq.Eq('Kunde',Kunde.uid.ToString) AND TLinq.Eq('PersonTyp',PersonTyp) AND TLinq.Eq('Hauptkontakt',False)).OrderBy('Nachname',False).OrderBy('Vorname')
else
if HauptKontakt = 1 then
FCriteria := Manager.CreateCriteria<TPerson>.Where(TLinq.Eq('Kunde',Kunde.uid.ToString) AND TLinq.Eq('PersonTyp',PersonTyp) AND TLinq.Eq('Hauptkontakt',True)).OrderBy('Nachname',False).OrderBy('Vorname')
else
FCriteria := Manager.CreateCriteria<TPerson>.Where(TLinq.Eq('Kunde',Kunde.uid.ToString) AND TLinq.Eq('PersonTyp',PersonTyp) ).OrderBy('Nachname',False).OrderBy('Vorname');
end
else
begin
// Ohne PersonTyp
if HauptKontakt = 0 then
FCriteria := Manager.CreateCriteria<TPerson>.Where(TLinq.Eq('Kunde',Kunde.uid.ToString) AND TLinq.Eq('Hauptkontakt',False)).OrderBy('Nachname',False).OrderBy('Vorname')
else
if HauptKontakt = 1 then
FCriteria := Manager.CreateCriteria<TPerson>.Where(TLinq.Eq('Kunde',Kunde.uid.ToString) AND TLinq.Eq('Hauptkontakt',True)).OrderBy('Nachname',False).OrderBy('Vorname')
if MyPerson.Adresse.uid, maybe Adresse is coming nil?
Sorry, but all this code you are posting is trivial (from what I can see) and is tested many times by different tests we have here, even indirectly. So if it's not something very simple like MyPerson.Adresse coming nil, it must be something very specific with your code that is not visible at first sight.
In this case I'd suggest you to build a sample project that can be compiled and run on our side here, so we can properly debug and fix the problem if it's a bug, or give you some guiding if the problem is in your code.