Autor Beitrag
Herbs
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:13 
Auf der Seite der Schweizer hab ich folgenden Quelltext gefunden: Dieser soll alle Computer im Netzwerk auflisten. Wenn ich diesen jetzt einbinden will, weiß ich nicht wie ich das deklarieren soll wenn zwei Prozeduren ineinander verschachtelt sind. Die habe ich mal mit (<--) markiert, und dann bin ich mir nicht sicher ob davor nicht noch ein "Tform1." kommen muss.

ausblenden Delphi-Quelltext
1:
2:
3:
type
  PNetResourceArray = ^TNetResourceArray;
  TNetResourceArray = array[0..100] of TNetResource;

ist das richtig, dass dieses direkt über die Deklaration des Formulars
geschrieben wird?


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:
function CreateNetResourceList(ResourceType: DWord;
                              NetResource: PNetResource;
                              out Entries: DWord;
                              out List: PNetResourceArray): Boolean;
//muss hier nicht noch ein “Tform1.” vor
var
  EnumHandle: THandle;
  BufSize: DWord;
  Res: DWord;
begin
  Result := False;
  List := Nil;
  Entries := 0;
  if WNetOpenEnum(RESOURCE_GLOBALNET,
                  ResourceType,
                  0,
                  NetResource,
                  EnumHandle) = NO_ERROR then begin
    try
      BufSize := $4000;  // 16 kByte
      GetMem(List, BufSize);
      try
        repeat
          Entries := DWord(-1);
          FillChar(List^, BufSize, 0);
          Res := WNetEnumResource(EnumHandle, Entries, List, BufSize);
          if Res = ERROR_MORE_DATA then
          begin
            ReAllocMem(List, BufSize);
          end;
        until Res <> ERROR_MORE_DATA;

        Result := Res = NO_ERROR;
        if not Result then
        begin
          FreeMem(List);
          List := Nil;
          Entries := 0;
        end;
      except
        FreeMem(List);
        raise;
      end;
    finally
      WNetCloseEnum(EnumHandle);
    end;
  end;
end;

procedure ScanNetworkResources(ResourceType, DisplayType: DWord; List: TStrings);                                //<--

procedure ScanLevel(NetResource: PNetResource);                                                                  //<--
var
  Entries: DWord;
  NetResourceList: PNetResourceArray;
  i: Integer;
begin
  if CreateNetResourceList(ResourceType, NetResource, Entries, NetResourceList) then try
    for i := 0 to Integer(Entries) - 1 do
    begin
      if (DisplayType = RESOURCEDISPLAYTYPE_GENERIC) or
        (NetResourceList[i].dwDisplayType = DisplayType) then begin
        List.AddObject(NetResourceList[i].lpRemoteName,
                      Pointer(NetResourceList[i].dwDisplayType));
      end;
      if (NetResourceList[i].dwUsage and RESOURCEUSAGE_CONTAINER) <> 0 then
        ScanLevel(@NetResourceList[i]);
    end;
  finally
    FreeMem(NetResourceList);
  end;
end;                                                                                                        //<--

begin
  ScanLevel(Nil);
end;                                                                                                         //<--

procedure TForm1.Button1Click(Sender: TObject); 
begin
  ScanNetworkResources(RESOURCETYPE_DISK, RESOURCEDISPLAYTYPE_SERVER, ListBox1.Items);
end;


Zuletzt bearbeitet von Herbs am Di 28.03.06 12:26, insgesamt 1-mal bearbeitet
Waldteufel
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.03.06 15:19 
Hi Herbs. :wave:

Solange du in den Funktionen nicht auf Properties oder Methoden deiner Form zugreifst, muss vor beide kein TForm1.!
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:25 
Titel: Wo dann?
Wo muss ich die denn dann deklarieren :?:
Waldteufel
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.03.06 15:27 
Einfach hinter der Zeile, in der implementation steht, und vor der, in der end. steht... ;-)
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:30 
Titel: dämmern
so langsam dämmerts bei mir... :) :o :D :lol: :wink: :idea:
Danke.
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:33 
Titel: siehe oben
und was ist mit der Schachtelung:
procedure ...;
procedure ...;
begin
...
end;
begin
...
end;
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: Mo 27.03.06 15:38 
Das innere ist einfach eine lokale Prozedure der äußeren ... Das kannst Du vorerst ignorieren; wichtig ist daran nur, dass die innere nicht außerhalb der äußeren Proc aufgerufen werden kann.

_________________
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.
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:44 
muss ich beide oben eintragen (also in meinem fall unter:privat) oder auch so verschachtelt oder nur die äußere?
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: Mo 27.03.06 15:45 
Nur die äußere, die innere ist ja, wie schon erwähnt, für die Außenwelt nicht sichtbar.

_________________
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.
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 15:53 
danke
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 27.03.06 15:54 
user profile iconWaldteufel hat folgendes geschrieben:
Hi Herbs. :wave:

Solange du in den Funktionen nicht auf Properties oder Methoden deiner Form zugreifst, muss vor beide kein TForm1.!

das ist schwachfug, man kann aus jeder beliebigen prozedur auf properties der form zugreifen, das TForm1. braucht man nur, wenn sich die Deklaration in dem Typ befinden, wenn die prozedur also eine prozedur des formulars ist, du darfst nicht vergessen, dass jedes formular eine Ableitung der Klasse TForm ist.
Waldteufel
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.03.06 17:04 
user profile iconF34r0fTh3D4rk hat folgendes geschrieben:
das ist schwachfug, man kann aus jeder beliebigen prozedur auf properties der form zugreifen

Stimmt! Aber wenn das TForm1. nicht davor steht, muss man jedes mal Form1. vor das Dingsda, auf das man zugreift, schreiben.

Allerdings tritt man so (Achtung! Dies eine persönliche Meinung!) die Objektorientierung mit Füßen... :?
Herbs Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 37

Win XP home edition
Delphi 2005 Prof
BeitragVerfasst: Mo 27.03.06 17:43 
ich werde mir mal von unserem Math/info lehrer noch ein paar infos zu diesem thema hohlen. um OOP nicht mit füßen zu treten und mit den Händen zu schütteln :nut: