Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


An Descendant from TTreView which shows the hierarchy of LANFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Component Writing
Skill Level:
Scoring:
Last Update:
08/29/2006
Search Keys:
delphi delphi3000 article borland vcl code-snippet Lan-TTreeView,TTreeView-descendants, creating-custom-tree
Times Scored:
2
Visits:
1888
Uploader: Eugine Veselov
Company:
Reference: N/A
 
Question/Problem/Abstract:
The component shows you LAN resources which are represented
as a tree.

How to use ?
Set Component on Form and assign property Active in True
Enjoy !
Answer:



unit mmLanTreeView;

interface

uses
  Windows,Messages,SysUtils, Classes, Controls, ComCtrls;

type
  TmmLanTreeView = class(TCustomTreeView)
  private
    FActive: Boolean;
    FOnProgress: TNotifyEvent;
    FOnEndScan: TNotifyEvent;
    procedure SetActive(const Value: Boolean);
    procedure SetOnProgress(const Value: TNotifyEvent);
    procedure SetOnEndScan(const Value: TNotifyEvent);
    { Private declarations }
  protected
    procedure LoadLevel(aRoot:pointer;aRootTree:TTreeNode);
    { Protected declarations }
  public
    property Items;
    procedure RefreshTree;
    { Public declarations }
  published
   property OnProgress:TNotifyEvent read FOnProgress write SetOnProgress;
   property Active:Boolean read FActive write SetActive;
   property OnEndScan:TNotifyEvent read FOnEndScan write SetOnEndScan;

    property Align;
    property Anchors;
    property AutoExpand;
    property BevelEdges;
    property BevelInner;
    property BevelOuter;
    property BevelKind default bkNone;
    property BevelWidth;
    property BiDiMode;
    property BorderStyle;
    property BorderWidth;
    property ChangeDelay;
    property Color;
    property Ctl3D;
    property Constraints;
    property DragKind;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property HotTrack;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('mmVCL', [TmmLanTreeView]);
end;

{ TmmLanTreeView }

procedure TmmLanTreeView.LoadLevel(ARoot: Pointer; ARootTree: TTreeNode);
var
Buffer: array [1..512] of TNetResource;
hEnum,Count,BufSize:Cardinal;
s:String;
vNode:TTreeNode;
i:integer;
R:TNetResource;
vData:^TNetResource;
begin
  Count:=512;
  BufSize:=SizeOf(TNetResource)*512;
  if WNetOpenEnumA(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,aRoot,HEnum)=NO_ERROR then
   begin
    while WNetEnumResourceA(HEnum,Count,@Buffer,BufSize)=NO_ERROR do
     for i:=1 to Count do
     begin
      s:=String(Buffer[i].lpRemoteName);
      if s='' then break;
      vNode:=Items.AddChild(aRootTree,s);

      if Assigned(FOnProgress) then FOnProgress(Self);
      if not Active then Exit;

      with vNode do begin
       New(vData);
       vData^:=Buffer[i];
       Data:=vData;
       if (Buffer[i].dwUsage=RESOURCEUSAGE_CONTAINER) or (Buffer[i].dwUsage>RESOURCEUSAGE_RESERVED) then
        begin
         r:=Buffer[i];
         LoadLevel(@r,vNode);
        end;
      end;

     end;
      WNetCloseEnum(hEnum);
   end;
   //if Items.Count>15 then exit;
end;

procedure TmmLanTreeView.RefreshTree;
begin
LoadLevel(nil,nil);                            
if Assigned( FOnEndScan) then FOnEndScan(Self);
end;

procedure TmmLanTreeView.SetActive(const Value: Boolean);
begin
  FActive := Value;
  if Value then RefreshTree else
   Items.Clear;
end;

procedure TmmLanTreeView.SetOnEndScan(const Value: TNotifyEvent);
begin
  FOnEndScan := Value;
end;

procedure TmmLanTreeView.SetOnProgress(const Value: TNotifyEvent);
begin
  FOnProgress := Value;
end;

end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Enjoy?
    Maarten de Haan (Jul 3 2003 3:03PM)

Set active = True and then the computer hangs...
(Win2k SP4, D5Professional, 100 MB/s LAN connection)
Success!
M. de Haan
Respond

RE: Enjoy?
Eugine Veselov (Jul 3 2003 3:36PM)

I have not understood? good my solving or now
if you want to discuss it my
ICQ is  175071789
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Carter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)