Autor Beitrag
Tabakbrummel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Mi 07.04.10 21:35 
Hallo

www.delphi-library.d...anzeigen_2420,0.html
Den Quelltext aus den Forum habe ich in meine Form eingebaut. Dabei habe ich zwei Speicherlecks gefunden. Wie kann ich die Speicherlecks abdichten?
Hier ist dann mal mein Quelltext.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ImgList;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    ImageList1: TImageList;
    procedure FormCreate(Sender: TObject);
    procedure FindFilesTree (aTree: tTreeView; aPath: String; aNode: tTreeNode; aWithFiles: Boolean);
  private

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

type
  pNodeInfo = ^tNodeInfo;
  tNodeInfo = record
      Path: Boolean;
      Name: String;
    end;


procedure TForm1.FindFilesTree(aTree: tTreeView; aPath: String;
  aNode: tTreeNode; aWithFiles: Boolean);
var
  SearchRec: tSearchRec;
  Info: pNodeInfo;
  NodeTmp: tTreeNode;
Begin
  aTree.Items.BeginUpdate;

  If FindFirst (aPath + '*.*', faDirectory, SearchRec) = 0 Then
    Begin
      Repeat
        // Wenn es sich um ein Verzeichnis handelt
        If (SearchRec.Attr and faDirectory = faDirectory)
          and (SearchRec.Name[1] <> '.')
        Then
          Begin
            If (SearchRec.Attr and faDirectory > 0then
              Begin
                New (Info);
                Info^.Path := True;
                Info^.Name := aPath + SearchRec.Name;

                // zum aktuellen Eintrag hinzufügen
                aNode := aTree.Items.AddChildObject (aNode, SearchRec.Name, Info);
              End;

            // Eintrag merken
            NodeTmp := aNode.Parent;
            // auf Untereinträge prüfen
            FindFilesTree (aTree, aPath + SearchRec.Name, aNode, aWithFiles);
            // Eintrag wiederholen
            aNode := NodeTmp;
          End
        Else
          // Eintrag ist eine Datei
          If aWithFiles
            and (SearchRec.Name <> '.'and (SearchRec.Name <> '..')
          Then
            Begin
              New (Info);
              Info^.Path := False;
              Info^.Name := aPath + SearchRec.Name;
              SearchRec.Name  := ChangeFileExt( SearchRec.Name , '');
              aTree.Items.AddChildObject (aNode, SearchRec.Name, Info);
            End;

      // solange weiter bis keine wieteren Dateien/Verzeichniss gefunden werden
      Until FindNext (SearchRec) <> 0;

      FindClose(SearchRec);
    End;

  aTree.Items.EndUpdate;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  S : String;
begin
  s := ExtractFilePath(Application.ExeName) + 'Testdaten\';
  FindFilesTree (TreeView1, s, nil, True);
end;

end.


Edit/ Hatte ein Falsche URL

Hier ist mal das Log.


Moderiert von user profile iconNarses: Topic aus Programmierwerkzeuge verschoben am Mi 07.04.2010 um 23:34
Moderiert von user profile iconNarses: Titel geändert, war: "FastMM4 Speicherleck"
Einloggen, um Attachments anzusehen!
_________________
MfG
Tabakbrummel
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 07.04.10 21:50 
Jedes Mal, wenn ein Knoten gelöscht wird, musst Du sicherstellen, dass auch die an den Knoten angehängten Informationen freigegeben werden. Dazu dürfte es im TreeView ein entsprechendes Ereeignis geben, was beim Freigeben des Knoten aufgerufen wird.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Tabakbrummel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Do 08.04.10 00:14 
Hallo

Ich habe es so Gelöst.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
...
 Until FindNext (SearchRec) <> 0;
   FindClose(SearchRec);
 End;
  Dispose(Info);
  aTree.Items.EndUpdate;
end;

_________________
MfG
Tabakbrummel
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 08.04.10 00:20 
Ich sage voraus: Das Teil wird Dir in dieser Form noch um die Ohren fliegen. Read Access on unallocated Memory --> GANZ BÖSE!

Du darfst die Info-Pointer erst freigeben, wenn Du auch den Item freigibst; also es keine Referenzen mehr auf den Pointer gibt.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
martin300
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Do 08.04.10 10:08 
Persönlich finde ich die Fehlermeldungen von Eurekalog besser. Nachteil bei der Testversion ist, daß beim Startbildschirm jedes mal bestätigt werden muss und Projekte haben eine Gültigkeit von 30 Tagen. Die kann aber durch neues Kompilieren wieder verlängert werden. Alternativ lässt es sich auch komplett deaktivieren.
Tabakbrummel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Do 22.04.10 10:15 
Hallo

Ist es jetzt so richtig.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.FormDestroy(Sender: TObject);
var
  Info: pNodeInfo;
  i : Integer;
begin
  for i := 0 to TreeView1.Items.Count -1 do
    begin
      if assigned(TreeView1.Items.Item[i]) then
      begin
        Info:=TreeView1.Items.Item[i].Data;
        dispose(Info);
      end;
    end;
  TreeView1.Items.Clear;
end;

_________________
MfG
Tabakbrummel
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 22.04.10 11:11 
Sollte soweit passen, auch wenn es noch nicht ganz ideal ist.

Zur Not einfach mal kurz FastMM4 fragen, der sagt Dir das ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Tabakbrummel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124

win 7
Turbo Delphi, VS 20010 Express
BeitragVerfasst: Do 22.04.10 15:00 
Hallo

Das FastMM4 sagt garnichts mehr.
Und vielen dank für die Antworten:

_________________
MfG
Tabakbrummel