Einzelnen Beitrag anzeigen

kompi

Registriert seit: 27. Apr 2012
Ort: Duisburg
54 Beiträge
 
Delphi 11 Alexandria
 
#1

Probleme mit Tdictionary in Packages

  Alt 3. Feb 2017, 16:58
Hallo DP'ler,

ich habe Probleme beim Aufruf von Tdictionary in Packages. Folgendes habe ich gemacht

1. Deklaration eines Typen in einer extra unit
Delphi-Quellcode:
   Tdokutype = class(Tdictionary<Integer ,Tdokurec>);
   Tdokurec = record
                                Filename : string;
                                Description : string;
                                Version : string;
                                Dokutyp : string;
                                Datum : string;
                                EngType : string;
                                Ausgeliefert : string;
                                ConNo : string;
                                ConTo : string;
                              end;
2. Definitionen von diversen Objekten in einer extra unit:

Delphi-Quellcode:
   Tbasicnode = class(TPersistent)
       published
   
        Property Dokumente : Tdokutype read fdokument write fdokument;

end;
Die Definition von Tbasicnode ist hier nur verkürzt wiedergegeben.

Diese beiden units sind in einem Package ausgelagert. Dieses Package wird statisch in das Hauptprogramm eingebunden.

Die Objekte vom Typ Tbasicnode werden im Hauptprogramm an Nodes eines Virtualstringtrees angebunden. Das funktioniert auch alles hervorragend.

Jetzt zu meinem Problem.

In einem weiteren Package, welches diesmal dynamisch eingebunden wird, greife ich folgendermaßen auf obiges Tdictionary zu.

Delphi-Quellcode:
procedure Taml.savedoctoaml(const axmlnode: IXMLNode; adatanode: Tbasicnode; apropname : string);
var
  propvalue : Tdokutype;
  key : integer;
  r : Tdokurec;
  xmlnode : Ixmlnode;
  subnode : Ixmlnode;
  subsubnode : Ixmlnode;
  subsubsubnode : Ixmlnode;
begin
  if not (getobjectprop(adatanode, apropname) is Tdokutype) then
    exit;
  try
    propvalue := getobjectprop(adatanode, apropname) as Tdokutype;
  except
    exit;
  end;
  if propvalue.Count = 0 then
    exit;
  try
    for key in propvalue.keys do
    begin
      if propvalue.TryGetValue(key,r) then
      begin
        try
          xmlnode := axmlnode.AddChild('InternalElement');
          xmlnode.Attributes['Name'] := r.Description;
          xmlnode.Attributes['ID'] := r.ConNo;
          subnode := xmlnode.addchild('Attribute');
          subnode.attributes['Name'] := 'aml-DocLang';
          subnode.Attributes['AttributeDataType'] := 'xs:string';
          subsubnode := subnode.AddChild('Value');
          subsubnode.NodeValue := 'de-DE';
          subnode := xmlnode.AddChild('ExternalInterface');
          subnode.Attributes['Name'] := 'Document';
          subnode.Attributes['RefBaseClassPath'] := 'AutomationMLBPRInterfaceClassLib/ExternalDataReference';
          subnode.Attributes['ID'] := r.ConNo;
          subsubnode := subnode.AddChild('Attribute');
          with subsubnode do begin
            Attributes['Name'] := 'MiMeType';
            Attributes['AttributeDataType'] := 'xs:string';
            subsubsubnode := addchild('Value');
            subsubsubnode.NodeValue := setmimetype(extractfileext(r.Filename));
          end;
          subsubnode := subnode.AddChild('Attribute');
          with subsubnode do begin
            Attributes['Name'] := 'refURI';
            Attributes['AttributeDataType'] := 'xs:string';
            subsubsubnode := addchild('Value');
            subsubsubnode.NodeValue := extractfilename(r.Filename);
          end;
        finally
          xmlnode := nil;
          subnode := nil;
          subsubnode := nil;
          subsubsubnode := nil;
        end;
      end;
    end;
  finally
// propvalue := nil;
  end;
end;
Das funktioniert auch alles, jedoch bekomme ich beim Beenden des Hauptprogramms (obiges Package ist bereits vorher entladen), einen Zugriffsfehler bei der Freigabe des Tdictionary Objekts. Dieser Zugriffsfehler tritt nur dann auf, wenn durch die Keys iteriert wird.

Binde ich jedoch die unit direkt in das Hauptprogramm ein, ist alles in Ordnung.

Weiss jemand von Euch einen Rat?

Gruß Kompi
Detlef Schmitz
  Mit Zitat antworten Zitat