⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network.htm

📁 对于学习很有帮助
💻 HTM
📖 第 1 页 / 共 2 页
字号:
{
  Add child item to container denoted as current top;
  this just adds a string for purposes such as being unable
  to enumerate a container.  That is, the container's shares
  are not accessible to us.
}
procedure TfrmMain.AddShareString(TopContainerIndex: Integer;
ItemName: String);
begin

tvResources.Items.AddChild(tvResources.Items[TopContainerIndex],ItemName);
end;

{
  Add a connection to the tree view.
  Mostly used for persistent and currently connected
  resources to be displayed.
}
procedure TfrmMain.AddConnection(NetRes: TNetResource);
var
  ItemName: String;
begin
  ItemName:=Trim(String(NetRes.lpLocalName));
  if Trim(String(NetRes.lpRemoteName))<>'' then
  begin
    if ItemName<>'' then ItemName:=ItemName+'  ';
    ItemName:=ItemName+'-> '+Trim(String(NetRes.lpRemoteName));
  end;
  tvResources.Items.Add(tvResources.Selected,ItemName);
end;

{
  Expand all containers in the tree view:
}
procedure TfrmMain.mniExpandAllClick(Sender: TObject);
begin
  tvResources.FullExpand;
end;

{
  Collapse all containers in the tree view:
}
procedure TfrmMain.mniCollapseAllClick(Sender: TObject);
begin
  tvResources.FullCollapse;
end;

{
  Allow saving of tree view to a file:
}
procedure TfrmMain.mniSaveToFileClick(Sender: TObject);
begin
  if dlgSave.Execute then
    tvResources.SaveToFile(dlgSave.FileName);
end;

{
  Allow loading of tree view from a file:
}
procedure TfrmMain.mniLoadFromFileClick(Sender: TObject);
begin
  if dlgOpen.Execute then
    tvResources.LoadFromFile(dlgOpen.FileName);
end;

{
  Rebrowse:
}
procedure TfrmMain.btnOKClick(Sender: TObject);
begin
  DoEnumeration;
end;

end.
</PRE><HR>

<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<H1><A NAME="network1">Accessing Netware Usernames</A></H1>
<I><P>From: &quot;Ryan Smith&quot; &lt;corsmith@ihc.com&gt;</P>
</I><P>You can try this code. I've been using it on a Netware LAN for some time now with no problems. 
It depends on having the NWCALLS.DLL library already on the users machine; if users have a Netware connection, then they should already have that DLL.</P>
<HR><PRE>unit GetLogin;

