![]() |
Ungültige Zeigeroperation
Hallo zusammen,
ich bekomme eine Fehlermeldung 'Ungültige Zeigeroperation' beim Aufruf des Destructors nach dem schließen der Anwendung.
Delphi-Quellcode:
Ich vermute das ich der Create() funktion noch eigene Variablen von TCallID und TCallInstance übergeben muss aber
type
TCallID = string; TCallInstance = class(TObject) CallID: String; CallFrom: String; CallTo: String; ChannelID: String; CallStart: TDateTime; CallEnd: TDateTime; CurrentEvent: TCallEvent; private public end; TCallInstanceDictionary = class(TObjectDictionary<TCallID,TCallInstance>) end; TCallInstanceDictionary = class(TObjectDictionary<TCallID,TCallInstance>) end; Tbc_AsteriskCallDictionaryDataModule = class(TDataModule) procedure DataModuleCreate(Sender: TObject); procedure DataModuleDestroy(Sender: TObject); function AddDictValue(ACallID: String): String; private { Private-Deklarationen } fCallInstanceDictionary: TCallInstanceDictionary; public { Public-Deklarationen } end; var bc_AsteriskCallDictionaryDataModule: Tbc_AsteriskCallDictionaryDataModule; implementation procedure Tbc_AsteriskCallDictionaryDataModule.DataModuleCreate(Sender: TObject); begin inherited; fCallInstanceDictionary := TCallInstanceDictionary.Create(); end; procedure Tbc_AsteriskCallDictionaryDataModule.DataModuleDestroy(Sender: TObject); begin inherited; fCallInstanceDictionary.Clear; fCallInstanceDictionary.free; // Hier Awnedungsfehlermeldung end; ansich funktioniert das Dictionary ohne Probleme. |
AW: Ungültige Zeigeroperation
Wie ist es denn so?
Delphi-Quellcode:
procedure Tbc_AsteriskCallDictionaryDataModule.DataModuleDestroy(Sender: TObject);
begin fCallInstanceDictionary.Clear; fCallInstanceDictionary.free; inherited; end; |
AW: Ungültige Zeigeroperation
Wieso eigentlich inherited, es handelt sich ja nicht um einen Destruktor?
|
AW: Ungültige Zeigeroperation
Stimmt! Ich sah nur "Destroy".
Das wird auch komplett ignoriert vom Compiler (keine blauen Punkte). |
AW: Ungültige Zeigeroperation
Zitat:
|
AW: Ungültige Zeigeroperation
Delphi-Quellcode:
..ist das ein Copy/Paste Fehler? :gruebel:
TCallInstanceDictionary = class(TObjectDictionary<TCallID,TCallInstance>)
end; TCallInstanceDictionary = class(TObjectDictionary<TCallID,TCallInstance>) end; Ownerships: ![]() Das erkärt noch nicht den Fehler. Das müßte MemoryLeaks erzeugen. :gruebel: |
AW: Ungültige Zeigeroperation
Danke für die Antworten.
Zitat:
Zitat:
Ich bin noch einmal mit dem Debugger und F8 weiter rein.
Code:
//System.Classes
procedure TComponent.DestroyComponents; var Instance: TComponent; begin FreeAndNil(FSortedComponents); while FComponents <> nil do begin Instance := FComponents.Last; if (csFreeNotification in Instance.FComponentState) or (FComponentState * [csDesigning, csInline] = [csDesigning, csInline]) then RemoveComponent(Instance) else Remove(Instance); Instance.DisposeOf; //////// Hier wird der Fehler ausgelöst end; end; //SYSTEM.pas procedure TObject.FreeInstance; begin CleanupInstance; _FreeMem(Pointer(Self)); //////// hier wird angehalten, wenn ich die Option beim ausgelösten Fehler wähle end; |
AW: Ungültige Zeigeroperation
Hallöle...8-)
Der Fehler riecht danach, daß ein Objekt, was im Dictionary liegt, extern vom Dictionary mit Free freigeben wurde. Dann hat das Dictionary nur einen Pointer der nicht mehr existiert. Prüfe mal darauf. :wink: Zeige mal wie du die Objekte erzeugst und in das Dictionary legst. |
AW: Ungültige Zeigeroperation
Zitat:
Code:
// neuen Anruf mit CallID anlegen
bc_AsteriskCallDictionaryDataModule.AddDictValue(GetCurrentCallID(StrBuffer));
Code:
Wenn ich Werte innerhalb der CallInstance bearbeiten möchte ruf ich die trygetvalue von Dictionary auf
procedure Tbc_AsteriskCallDictionaryDataModule.AddDictValue(ACallID: String);
var lCallInstance: TCallInstance; begin if not fCallInstanceDictionary.TryGetValue(ACallID, lCallInstance) then begin lCallInstance := TCallInstance.Create; lCallInstance.CallID := ACallID; fCallInstanceDictionary.Add(ACallID, lCallInstance); end end; Bspw.:
Code:
function Tbc_AsteriskCallDictionaryDataModule.GetChannelID(ACallID: String): String;
var lCallInstance: TCallInstance; begin if (fCallInstanceDictionary.TryGetValue(ACallID, lCallInstance)) then result := lCallInstance.ChannelID; end; procedure Tbc_AsteriskCallDictionaryDataModule.SetCallEnd(ACallID: String; AToday: TDateTime); var lCallInstance: TCallInstance; begin if(fCallInstanceDictionary.TryGetValue(ACallID, lCallInstance)) then begin lCallInstance.CallEnd := AToday; end; end; |
AW: Ungültige Zeigeroperation
Moin...8-)
Sieht unspektulär aus...:gruebel: Kein Free für eine TCallInstance? Versuche mal das:
Delphi-Quellcode:
procedure Tbc_AsteriskCallDictionaryDataModule.DataModuleCreate(Sender: TObject);
begin inherited; fCallInstanceDictionary := TCallInstanceDictionary.Create([doOwnsValues]); // die Values werden von der Liste freigeben end; procedure Tbc_AsteriskCallDictionaryDataModule.DataModuleDestroy(Sender: TObject); begin inherited; // fCallInstanceDictionary.Clear; // vor dem Free brauchst du das nicht fCallInstanceDictionary.Free; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:34 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz