Custom Word Fields
The use of Field information in Microsoft® Word allows for easier maintenance of your documents. Using fields, you can include references to document property information within your document. This avoids the need to update changing property information that is referenced within a document (title, author, etc...). Using fields with templates makes format standardization a bit more exciting. Besides the standard fields, you can also reference your custom document properties. Personally, I often reference custom document revision information.


To reference custom properties in your document you first need to set them up. In my case, I use
MAJ_REV and
MIN_REV, both of these are of type Number.

In your Word document move the cursor to the location where you would like to insert your custom property and press
CTRL+F9. This will insert a Word field denoted by brackets (note that you cannot type these in yourself, you must press
CTRL+F9 to indicate it is a field). Between the brackets type
DOCPROPERTY followed by the property name you would like to reference. While the cursor is still on the field, press
F9 to update it and there you go….
Adapter Information Round 2
In an earlier post getting local adapter information via the Internet Protocol Helper (IP Helper) was discussed. The .NET Framework version 2.0 has the System.Net.NetworkInformation namespace that provides access to this information. For this sample I used VB.NET, however I will try some 'blogged' tricks to see if I can get this working in BDS® 2006 and see how it all works out.

Imports System.Net.NetworkInformation
Imports System.Net
Public Sub RetrieveLocalAdapterInformation(ByVal text As TextBox)
Dim interfaces As NetworkInterface() 'NIC
Dim netInterface As NetworkInterface ' adapter
Dim properties As IPInterfaceProperties
Dim address As PhysicalAddress
Dim ip As IPAddress
Dim ipinfo As IPAddressInformation
text.Clear()
If NetworkInterface.GetIsNetworkAvailable Then
interfaces = NetworkInterface.GetAllNetworkInterfaces
If interfaces.GetLength(0) > 0 Then
For Each netInterface In interfaces
properties = netInterface.GetIPProperties
text.AppendText(netInterface.Name & vbCrLf)
text.AppendText("Id: " & netInterface.Id.ToString & vbCrLf)
address = netInterface.GetPhysicalAddress
text.AppendText("MAC Address: " & (Microsoft.VisualBasic.IIf(address.ToString = String.Empty, "None", address.ToString)) & vbCrLf)
For Each ipinfo In properties.UnicastAddresses
text.AppendText("IP: " & ipinfo.Address.ToString & vbCrLf)
Next
For Each ip In properties.DhcpServerAddresses
text.AppendText("DHCP Server: " & ip.ToString & vbCrLf)
Next
For Each ip In properties.DnsAddresses
text.AppendText("DNS Server: " & ip.ToString & vbCrLf)
Next
text.AppendText("Type: " & netInterface.NetworkInterfaceType.ToString & vbCrLf)
text.AppendText("Operational Status: " & netInterface.OperationalStatus.ToString & vbCrLf)
text.AppendText("Speed: " & netInterface.Speed.ToString("N") & " bytes" & vbCrLf)
' XP Only
'text.AppendText("Receive Only: " & netInterface.IsReceiveOnly.ToString & vbCrLf)
' XP Only
'text.AppendText("Support Multicast: " & netInterface.SupportsMulticast.ToString & vbCrLf)
text.AppendText("Support IPv4: " & netInterface.Supports(NetworkInterfaceComponent.IPv4).ToString & vbCrLf)
text.AppendText("Support IPv6: " & netInterface.Supports(NetworkInterfaceComponent.IPv6).ToString & vbCrLf)
text.AppendText("DnsSuffix: " & properties.DnsSuffix.ToString & vbCrLf)
text.AppendText("" & vbCrLf)
Next
End If
End If
End Sub
Local Computer Adapter Information
Most computers today have some sort of adapter for connecting to a network. It is often desirable to retrieve the local computer’s adapter information. The .NET Framework version 2.0 has the System.Net.NetworkInformation namespace to provide easy access to this and a lot of other adapter information. In the WIN32 world there is the Internet Protocol Helper (IP Helper), specifically the GetAdaptersInfo function. If you are using BDS® 2006 (or earlier versions) grab the IP Helper API from the JEDI Project (there is a lot of work in that project and we should all thank the contributors of that project).
With the IP Helper wrapper, getting the local adapter information is as easy as:
uses
IpHlpApi, IpTypes;
procedure RetrieveLocalAdapterInformation(strings: TStrings);
var
pAdapterInfo: PIP_ADAPTER_INFO;
AdapterInfo: IP_ADAPTER_INFO;
BufLen: DWORD;
Status: DWORD;
strMAC: String;
i: Integer;
begin
strings.Clear;
BufLen:= sizeof(AdapterInfo);
pAdapterInfo:= @AdapterInfo;
Status:= GetAdaptersInfo(nil, BufLen);
pAdapterInfo:= AllocMem(BufLen);
try
Status:= GetAdaptersInfo(pAdapterInfo, BufLen);
if (Status ERROR_SUCCESS) then
begin
case Status of
ERROR_NOT_SUPPORTED:
strings.Add('GetAdaptersInfo is not supported by the operating ' +
'system running on the local computer.');
ERROR_NO_DATA:
strings.Add('No network adapter on the local computer.');
else
strings.Add('GetAdaptersInfo failed with error #' + IntToStr(Status));
end;
Exit;
end;
while (pAdapterInfo nil) do
begin
strings.Add('Description: ' + pAdapterInfo^.Description);
strings.Add('Name: ' + pAdapterInfo^.AdapterName);
strMAC := '';
for I := 0 to pAdapterInfo^.AddressLength - 1 do
strMAC := strMAC + '-' + IntToHex(pAdapterInfo^.Address[I], 2);
Delete(strMAC, 1, 1);
strings.Add('MAC address: ' + strMAC);
strings.Add('IP address: ' + pAdapterInfo^.IpAddressList.IpAddress.S);
strings.Add('Gateway: ' + pAdapterInfo^.GatewayList.IpAddress.S);
strings.Add('DHCP enabled: ' + IntTOStr(pAdapterInfo^.DhcpEnabled));
strings.Add('DHCP: ' + pAdapterInfo^.DhcpServer.IpAddress.S);
strings.Add('Have WINS: ' + BoolToStr(pAdapterInfo^.HaveWins,True));
strings.Add('Primary WINS: ' + pAdapterInfo^.PrimaryWinsServer.IpAddress.S);
strings.Add('Secondary WINS: ' + pAdapterInfo^.SecondaryWinsServer.IpAddress.S);
pTempAdapterInfo := pAdapterInfo;
pAdapterInfo:= pAdapterInfo^.Next;
Dispose(pTempAdapterInfo);
end;
finally
Dispose(pAdapterInfo);
end;
end;
Note: Responding to a newsgroup posting gave me the idea of posting this blog message.