access violation when Item (the Type of the Item has TPropertyChangedBase as base class) is removed from TObservableCollection that is a ItemSoure for TlistView

Issue #49 new
Former user created an issue

Hi. I Try to remove a Item from a TObservableCollection that is a ItemSoure for TlistView.

it works when the Type of the Item has not TPropertyChangedBase as base Class

the Class of the Item:

  TViewPatient = class(TPropertyChangedBase)
  private
    FPatientName: string;
    FDateOfBirth: string;
    FPatientID: string;
    FCreated: string;
    FSaved: string;
    FUID: string;
    FDateOfBirthAsHex: string;
    FCreatedAsHex: string;
    FSavedAsHex: string;
    procedure SetPatientName(const APatientName: string);
    procedure SetDateOfBirth(const ADateOfBirth: string);
    procedure SetPatientID(const APatientID: string);
    procedure SetCreated(const ACreated: string);
    procedure SetSaved(const ASaved: string);
   public
    property PatientName: string read FPatientName write SetPatientName;
    property DateOfBirth: string read FDateOfBirth write SetDateOfBirth;
    property PatientID: string read FPatientID write SetPatientID;
    property Created: string read FCreated write SetCreated;
    property Saved: string read FSaved write SetSaved;
    property UID: string read FUID write FUID;
    property DateOfBirthAsHex: string read FDateOfBirthAsHex write FDateOfBirthAsHex;
    property CreatedAsHex: string read FCreatedAsHex write FCreatedAsHex;
    property SavedAsHex: string read FSavedAsHex write FSavedAsHex;
    procedure Assign(const AViewPatient: TViewPatient);
  end;

procedure TViewPatient.SetPatientName(const APatientName: string);
begin
  FPatientName := APatientName;
  NotifyOfPropertyChange('PatientName');
end;
procedure TViewPatient.SetDateOfBirth(const ADateOfBirth: string);
begin
  FDateOfBirth := ADateOfBirth;
  NotifyOfPropertyChange('DateOfBirth');
end;
procedure TViewPatient.SetPatientID(const APatientID: string);
begin
  FPatientID := APatientID;
  NotifyOfPropertyChange('PatientID');
end;
procedure TViewPatient.SetCreated(const ACreated: string);
begin
  FCreated := ACreated;
  NotifyOfPropertyChange('Created');
end;

procedure TViewPatient.SetSaved(const ASaved: string);
begin
  FSaved := ASaved;
  NotifyOfPropertyChange('Saved');
end;

procedure TViewPatient.Assign(const AViewPatient: TViewPatient);
begin
  PatientName := AViewPatient.PatientName;
  DateOfBirth := AViewPatient.DateOfBirth;
  PatientID := AViewPatient.PatientID;
  Created := AViewPatient.Created;
  Saved := AViewPatient.Saved;
  UID := AViewPatient.UID;
  DateOfBirthAsHex := AViewPatient.DateOfBirthAsHex;
  CreatedAsHex := AViewPatient.CreatedAsHex;
  SavedAsHex := AViewPatient.SavedAsHex;
end;

the Collcetion in the ViewModel

property Patients: TObservableCollection<TViewPatient> read FPatients;

The Binding in the View

PatientListView.View.ItemTemplate := DataTemplate(['PatientName','DateOfBirth','PatientID','Created', 'Saved']);
PatientListView.View.ItemsSource := FViewModel.Patients as IObjectList;

when i call

FPatients.Delete(FSelectedPatientIndex);

or

FPatients.Clear;

in the ViewModel i get a access violation. When TViewPatient has not TPropertyChangedBase as base class I get no access violation, but then i have always to remove and add objects to the collection to notify the ListView. I get also a access violation when i try to close the Software.

Comments (0)

  1. Log in to comment