{This unit is a wrapper for several external functions in the NWCALLS.DLL}
{Adapted by Ray Buck from code written by Gregory Trubetskoy}
{The unit contains a function that returns the Netware User ID}
{and one that returns the user's full name.}

interface
 uses
  SysUtils, Messages, Dialogs;
function GetUserLogin: string;
function GetUserFullName( SomeUser: string): string;

implementation
  type
    NWTimeStamp = record
      Year:      byte;
      Month:     byte;
      Day:       byte;
      Hour:      byte;
      Minute:    byte;
      Second:    byte;
      DayOfWeek: byte;
    end;

  {Netware API's - require NWCALLS.DLL}
  function NWGetDefaultConnectionID(var Connection: word): word;
           far; external 'NWCALLS';

  function NWGetConnectionNumber(Connection: word; var ConnectionNumber:
word): word;
           far; external 'NWCALLS';

  function NWGetConnectionInformation(Connection: word;
                                      ConnectionNumber: word;
                                      ObjectName: pchar;
                                      var ObjectType: word;
                                      var ObjectID: word;
                                      var LoginTime: NWTimeStamp):word;
           far; external 'NWCALLS';

  function NWReadPropertyValue(Connection:       word;
                               ObjectName:       pChar;
                               ObjectType:       word;
                               PropertyName:     pChar;
                               DataSetIndex:     byte;
                               DataBuffer:       pChar;
                               var More:             byte;
                               var Flags:            byte): word;
           far; external 'NWCALLS';
  { end of Netware API stuff }

function GetUserLogin: string;
var
  ConnectionID: word;
  ConnectionNumber: word;
  RC: word;
  Name: array[0..50] of Char;
  ObjectType: word;
  ObjectID: word;
  LoginTime: NWTimeStamp;
begin
  RC := NWGetDefaultConnectionID(ConnectionID);
  RC := NWGetConnectionNumber(ConnectionID, ConnectionNumber);
  RC := NWGetConnectionInformation( ConnectionID,
                                    ConnectionNumber,
                                    Name,
                                    ObjectType,
                                    ObjectID,
                                    LoginTime);

  Result := StrPas(Name);
end;

function GetUserFullName( SomeUser: string): string;
{The real user name is a 'property' called 'IDENTIFICATON'.
You have to call NWReadPropertyValue passing it (among other things) your ConnectionID, 
the name of the object (same as the login of the user who's full name you need) 
and the name property you want to retrieve, in this case 'IDENTIFICATION' 
(which translated from Novellish to English means 'Full Name').}

var
  ConnectionID: word;
  RC: word;
  Name: array[0..50] of Char;
  ObjectType: word;
  PropName: array[0..14] of Char;
  DataSetIndex: byte;
  FullName: array[0..127] of Char;
  More: byte;
  Flags: byte;
begin
  RC := NWGetDefaultConnectionID(ConnectionID);
  ObjectType := 256; {user}
  StrPCopy(PropName, 'IDENTIFICATION');
  DataSetIndex := 1;
  StrPCopy(Name, SomeUser);
  RC := NWReadPropertyValue( ConnectionID,
                               Name,
                               ObjectType,
                               PropName,
                               DataSetIndex,
                               FullName,
                               More,
                               Flags);
  if RC = 35324 then
    MessageDlg('No user ' + SomeUser + ' exists on this server!',
                mtError, [mbOK], 0);
  Result := StrPas(FullName);
end;

end.</PRE><HR>

<H1><A NAME="network2">How to Connect to a Network Drive in Delphi</A></H1>

<P>This document explains how to create a 'Network' button that brings
up a connection dialog and then sets a drive box to point to the new drive
in Delphi. The code was created in Delphi 2, but doing it in Delphi 1 should
be about the same procedure.</P>

<P>Create a command button named NetBtn, and a drive combo box named DriveBox.
Then type this code in the OnClick event for the button:</P>

<HR>
<PRE>procedure TStartForm.NetBtnClick(Sender: TObject); 
var
  OldDrives: TStringList;
  i: Integer;
begin
  OldDrives := TStringList.Create;
  OldDrives.Assign(Drivebox.Items);                            // Remember old drive list
  // Show the connection dialog
  if WNetConnectionDialog(Handle, RESOURCETYPE_DISK) = NO_ERROR then begin
    DriveBox.TextCase := tcLowerCase;                          // Refresh the drive list box
    for i := 0 to DriveBox.Items.Count - 1 do begin
      if Olddrives.IndexOf(Drivebox.Items[i]) = -1 then begin  // Find new Drive letter
        DriveBox.ItemIndex := i;              // Updates the drive list box to new drive letter
        DriveBox.Drive := DriveBox.Text[1];   // Cascades the update to connected directory lists, etc
      end;
    end;
    DriveBox.SetFocus;
  end;
  OldDrives.Free;
end;</PRE>
<HR>

<P>You must also add the WinProcs and WinTypes units to the uses clause
of your unit.</P>

<P>The difficult part here is that the DriveComboBox lacks a refresh function.
By setting the TextCase property, we force an update of the box.</P>

<P ALIGN=RIGHT>Copyright &copy; 1997 by Josef Garvi
</P>
<!---------------------------------------------------------------------------------------------------------------------------------------------------->
<P><H1><A NAME="network3">accessing network drive mapping dialog<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>
<i>From: Edward McSweeney &lt;emcsweeney@mayo.edu&gt;</i><p>

Try WNetConnectionDialog. This function is already pre-wrapped in
Windows.pas and is specifically designed to do exactly what you
want it to do. <p>

<P><H1><A NAME="network4">Detect my own IP Address ?<IMG SRC="../images/new.gif" WIDTH=28 HEIGHT=11 BORDER=0 ALT=" [NEW]"></P></A></H1>
<I>From: Andreas Hoerstemeier &lt;andy@scp.de&gt;</I><P>

<PRE>&gt; How can I detect my own IP address in delphi 1?</PRE>

<HR><PRE>
function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    RemoteHost:=Winsock.GetHostByName(buf);
    if RemoteHost=NIL then
      my_ip_address:=winsock.htonl($07000001)  (* 127.0.0.1 *)
    else
      my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
  finally
    if buf&lt;&gt;NIL then  freemem(buf,bufsize);
    end;
  result:=winsock.ntohl(result);
  end;
</PRE><HR>

This give the (first) network address of the local computer, and if not
connected the 127.0.0.1 as the standard address for the local computer.<p>

You only need a winsock.dcu/winsock.pas as this one isn't included with D1;
I have one together with my tcpip component pack (where I snipped out the
above routine).

<HR SIZE="6" COLOR="LIME">
<FONT SIZE="2">
<a href="mailto:rdb@ktibv.nl">Please email me</a> and tell me if you liked this page.<BR>
<SCRIPT LANGUAGE="JavaScript">
<!--
	document.write("Last modified " + document.lastModified);
// -->
</SCRIPT><P>
<TABLE BORDER=0 ALIGN="CENTER">
<TR>
	<TD>This page has been created with </TD>
	<TD> <A HREF="http://www.dexnet.com./homesite.html"><IMG SRC="../images/hs25ani.gif" WIDTH=88 HEIGHT=31 BORDER=0 ALT="HomeSite 2.5b">
</A></TD>
</TR>
</TABLE>

</FONT>



</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -