Fórum Descobrir o IP do servidor. #367024
10/12/2008
0
Quero fazer minhas conexões com banco de dados o mais dinâmico possível.
Edno
Curtir tópico
+ 0Posts
11/12/2008
Facc
pois acabo de achar isso.
[url]http://forum.devmedia.com.br/viewtopic.php?t=86396&highlight=descobrir[/url]
não testei
Gostei + 0
11/12/2008
Edno
Gostei + 0
11/12/2008
Paullsoftware
[b:29dad1a0be]Fontes da FindComp.Pas[/b:29dad1a0be]
unit FindComp_;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Dim, Networks, StdCtrls, ComCtrls, ImgList, ShellAPI, ShlObj;
type
TForm1 = class(TForm)
Memo1: TMemo;
ClickMe: TButton;
TreeView1: TTreeView;
ImageList1: TImageList;
ListView1: TListView;
Memo2: TMemo;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Memo3: TMemo;
procedure ClickMeClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function GetShellFolder(CompName: TString): IShellFolder;
var
S: TString;
W: WideString;
P: PWideChar;
Desktop: IShellFolder;
Len, Flags: LongWord;
Machine: PItemIDList;
begin
S:=CompName;
if Pos(´\\´, S) <> 1 then S:=´\\´+S;
Len:=Length(S);
W:=S;
P:=@W[1];
SHGetDesktopFolder(Desktop);
Desktop.ParseDisplayName(0, nil, P, Len, Machine, Flags);
Desktop.BindToObject(Machine, nil, IShellFolder, Pointer(Result));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo3.Lines.Clear;
Screen.Cursor:=crHourGlass;
try
if not EnumSharedResources(Edit1.Text, Memo3.Lines)
then raise Exception.Create(´Invalid computer name´);
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TForm1.ClickMeClick(Sender: TObject);
var
N: TNetworkNeighborhood;
List: TStringList;
i, j: Integer;
ListViewItem: TListItem;
WorkgroupNode, ComputerNode: TTreeNode;
begin
Screen.Cursor:=crHourGlass;
try
// Initializing the objects and scanning a network
N:=TNetworkNeighborhood.Create;
try
// Obtaining the list of all the computers in a local area network
Memo1.Lines.Clear;
N.ListComputers(Memo1.Lines);
// Obtaining the alphbetically sorted list of all the workgroups
// and computers in a network
List:=TStringList.Create;
ListView1.Items.Clear;
try
N.ListNetwork(List);
for i:=0 to List.Count - 1 do begin
ListViewItem:=ListView1.Items.Add;
ListViewItem.Caption:=List[i];
ListViewItem.ImageIndex:=Integer(List.Objects[i]);
end;
finally
List.Free;
end;
// Obtaining the tree view of the workgroups and computers in a network
TreeView1.Items.Clear;
for i:=0 to N.Count - 1 do begin
WorkgroupNode:=TreeView1.Items.Add(nil, N[i]);
WorkgroupNode.ImageIndex:=1;
WorkgroupNode.SelectedIndex:=1;
for j:=0 to (N.Objects[i] as TStrings).Count - 1 do begin
ComputerNode:=TreeView1.Items.AddChild(WorkgroupNode, (N.Objects[i] as TStrings).Strings[j]);
ComputerNode.ImageIndex:=0;
end;
end;
// Obtaining the IP addresses of computers
GetIPAddresses(N, Memo2.Lines);
finally
N.Free;
end;
TreeView1.FullExpand;
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:=GetComputerName;
end;
end.[b:29dad1a0be]Units auxiliares[/b:29dad1a0be]
[color=blue:29dad1a0be]Unit DimConst.pas[/color:29dad1a0be]
unit DimConst; interface resourcestring SShellLinkReadError = ´Shortcut read error´; SShellLinkWriteError = ´Shortsut write error´; SShellLinkLoadError = ´Cannot load shortcut ¬s´; SShellLinkSaveError = ´Cannot save shortcut ¬s´; SShellLinkCreateError = ´Cannot initialize shortcut interface´; SDynArrayIndexError = ´Array ¬s item index is out of bounds (¬d)´; SDynArrayCountError = ´Array items count is out of bounds (¬d)´; SSharedMemoryError = ´Cannot create file mapping object´; SCannotInitTimer = ´Cannot initialize timer´; SPrinterIndexError = ´Printer index is out of bounds (¬d)´; SIndicesOutOfRange = ´Matrix item indices is out of bounds [¬d: ¬d]´; SRowIndexOutOfRange = ´Matrix row index is out of bounds (¬d)´; SColIndexOutOfRange = ´Matrix col index is out of bounds (¬d)´; SNoAdminRights = ´No admin rights to continue the program´; SFileError = ´Error ¬s file ¬s¬s´; SFileReading = ´reading´; SFileWriting = ´writing´; SFileError002 = ´ - file not found´; SFileError003 = ´ - path not found´; SFileError004 = ´ - cannot open file´; SFileError005 = ´ - access denied´; SFileError014 = ´ - no enough memory´; SFileError015 = ´ - cannot find specified drive´; SFileError017 = ´ - cannot move file to another drive´; SFileError019 = ´ - write protected media´; SFileError020 = ´ - cannot find specified device´; SFileError021 = ´ - device is not ready´; SFileError022 = ´ - device cannot recognize command´; SFileError025 = ´ - specified area not found´; SFileError026 = ´ - drive access denied´; SFileError027 = ´ - sector not found´; SFileError029 = ´ - device write error´; SFileError030 = ´ - device read error´; SFileError032 = ´ - file is used by another application´; SFileError036 = ´ - too many open files´; SFileError038 = ´ - end of file reached´; SFileError039 = ´ - disk full´; SFileError050 = ´ - network request not supported´; SFileError051 = ´ - remote computer is inaccessible´; SFileError052 = ´ - indentical names found on network´; SFileError053 = ´ - network path not found´; SFileError054 = ´ - network busy´; SFileError055 = ´ - network resource or device is inaccessible´; SFileError057 = ´ - network card hardware error´; SFileError058 = ´ - server unable to perform operation´; SFileError059 = ´ - network error´; SFileError064 = ´ - inaccessible network name´; SFileError065 = ´ - network access denied´; SFileError066 = ´ - network resource type incorrectly specified´; SFileError067 = ´ - network name not found´; SFileError070 = ´ - network server shut down´; SFileError082 = ´ - cannot create file or folder´; SFileError112 = ´ - no enough disk free space´; SFileError123 = ´ - file name syntax error´; SFileError161 = ´ - path incorrectly specified´; SFileError183 = ´ - file already exists´; SCannotSetSize = ´Unable to change the size of a file´; SUnableToCompress = ´Cannot compress data´; SUnableToDecompress = ´Cannot decompress data´; SCannotFindNetwork = ´Cannot find network neiborhood´; implementation end.
[color=blue:29dad1a0be]Fontes da Unit NetWorks.pas[/color:29dad1a0be]
{
A Borland Delphi 5.0 runtime unit.
The Networks unit defines classes to obtain lists of workgroups and users of
those workgroups in a local area network. The unit is built with ShellAPI
procedures and works in any Win32 operating system. Some procedures of this
unit were taken from VirtualListView demo project. In addition this unit
allows to obtain IP addresses of computers in a local area network
(firewall users may see an alert message that a program is attempting to
access internet because this unit refers to DNS servers). Also this unit
allows to enumerate shared network resources of a computer in a network.
Copyright © 2001, 2002 by Dimka Maslov
E-mail: dms@nm.ru
Web-site: http://dims.nm.ru
}
unit Networks;
interface
uses Windows, ShellAPI, ShlObj, ActiveX, ComObj, Dim, Classes, SysUtils, WinSock;
type
ComputerFound = class (Exception);
ECannotFindNetwork = class (Exception);
TStringObject = class (TObject)
private
FValue: TString;
FTag: Integer;
FData: Pointer;
FRefObj: TObject;
procedure SetValue(const Value: TString);
procedure SetData(const Value: Pointer);
procedure SetRefObj(const Value: TObject);
procedure SetTag(const Value: Integer);
public
property Value: TString read FValue write SetValue;
property RefObj: TObject read FRefObj write SetRefObj;
property Tag: Integer read FTag write SetTag;
property Data: Pointer read FData write SetData;
end;
TStringObjectArray = class (TDynamicArray)
private
function GetObject(Index: Integer): TStringObject;
function GetData(Index: Integer): Pointer;
function GetRefObj(Index: Integer): TObject;
function GetTag(Index: Integer): Integer;
function GetValue(Index: Integer): TString;
procedure SetData(Index: Integer; const Value: Pointer);
procedure SetRefObj(Index: Integer; const Value: TObject);
procedure SetTag(Index: Integer; const Value: Integer);
procedure SetValue(Index: Integer; const Value: TString);
function FreeObject(Index: Integer; var Obj: TStringObject): Integer;
procedure FreeItem(Index: Integer);
procedure CreateItem(Index: Integer);
protected
procedure SetCount(const NewCount: Cardinal); override;
public
function Add: Integer; override;
procedure Insert(Index: Integer); override;
procedure Delete(Index: Integer); override;
function AddItem(const Item): Integer; override;
procedure InsertItem(Index: Integer; const Item); override;
procedure DeleteItem(Index: Integer; out Item); override;
property Value[Index: Integer]: TString read GetValue write SetValue; default;
property RefObj[Index: Integer]: TObject read GetRefObj write SetRefObj;
property Tag[Index: Integer]: Integer read GetTag write SetTag;
property Data[Index: Integer]: Pointer read GetData write SetData;
constructor Create;
destructor Destroy; override;
end;
TStringObjectList = class (TStrings)
private
FArray: TStringObjectArray;
function GetData(Index: Integer): Pointer;
function GetTag(Index: Integer): Integer;
procedure SetData(Index: Integer; const Value: Pointer);
procedure SetTag(Index: Integer; const Value: Integer);
protected
function Get(Index: Integer): string; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AObject: TObject); override;
public
property Data[Index: Integer]: Pointer read GetData write SetData;
property Tag[Index: Integer]: Integer read GetTag write SetTag;
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Exchange(Index1, Index2: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
constructor Create;
destructor Destroy; override;
end;
{TNetworkWorkgroup - the class that lists all the computers in a workgroup.
This class is a TStrings class descendant and is fully compatible with other
descendants of that class. The Objects and Workgroups properties of
TNetworkNeiborhood class contains objects of this class (see below)}
{TNetworkWorkgroup - êëàññ ñïèñêà âñåõ êîìïüþòåðîâ â ðàáî÷åé ãðóïïå. Óíàñëåäîâàí
îò TStrings è ïîëíîñòüþ ñîâìåñòèì ñî âñåìè êëàññàìè ñïèñêîâ ñòðîê.
Îáúåêòû ýòîãî êëàññà çàïèûâàþòñÿ â ñâîéñòâà Objects è Workgroups îáúåêòîâ
êëàññà TNetworkNeiborhood}
TNetworkWorkgroup = class (TStringObjectList);
{TNetworkNeiborhood - the class that lists all the workgroups in a local area network
The Strings property of this class contains names of workgroups. Each item of this
property has the corresponding (with the same index) item of the Objects property
that contains an object of the TNetworkWorkgroup, use the (Objects[i] as TStrings)
definition to obtain the users list of desired workgroup. This class contains the
array-like property ´Workgroups´ that is useful to obtain the users list of a
workgroup with known name}
TNetworkNeighborhood = class (TStringObjectList)
private
function CreatePIDL(Size: Integer): PItemIDList;
procedure DisposePIDL(ID: PItemIDList);
function NextPIDL(IDList: PItemIDList): PItemIDList;
function GetPIDLSize(IDList: PItemIDList): Integer;
function CopyPIDL(IDList: PItemIDList): PItemIDList;
procedure StripLastID(IDList: PItemIDList);
function GetPrevPIDL(PIDL: PItemIDList): PItemIDList;
class function GetDisplayName(ShellFolder: IShellFolder; PIDL: PItemIDList): TString;
function OriginFolder: IShellFolder;
function OriginFolderNT: IShellFolder;
class function EnumObjects(ShellFolder: IShellFolder): IEnumIDList;
class procedure ParseFolder(Folder: IShellFolder; Items: TStringObjectList; StorePIDLs: Boolean = False);
class procedure ParseFolderEx(Folder: IShellFolder; Items: TStrings);
function FreeRefObj(Index: Integer; var Obj: TStringObject): Integer;
function GetWorkgroup(Name: TString): TNetworkWorkgroup;
public
{ The Refresh procedure searches all accessible workgroups in a local area
network. Before calling this procedure the hourglass cursor would be switched on,
because this procedure takes a part of time depending on a network speed and the
count of workgroups and computers in a local area network. This procedure runs
in an object constructor and then should be runned to refresh lists}
procedure Refresh;
{ The Workgroups property contains lists of all computers in a network departed
by workgroups. To obtain list of computers of a workgroup by its number
(not by name) use the inherited property Objects as following:
Objects[Index] as TNetworkWorkgroup}
property Workgroup[Name: TString]: TNetworkWorkgroup read GetWorkgroup;
{ The FindComputer function searches a computer by its name and returns the
workgroup name where a computer is. This function returns an empty string
if a computer not found}
function FindComputer(Name: TString): TString;
{ The ListComputers procedure copies the list of all the computers in a network
into a TStrings object}
procedure ListComputers(Strings: TStrings);
{ The ListNetwork procedure copies the alphbetically sorted list of all the
workroups and computers in a local area network. The Objects property of the
target TStrings objects is used to distinguish a workgroup from a computer.
Workgroups have ´TObject(1)´ in the corresponding item of the Objects property,
and computers have ´nil´}
procedure ListNetwork(Strings: TStrings);
function Add(const S: string): Integer; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
constructor Create;
end;
{ The GetIPAddress function obtains the IP address of a computer or internet server.
The NetworkName parameter specifies the name of a computer or internet server.
This function returns IP addresses as a string in XXX.XXX.XXX.XXX format when
succeeded, ´Error´ when it is impossible to initialize, ´Unknown´ when
the NetworkName parameter refers to non-existent computer or to a computer
with no TCP/IP protocol installed }
function GetIPAddress(NetworkName: TString): TString;
{ The GetIPAddresses obtains the IP addresses of all accessible computers in
a local area network. The Network parameter specifies a TNetworkNeiborhood
class object (you have to create an object prior to calling this procedure).
The List parameter specifies a string list to write data. In result each line
of a list will contain the network name with IP address (in square brackets) of
a computer }
procedure GetIPAddresses(Network: TNetworkNeighborhood; List: TStrings);
{ The EnumSharedResources function enumerates shared network resources of a
computer in a local area network. The ComputerName parameter specifies the
network name of a computer. This parameter may be within or without leading
backslashes. The List parameter specifies a string list to write data.
This function returns True if the computer with specified name exists or
False otherwise.}
function EnumSharedResources(ComputerName: TString; List: TStrings): Boolean;
implementation
uses DimConst;
{ TStringObject }
procedure TStringObject.SetData(const Value: Pointer);
begin
FData := Value;
end;
procedure TStringObject.SetRefObj(const Value: TObject);
begin
FRefObj := Value;
end;
procedure TStringObject.SetTag(const Value: Integer);
begin
FTag := Value;
end;
procedure TStringObject.SetValue(const Value: TString);
begin
FValue := Value;
end;
{ TStringObjectArray }
function TStringObjectArray.Add: Integer;
begin
Result:=inherited Add;
CreateItem(Result);
end;
function TStringObjectArray.AddItem(const Item): Integer;
begin
Result:=Add;
end;
constructor TStringObjectArray.Create;
begin
inherited Create(0, SizeOf(TStringObject));
end;
procedure TStringObjectArray.CreateItem(Index: Integer);
var
P: ^TStringObject;
begin
P:=GetItemPtr(Index);
P^:=TStringObject.Create;
end;
procedure TStringObjectArray.Delete(Index: Integer);
begin
FreeItem(Index);
inherited;
end;
procedure TStringObjectArray.DeleteItem(Index: Integer; out Item);
begin
Delete(Index);
end;
destructor TStringObjectArray.Destroy;
begin
ForEach(Integer(Self), @TStringObjectArray.FreeObject);
inherited;
end;
procedure TStringObjectArray.FreeItem(Index: Integer);
var
P: ^TStringObject;
begin
P:=GetItemPtr(Index);
FreeAndNil(P^);
end;
function TStringObjectArray.FreeObject(Index: Integer;
var Obj: TStringObject): Integer;
begin
FreeAndNil(Obj);
Result:=0;
end;
function TStringObjectArray.GetData(Index: Integer): Pointer;
begin
Result:=GetObject(Index).Data;
end;
function TStringObjectArray.GetObject(Index: Integer): TStringObject;
begin
GetItem(Index, Result);
end;
function TStringObjectArray.GetRefObj(Index: Integer): TObject;
begin
Result:=GetObject(Index).RefObj;
end;
function TStringObjectArray.GetTag(Index: Integer): Integer;
begin
Result:=GetObject(Index).Tag;
end;
function TStringObjectArray.GetValue(Index: Integer): TString;
begin
Result:=GetObject(Index).Value;
end;
procedure TStringObjectArray.Insert(Index: Integer);
begin
inherited;
CreateItem(Index);
end;
procedure TStringObjectArray.InsertItem(Index: Integer; const Item);
begin
Insert(Index);
end;
procedure TStringObjectArray.SetCount(const NewCount: Cardinal);
var
i, OldCount: Integer;
begin
OldCount:=Count;
if NewCount > Count then begin
inherited SetCount(NewCount);
for i:=OldCount to NewCount - 1 do CreateItem(i);
end else if NewCount < Count then begin
for i:=NewCount to OldCount - 1 do FreeItem(i);
inherited SetCount(NewCount);
end;
end;
procedure TStringObjectArray.SetData(Index: Integer; const Value: Pointer);
begin
GetObject(Index).Data:=Value;
end;
procedure TStringObjectArray.SetRefObj(Index: Integer;
const Value: TObject);
begin
GetObject(Index).RefObj:=Value;
end;
procedure TStringObjectArray.SetTag(Index: Integer; const Value: Integer);
begin
GetObject(Index).Tag:=Value;
end;
procedure TStringObjectArray.SetValue(Index: Integer; const Value: TString);
begin
GetObject(Index).Value:=Value;
end;
{ TStringObjectList }
function TStringObjectList.Add(const S: string): Integer;
begin
Result:=FArray.Add;
FArray.Value[Result]:=S;
end;
procedure TStringObjectList.Clear;
begin
FArray.Count:=0;
end;
constructor TStringObjectList.Create;
begin
inherited Create;
FArray:=TStringObjectArray.Create;
end;
procedure TStringObjectList.Delete(Index: Integer);
begin
FArray.Delete(Index);
end;
destructor TStringObjectList.Destroy;
begin
FArray.Free;
inherited;
end;
procedure TStringObjectList.Exchange(Index1, Index2: Integer);
begin
FArray.Swap(Index1, Index2);
end;
function TStringObjectList.Get(Index: Integer): string;
begin
Result:=FArray.Value[Index];
end;
function TStringObjectList.GetCount: Integer;
begin
Result:=FArray.Count;
end;
function TStringObjectList.GetData(Index: Integer): Pointer;
begin
Result:=FArray.Data[Index];
end;
function TStringObjectList.GetObject(Index: Integer): TObject;
begin
Result:=FArray.RefObj[Index];
end;
function TStringObjectList.GetTag(Index: Integer): Integer;
begin
Result:=FArray.Tag[Index];
end;
procedure TStringObjectList.Insert(Index: Integer; const S: string);
begin
FArray.Insert(Index);
FArray.Value[Index]:=S;
end;
procedure TStringObjectList.Put(Index: Integer; const S: string);
begin
FArray.Value[Index]:=S;
end;
procedure TStringObjectList.PutObject(Index: Integer; AObject: TObject);
begin
FArray.RefObj[Index]:=AObject;
end;
procedure TStringObjectList.SetData(Index: Integer; const Value: Pointer);
begin
FArray.Data[Index]:=Value;
end;
procedure TStringObjectList.SetTag(Index: Integer; const Value: Integer);
begin
FArray.Tag[Index]:=Value;
end;
{ TNetworkNeighborhood }
function TNetworkNeighborhood.Add(const S: string): Integer;
begin
Result:=inherited Add(S);
Objects[Result]:=TNetworkWorkgroup.Create;
end;
procedure TNetworkNeighborhood.Clear;
begin
FArray.ForEach(Integer(Self), @TNetworkNeighborhood.FreeRefObj);
inherited;
end;
function TNetworkNeighborhood.CopyPIDL(IDList: PItemIDList): PItemIDList;
var
Size: Integer;
begin
Size := GetPIDLSize(IDList);
Result := CreatePIDL(Size);
if Assigned(Result) then CopyMemory(Result, IDList, Size);
end;
constructor TNetworkNeighborhood.Create;
begin
inherited Create;
Refresh;
end;
function TNetworkNeighborhood.CreatePIDL(Size: Integer): PItemIDList;
var
Malloc: IMalloc;
HR: HResult;
begin
Result := nil;
HR := SHGetMalloc(Malloc);
if Failed(HR) then Exit;
try
Result := Malloc.Alloc(Size);
if Assigned(Result) then FillChar(Result^, Size, 0);
finally
end;
end;
procedure TNetworkNeighborhood.Delete(Index: Integer);
begin
end;
procedure TNetworkNeighborhood.DisposePIDL(ID: PItemIDList);
var
Malloc: IMalloc;
begin
if ID = nil then Exit;
OLECheck(SHGetMalloc(Malloc));
Malloc.Free(ID);
end;
class function TNetworkNeighborhood.EnumObjects(
ShellFolder: IShellFolder): IEnumIDList;
const
Flags = SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN;
begin
ShellFolder.EnumObjects(0, Flags, Result);
end;
function TNetworkNeighborhood.FindComputer(Name: TString): TString;
var
i, j: Integer;
List: TNetworkWorkgroup;
S: TString;
begin
Result:=´´;
try
for i:=0 to Count - 1 do begin
List:=Objects[i] as TNetworkWorkgroup;
for j:=0 to List.Count - 1 do begin
S:=List[j];
CleanUp(S);
if EqualText(Name, S) then begin
Result:=Strings[i];
raise ComputerFound.Create(´´);
end;
end;
end;
except
if not (ExceptObject is ComputerFound) then raise;
end;
end;
function TNetworkNeighborhood.FreeRefObj(Index: Integer;
var Obj: TStringObject): Integer;
begin
FreeAndNil(Obj.FRefObj);
Result:=0;
end;
class function TNetworkNeighborhood.GetDisplayName(ShellFolder: IShellFolder;
PIDL: PItemIDList): TString;
var
StrRet: TStrRet;
P: PChar;
begin
Result := ´´;
ShellFolder.GetDisplayNameOf(PIDL, SHGDN_NORMAL, StrRet);
case StrRet.uType of
STRRET_CSTR: SetString(Result, StrRet.cStr, lStrLen(StrRet.cStr));
STRRET_OFFSET: begin
P := @PIDL.mkid.abID[StrRet.uOffset - SizeOf(PIDL.mkid.cb)];
SetString(Result, P, PIDL.mkid.cb - StrRet.uOffset);
end;
STRRET_WSTR: Result := StrRet.pOleStr;
end;
CleanUp(Result, True);
end;
function TNetworkNeighborhood.GetPIDLSize(IDList: PItemIDList): Integer;
begin
Result := 0;
if Assigned(IDList) then begin
Result := SizeOf(IDList^.mkid.cb);
while IDList^.mkid.cb <> 0 do begin
Result := Result + IDList^.mkid.cb;
IDList := NextPIDL(IDList);
end;
end;
end;
function TNetworkNeighborhood.GetPrevPIDL(PIDL: PItemIDList): PItemIDList;
var
Temp: PItemIDList;
begin
Temp := CopyPIDL(PIDL);
if Assigned(Temp) then StripLastID(Temp);
if Temp.mkid.cb <> 0 then Result:=Temp else Result:=nil;
end;
function TNetworkNeighborhood.GetWorkgroup(Name: TString): TNetworkWorkgroup;
var
Index: Integer;
begin
Index:=IndexOf(Name);
if Index<>-1 then Result:=Objects[Index] as TNetworkWorkgroup else Result:=nil;
end;
procedure TNetworkNeighborhood.Insert(Index: Integer; const S: string);
begin
end;
procedure TNetworkNeighborhood.ListComputers(Strings: TStrings);
var
i, j: integer;
L: TNetworkWorkgroup;
S: TString;
begin
Strings.BeginUpdate;
try
Strings.Clear;
for i:=0 to Count - 1 do begin
L:=Objects[i] as TNetworkWorkgroup;
for j:=0 to L.Count - 1 do begin
S:=L[j];
CleanUp(S);
Strings.Add(S);
end;
end;
finally
Strings.EndUpdate;
end;
end;
procedure TNetworkNeighborhood.ListNetwork(Strings: TStrings);
var
List: TStringList;
i: Integer;
begin
List:=TStringList.Create;
try
List.AddStrings(Self);
for i:=0 to List.Count - 1 do List.Objects[i]:=TObject(1);
for i:=0 to Count - 1 do begin
List.AddStrings(Objects[i] as TStrings);
end;
for i:=Count to List.Count - 1 do List.Objects[i]:=nil;
List.Sort;
Strings.Assign(List);
finally
List.Free;
end;
end;
function TNetworkNeighborhood.NextPIDL(IDList: PItemIDList): PItemIDList;
begin
Result := IDList;
Inc(PChar(Result), IDList^.mkid.cb);
end;
function TNetworkNeighborhood.OriginFolder: IShellFolder;
var
Desktop: IShellFolder;
S: TString;
P: PWideChar;
Len, Flags: LongWord;
Machine, Workgroup, Network: PItemIDList;
begin
S:=´\\´+GetComputerName;
Len:=Length(S);
P:=StringToOleStr(S);
Flags:=0;
SHGetDesktopFolder(Desktop);
Desktop.ParseDisplayName(0, nil, P, Len, Machine, Flags);
Workgroup:=GetPrevPIDL(Machine);
try
Network:=GetPrevPIDL(Workgroup);
try
Desktop.BindToObject(Network, nil, IShellFolder, Pointer(Result));
finally
DisposePIDL(Network);
end;
finally
DisposePIDL(Workgroup);
end;
end;
function TNetworkNeighborhood.OriginFolderNT: IShellFolder;
var
Desktop: IShellFolder;
S: TString; W: WideString; P: PWideChar;
Len, Flags: LongWord;
Machine, Workgroup, Network: PItemIDList;
NetShell: IShellFolder;
Enum: IEnumIDList;
ID: PItemIDList;
begin
S:=´\\´+GetComputerName;
Len:=Length(S);
W:=S; P:=PWideChar(W);
SHGetDesktopFolder(Desktop);
Desktop.ParseDisplayName(0, nil, P, Len, Machine, Flags);
Workgroup:=GetPrevPIDL(Machine);
Network:=GetPrevPIDL(Workgroup);
Desktop.BindToObject(Network, nil, IShellFolder, NetShell);
Enum:=EnumObjects(NetShell);
Enum.Next(1, ID, Flags);
NetShell.BindToObject(ID, nil, IShellFolder, Pointer(Result));
DisposePIDL(Network);
DisposePIDL(Workgroup);
end;
class procedure TNetworkNeighborhood.ParseFolder(Folder: IShellFolder;
Items: TStringObjectList; StorePIDLs: Boolean);
var
ID: PItemiDList;
EnumList: IEnumIDList;
NumIDs: LongWord;
S: TString;
Index: Integer;
begin
Items.BeginUpdate;
try
Items.Clear;
EnumList:=EnumObjects(Folder);
if Assigned(EnumList) then while EnumList.Next(1, ID, NumIDs) = S_OK do begin
S:=GetDisplayName(Folder, ID);
Index:=Items.Add(S);
if StorePIDLs then Items.Data[Index]:=ID;
end;
finally
Items.EndUpdate;
end;
end;
class procedure TNetworkNeighborhood.ParseFolderEx(Folder: IShellFolder;
Items: TStrings);
var
ID: PItemiDList;
EnumList: IEnumIDList;
NumIDs: LongWord;
S: TString;
begin
Items.BeginUpdate;
try
Items.Clear;
EnumList:=EnumObjects(Folder);
if Assigned(EnumList) then while EnumList.Next(1, ID, NumIDs) = S_OK do begin
S:=GetDisplayName(Folder, ID);
Items.Add(S);
end;
finally
Items.EndUpdate;
end;
end;
procedure TNetworkNeighborhood.Refresh;
var
Network: IShellFolder;
Workgroup: IShellFolder;
i: Integer;
begin
try
if WinNT and (not Win2K) then Network:=OriginFolderNT else
Network:=OriginFolder;
ParseFolder(Network, Self, True);
for i:=0 to Count - 1 do begin
Network.BindToObject(PItemIDList(Data[i]), nil, IShellFolder, Workgroup);
ParseFolder(Workgroup, Objects[i] as TStringObjectList, False);
Workgroup:=nil;
end;
except
raise ECannotFindNetwork.Create(SCannotFindNetwork);
end;
end;
procedure TNetworkNeighborhood.StripLastID(IDList: PItemIDList);
var
MarkerID: PItemIDList;
begin
MarkerID := IDList;
if Assigned(IDList) then begin
while IDList.mkid.cb <> 0 do begin
MarkerID := IDList;
IDList := NextPIDL(IDList);
end;
MarkerID.mkid.cb := 0;
end;
end;
procedure GetIPAddresses(Network: TNetworkNeighborhood; List: TStrings);
var
Error: DWORD;
HostEntry: PHostEnt;
Data: WSAData;
Address: In_Addr;
i: Integer;
TmpList: TStringList;
S: TString;
begin
{ List.BeginUpdate;
try}
List.Clear;
Error:=WSAStartup(MakeWord(1, 1), Data);
if Error = 0 then begin
TmpList:=TStringList.Create;
try
Network.ListComputers(TmpList);
for i:=0 to TmpList.Count - 1 do begin
HostEntry:=gethostbyname(PChar(TmpList[i]));
Error:=GetLastError;
if Error <> 0 then S:=´Unknown´ else begin
Address:=PInAddr(HostEntry^.h_addr_list^)^;
S:=inet_ntoa(Address);
end;
List.Add(Format(´¬s [¬s]´, [TmpList[i], S]));
end;
finally
TmpList.Free;
end;
end else begin
List.Add(´Error´);
end;
{ finally
List.EndUpdate;
end;}
end;
function GetShellFolder(ComputerName: TString): IShellFolder;
var
S: TString;
W: WideString;
P: PWideChar;
Desktop: IShellFolder;
Len, Flags: LongWord;
Machine: PItemIDList;
begin
S:=ComputerName;
if Pos(´\\´, S) <> 1 then S:=´\\´+S;
Len:=Length(S);
W:=S;
P:=@W[1];
SHGetDesktopFolder(Desktop);
Desktop.ParseDisplayName(0, nil, P, Len, Machine, Flags);
Desktop.BindToObject(Machine, nil, IShellFolder, Pointer(Result));
end;
function EnumSharedResources(ComputerName: TString; List: TStrings): Boolean;
var
ShellFolder: IShellFolder;
begin
ShellFolder:=GetShellFolder(ComputerName);
Result:=Assigned(ShellFolder);
if Result then TNetworkNeighborhood.ParseFolderEx(ShellFolder, List);
end;
function GetIPAddress(NetworkName: TString): TString;
var
Error: DWORD;
HostEntry: PHostEnt;
Data: WSAData;
Address: In_Addr;
begin
Error:=WSAStartup(MakeWord(1, 1), Data);
if Error = 0 then begin
HostEntry:=gethostbyname(PChar(NetworkName));
Error:=GetLastError();
if Error = 0 then begin
Address:=PInAddr(HostEntry^.h_addr_list^)^;
Result:=inet_ntoa(Address);
end else begin
Result:=´Unknown´;
end;
end else begin
Result:=´Error´;
end;
WSACleanup();
end;
end.[color=blue:29dad1a0be]Unit Dim.pas[/color:29dad1a0be][code:1:29dad1a0be]{*********************************************************}
{* Turbo Pascal 5.0 - Borland Delphi 6.0 Runtime Library *}
{* Copyright © 1992-2002 by Dimka Maslov *}
{* E-mail: dms@nm.ru *}
{* Web-site: http://dims.gpsm.ru *}
{* *}
{**** Licensed for free distribution ****}
{* *}
{* Last Update: Feb. 18, 2002 *}
{*********************************************************}
unit Dim;
interface
uses Windows, SysUtils, ActiveX, ShlObj, Classes, ShellAPI;
const
// Useful constants declaration
Nul = 0;
MaxWord = $FFFF;
MaxInteger = $7FFFFFFF;
MaxFloat = 1.7e308;
MinFloat = 5.0e-324;
MaxExtended = 1.1e4932;
MinExtended = 9.99e-4933;
HalfCycle = Pi;
FullCycle = 2*Pi;
Quadrant = Pi/2;
chNull = #0;
chBackspace = #8;
chTab = 9;
chShiftTab = 15;
chEnter = 13;
chEsc = 27;
chSpace = 32;
chComma = ´,´;
chPoint = ´.´;
chQuote = ´´´´;
chDoubleQuote = ´"´;
chColon = ´:´;
chEqual = ´=´;
chMore = ´>´;
chLess = ´<´;
chLast = 255;
chPlus = ´+´;
chMinus = ´-´;
nTrue = Integer(True);
nFalse = Integer(False);
uTrue = cardinal(True);
uFalse = cardinal(False);
lTrue = -1;
lFalse = 0;
// comparison result constants
nMore = 1;
nLess = -1;
nEqual = 0;
// virtual-key codes aliases;
VK_Enter = VK_Return;
VK_Alt = VK_Menu;
VK_PageUp = VK_Prior;
VK_PageDown = VK_Next;
VK_PrintScreen = VK_SnapShot;
VK_Ctrl = VK_Control;
achCR : array [0..1] of AnsiChar = 1310;
wCR = $0A0D;
// html colors
clAliceBlue = $FFF8F0;
clAntiqueWhite = $D7EBFA;
clAqua = $FFFF00;
clAquamarine = $D4FF7F;
clAzure = $FFFFF0;
clBeige = $DCF5F5;
clBisque = $C4E4FF;
clBlack = $000000;
clBlanchedAlmond = $CDEBFF;
clBlue = $FF0000;
clBlueViolet = $E22B8A;
clBrown = $2A2AA5;
clBurlyWood = $87B8DE;
clCadetBlue = $A09E5F;
clChartreuse = $00FF7F;
clChocolate = $1E6902;
clCoral = $507FFF;
clCornflowerBlue = $ED9564;
clCornSilk = $DCF8FF;
clCrimson = $3C14DC;
clCyan = $FFFF00;
clDarkBlue = $8B0000;
clDarkCyan = $8B8B00;
clDarkGoldenrod = $0B86B8;
clDarkGray = $A9A9A9;
clDarkGreen = $006400;
clDarkKhaki = $6BB7BD;
clDarkMagenta = $8B008B;
clDarkOliveGreen = $2F6B55;
clDarkOrange = $008CFF;
clDarkOrchid = $CC3299;
clDarkRed = $000088;
clDarkSalmon = $7A96E9;
clDarkSeaGreen = $8FBC8F;
clDarkSlateBlue = $8B3D48;
clDarkSlateGray = $4F4F2F;
clDarkTurquoise = $D1CE00;
clDarkViolet = $030094;
clDeepPink = $9314FF;
clDeepSkyBlue = $FFBF00;
clDimGray = $696969;
clDodgerBlue = $FF901E;
clFireBrick = $2222B2;
clFloralWhite = $F0FAFF;
clForestGreen = $228B22;
clFuchsia = $FF00FF;
clGhostWhite = $FFF8F8;
clGainsboro = $DCDCDC;
clGold = $00D7FF;
clGoldenrod = $20A5DA;
clGray = $808080;
clGreen = $008000;
clGreenYellow = $2FFFAD;
clHoneyDew = $F0FFF0;
clHotPink = $B469FF;
clIndianRed = $5C5CCD;
clIndigo = $82004B;
clIvory = $F0FFFF;
clKhaki = $8CE6F0;
clLavender = $FAE6E6;
clLavenderBlush = $F5F0FF;
clLawnGreen = $00FC7C;
clLemonChiffon = $CDFAFF;
clLightBlue = $E6D8AD;
clLightCoral = $8080F0;
clLightCyan = $FFFFE0;
clLightGoldenrodYellow = $D2FAFA;
clLightGreen = $90EE90;
clLightGrey = $D3D3D3;
clLightPink = $C1B6FF;
clLightSalmon = $7AA0FF;
clLightSeaGreen = $AAB220;
clLightSkyBlue = $FACE87;
clLightSlateGray = $998877;
clLightSteelBlue = $DEC4B0;
clLightYellow = $E0FFFF;
clLime = $00FF00;
clLimeGreen = $32CD32;
clLinen = $E6F0FA;
clMagenta = $FF00FF;
clMaroon = $000080;
clMediumAquamarine = $AACD66;
clMediumBlue = $CD0000;
clMediumOrchid = $D355BA;
clMediumPurple = $DB7093;
clMediumSeaGreen = $71B33C;
clMediumSlateBlue = $EE687B;
clMediumSpringGreen = $9AFA00;
clMediumTurquoise = $CCD148;
clMediumVioletRed = $851507;
clMidnightBlue = $701919;
clMintCream = $FAFFF5;
clMistyRose = $E1E4FF;
clMoccasin = $B5E4FF;
clNavajoWhite = $ADDEFF;
clNavy = $800000;
clOldLace = $E6F5FD;
clOlive = $008080;
clOliveDrab = $238E6B;
clOrange = $00A5FF;
clOrangered = $0045FF;
clOrchid = $D670DA;
clPaleGoldenrod = $AAE8EE;
clPaleGreen = $98FB98;
clPaleTurquoise = $EEEEAF;
clPaleVioletRed = $9370DB;
clPapayaWhip = $D5EFFF;
clPeachPuff = $B9DAFF;
clPeru = $3F85CD;
clPink = $CBC0FF;
clPlum = $DDA0DD;
clPowderBlue = $E6E0B0;
clPurple = $800080;
clRed = $0000FF;
clRosyBrown = $8F8FBC;
clRoyalBlue = $E16941;
clSaddleBrown = $13458B;
clSalmon = $7280FA;
clSandyBrown = $60A4F4;
clSeaGreen = $578B2E;
clSeaShell = $EEF5FF;
clSienna = $2D52A0;
clSilver = $C0C0C0;
clSkyBlue = $EBCE87;
clSlateBlue = $CD5A6A;
clSlateGray = $908070;
clSnow = $FAFAFF;
clSpringGreen = $7FFF00;
clSteelBlue = $B48246;
clTan = $8CB4D2;
clTeal = $808000;
clThistle = $D8BFD8;
clTomato = $4763FF;
clTurquoise = $D0E040;
clViolet = $EE82EE;
clWheat = $B3DEF5;
clWhite = $FFFFFF;
clWhiteSmoke = $F5F5F5;
clYellow = $00FFFF;
clYellowGreen = $32CD9A;
clDimGreen = $3C8000;
type
PString=^TString;
TString=type AnsiString;
PAnsiStr=^TAnsiStr;
TAnsiStr=array[0..259] of AnsiChar;
PWideStr=^TWideStr;
TWideStr=array[0..259] of WideChar;
PShortStr=^TShortStr;
TShortStr=type ShortString;
PSetChar=^TSetChar;
TSetChar=set of AnsiChar;
PWideInt=^TWideInt;
TWideInt=type Int64;
TColorChannel = (ccRed, ccGreen, ccBlue, ccAlpha);
TColorChannels = set of TColorChannel;
PBoolean = ^Boolean;
{ The Hole function prevents allocating some variables
inside CPU registers due an optimization }
function Hole(var A):Integer;
{ The Sync procedure prevents flickering while repainting windows.
Provided for backward compatibility.
Use TWinControl.DoubleBuffered property instead calling this procedure.
This function has no action under Windows NT }
procedure Sync;
{ The KeyPressed function returns True if specified as VKey key is being pressed or
False otherwise. Use VK_xxx constants to specify required key }
function KeyPressed(VKey: Integer): LongBool;
{ The ScanCode function returns the scan code of a pressed or released key.
lKeyData parameters must contain the LParam parameter of received WM_KEYDOWN or
WM_KEYUP messages }
function ScanCode(lKeyData: Integer): Byte;
{ The RightKey function returns TRUE if received WM_KEYDOWN or WM_KEYUP messages
caused by pressing RightShift or RightControl keys, or FALSE otherwise }
function RightKey(lKeyData: Integer): Boolean;
{ The EmulateKey procedure posts messages to a control to emulate a keystroke.
The Wnd parameter specifies the window handle to a control.
The VKey paremeter specifies a virtual key code (see VK_xxx constants)}
procedure EmulateKey(Wnd: HWND; VKey: Integer);
{ The Perspective procedure calculates 2D on-picture coordinates of a point.
3D coordinates of a point must be specified as the X, Y and Z parameters.
The HEIGHT parameter specifies the altitude of "observer".
The BASIS parameter specifies the distance between "observer" and "picture".
The result values will be placed at the YP and ZP coordinates }
procedure Perspective(const X, Y, Z, Height, Basis: Extended; var XP, YP: Extended);
{ The Interpolate function returns value of the linear function passing through the points
(X1, Y1) and (X2, Y2) at the X coordinate }
function Interpolate(const X1, Y1, X2, Y2, X: Extended): Extended;
{ The Det function returns the determinant of a matrix described as
a11 a12 a13
a21 a22 a23
a31 a32 a33 }
function Det(a11, a12, a13, a21, a22, a23, a31, a32, a33: Double): Double;
{ The SinCos procedure places values of sine and cosine functions of the THETA angle
expressed in radians at the Sin and Cos variables respectively}
procedure SinCos(Theta: Extended; var Sin, Cos: Extended);
{ The Tan function returns tangent of an angle ALPHA }
function Tan(Alpha: Extended): Extended;
{ The GetLineEqn procedure places the equation parameters (A*y+B*z+C=0) of a line
passing through the points (Y1, Z1) and (Y2, Z2) at the A, B and C variables }
procedure GetLineEqn(Y1, Z1, Y2, Z2: Extended; var A, B, C: Extended);
{ The LinesIntersection functions return TRUE if specified lines have the intersection
point and places values of that point coordinates at Y and Z variables. If specified
lines are parallel these functions return FALSE.
The first of two functions described below receives equations of two lines specified
as A1*y+B1*z+C1=0 and A2*y+B2*z+C2=0. The second function receives coordinates of
points (Y1, Z1) and (Y2, Z2) where the first line passing through and coordinates
of points (Y3, Z3) and (Y4, Z4) which belong to the second line }
function LinesIntersection(A1, B1, C1, A2, B2, C2: Extended; var Y, Z: Extended): Boolean; overload;
function LinesIntersection(Y1, Z1, Y2, Z2, Y3, Z3, Y4, Z4: Extended; var Y, Z: Extended): Boolean; overload;
{ The SegmentLength function returns the lengths of a segment passing through
the (X1, Y1) and (X2, Y2) points. The value returned by this function
calculated by the Pythagorean proposition }
function SegmentLength(const X1, Y1, X2, Y2: Extended): Extended;
{ The Rotate procedure calculates the coordinates of the point (X, Y) in
cartesian coordinate system with the origin in the (X0, Y0) point
and turned at the Alpha angle about initial coordinate system. This procedure
places calculated values at the X1 and Y1 variables}
procedure Rotate(X, Y, X0, Y0, Alpha: Extended; var X1, Y1: Extended);
{ The GetAngle function returns the clockwise angle between the up direction and
the vector sum of two vectors. The Num parameter specifies the vertical coordinate
of the end of the first vector. The Den parameter specifies the horizontal coordinate
of the end of the second vector }
function GetAngle(Num, Den: Double): Double;
{ The GetAlpha function returns the clockwise angle between two vectors in a right-hand
cartesian coordinate system. The Y axis of that coordinate system is directed to up
and the Z axis is directed to left.
Both of two vectors have the common origin in the point (Y2, Z2). The first vector
is directed to the point (Y1, Z1) and the second vector to the point (Y3, Z3) }
function GetAlpha(Y1, Z1, Y2, Z2, Y3, Z3: Double): Double;
{ The GetAlphaScr function returns the counterclockwise angle between two vectors in
a left-hand cartesian coordinate system. The X axis of yhat coodinate system is
directed to left and the Y axis is directed to bottom.
Both of two vectors have the common origin in the point (X2, Y2). The first vector
is directed to the point (X1, Y1) and the second vector to the point (X3, Y3) }
function GetAlphaScr(X1, Y1, X2, Y2, X3, Y3: Double): Double;
{ The RebuildRect procedure verifies that both of
coodinates in the TopLeft field in the Rect variable are less than
the corresponding coordinates in the BottomRight field, i.e. the
TopLeft field really signs at the Top Left point of a rectangle }
procedure RebuildRect(var Rect: TRect);
{ The MoveRect procedure adds to the fields Left and Right of the
Rect variable the value of DeltaX parameter and to the fields
Top and Bottom the value of the DeltaY }
procedure MoveRect(var Rect: TRect; DeltaX, DeltaY: Integer);
{ The CopyRect procedure assigns to the fields of the Dest variable
the values of the Source parameter }
procedure CopyRect(const Source: TRect; var Dest: TRect);
{ The DeltaRect procedure increases bounds of the Rect variable
by the value of the Delta parameter, i.e. adds the Delta
value to the Right and Bottom fields and subtracts that value
from the Left and Top fields of a rectangle }
procedure DeltaRect(var Rect: TRect; Delta: Integer);
{ The IsEmptyRect function returns TRUE if each field of the
Rect parameter has the zero value or FALSE otherwise }
function IsEmptyRect(const Rect: TRect): LongBool;
{ The RectInterscetion function calculates and returns bounds
of the rectangle that consists of the area which belongs to
both of Rect1 and Rect2 rectangles. If these rectangles have
no common area this function places zero values to each field
of its result }
function RectIntersection(const Rect1, Rect2: TRect): TRect;
{ The SamePoint function returns TRUE if the coordinates of the
Point1 parameter are both equally to the coordinates of the
Point2 parameter, or FALSE otherwise }
function SamePoint(const Point1, Point2: TPoint): LongBool;
{ The IsNullPoint function returns TRUE if both of coordinates of
the Point1 have the zero value, or FALSE otherwise }
function IsNullPoint(const Point: TPoint): LongBool;
{ The ComparePointX function compares the coordinates of two
points described in the Point1 and Point2 parameters. The
X coordinates of those points have the advantage during the
comparison.
The function returns:
the nLess constant value in the following cases:
1: Point1.X < Point2.X
2: (Point1.X = Point2.X) and (Point1.Y < Point2.Y);
the nMore constant value in the subsequent cases:
1: Point1.X > Point2.X
2: (Point1.X = Point2.X) and (Point2.Y > Point2.Y);
the nEqual constant value in case of each coordinate of
Point1 are equal to the corresponding cooordinates of Point2 }
function ComparePointX(const Point1, Point2: TPoint): Integer;
{ The ComparePointY function compares the coordinates of two
points described in the Point1 and Point2 parameters. The
Y coordinates of those points have the advantage during the
comparison.
The function returns:
the nLess constant value in the following cases:
1: Point1.Y < Point2.Y
2: (Point1.Y = Point2.Y) and (Point1.X < Point2.X);
the nMore constant value in the subsequent cases:
1: Point1.Y > Point2.Y
2: (Point1.Y = Point2.Y) and (Point2.X > Point2.X);
the nEqual constant value in case of each coordinate of
Point1 are equal to the corresponding cooordinates of Point2 }
function ComparePointY(const Point1, Point2: TPoint): Integer;
{ The MovePoint procedure adds the values of the DispX and DispY parameters
respectively to the X and Y fields of the Point variable }
procedure MovePoint(var Point: TPoint; DispX, DispY: Integer);
{ The CloseTo function returns TRUE if the coordinates of the Point2 differ
from the corresponding coordinates of the Point1 on no more than the Distance
parameter, or FALSE otherwise }
function CloseTo(const Point1, Point2: TPoint; Distance: Integer): LongBool;
{ The CenterPoint function returns the coordinates of the central point of a rectangle}
function CenterPoint(const Rect: TRect): TPoint;
{ The Max function has several overloaded versions. Each of these function returns
the greater value of the two parameters but receives parameters of different types}
function Max(const R1, R2: Integer): Integer; overload;
function Max(const R1, R2: Extended):Extended; overload;
{ Unlike two functions Max this overloaded version receives additional optional
parameter that specifies the function to compare coordinates of two points.
If the CompareY parameter is FALSE (default value) comparison use ComparePointX
function or ComparePointY function otherwise }
function Max(const P1, P2: TPoint; CompareY: LongBool = False): TPoint; overload;
{ The Min function has several overloaded version. Each of these function returns
the smaller value of the two parameters but receives parameters of different types}
function Min(const R1, R2: Integer): Integer; overload;
function Min(const R1, R2: Extended):Extended; overload;
{ Unlike two functions Min this overloaded version receives additional optional
parameter that specifies the function to compare coordinates of two points.
If the CompareY parameter is FALSE (default value) comparison use ComparePointX
function or ComparePointY function otherwise }
function Min(const P1, P2: TPoint; CompareY: LongBool = False): TPoint; overload;
{ The ArrangeMin procedure exchanges values of two parameters if the second parameter
is smaller than the first }
procedure ArrangeMin(var R1, R2: Integer);
{ The ArrangeMax procedure exchanges value of two parameters if the second parameter
is greater than the first}
procedure ArrangeMax(var R1, R2: Integer);
{ The Sign functions return -1 if the Value parameter is negative,
1 if the parameter is positive and 0 if the parameter is equal to zero}
function Sign(const Value: Integer): Integer; overload;
function Sign(const Value: Extended): Extended; overload;
{ The Swap procedures exchange values of two parameters specified as R1 and R2}
procedure Swap(var R1, R2: Integer); overload;
procedure Swap(var R1, R2: Extended); overload;
procedure Swap(var R1, R2: Double); overload;
procedure Swap(var R1, R2: TString); overload;
{ The Inside functions return TRUE if the Value parameter is situated
between the values of Down and Up parameters, or FALSE otherwise }
function Inside(Value, Down, Up: Integer): LongBool; overload;
function Inside(Value, Down, Up: Extended): LongBool; overload;
{ The Inside function (third version) returns TRUE if a point lies inside
a rectangle. The coordinates of a point are specified in the Point parameter
and a rectangle is defined in the Rect parameter }
function Inside(const Point: TPoint; const Rect: TRect): LongBool; overload;
{ The Center function returns the coordinate where it is needed to place the origin of a
line segment to superpose its center with the center of another line segment.
The Value parameter specifies the length of the first line segment.
The HiValue parameter specifies the finish coordinate of the second segment.
The LoValue optional parameter specifies the origin coordinate of the second segment }
function Center(Value: Integer; HiValue: Integer; LoValue: Integer = 0): Integer;
{ The IncPtr function returns the pointer that is greater than the initial pointer P
by the Delta value }
function IncPtr(P: Pointer; Delta: Integer = 1): Pointer;
{ The DecPtr function returns the pointer that is smaller than the initial pointer P
by the Delta value }
function DecPtr(P: Pointer; Delta: Integer = 1): Pointer;
{ The Join function places the LoWord value at the low-order word of a 32-bit integer
number and the HiWord value at the high-order word of that number }
function Join(const LoWord, HiWord: Word): Integer; overload;
{ The SetValue procedure places the integer Value at specified address if the P parameter
is not nil }
procedure SetValue(P: Pointer; Value: Integer);
{ The SetIntValue procedure has the same action as the previous procedure }
procedure SetIntValue(P: Pointer; Value: Integer);
{ The SetWordValue procedure places the word (16-bit) Value at specified address if
the P parameter is not nil }
procedure SetWordValue(P: Pointer; Value: Word);
{ The SetByteValue procedure places the byte (8-bit) Value at specified address if
the P parameter is not nil }
procedure SetByteValue(P: Pointer; Value: Byte);
{ The DecInt procedure decreases the N variable by the Delta parameter in case
of N is not smaller or equal to the Lowest parameter }
procedure DecInt(var N: Integer; Delta: Integer = 1; Lowest: Integer = 0);
{ The IncInt procedure increases the N variable by the Delta parameter in case
of N is not greater or equal to the Highest parameter }
procedure IncInt(var N: Integer; Delta: Integer = 1; Highest: Integer = MaxInt);
{ The RoundPrev function returns the greatest multiple of Divider that is
smaller or equal than Value }
function RoundPrev(Value, Divider: Integer): Integer;
{ The RoundNext function returns the smallest multiple of Divider that is
greater than Value }
function RoundNext(Value, Divider: Integer): Integer;
{ The BoolToSign function returns 1 if B is FALSE or -1 if B is TRUE }
function BoolToSign(B: LongBool): Integer;
{ The Among function returns TRUE if the N parameter is equal to
one of Value array elements }
function Among(N: Integer; const Values: array of Integer): LongBool;
{ The Incr function increases the N value by one and returns the value
assigned to the N variable }
function Incr(var N: Integer): Integer;
{ The Decr function decreaeses the N value by one adn returns the value
assigned to the N variable }
function Decr(var N: Integer): Integer;
{ The HiLong function returns the highest long word of the N parameter
of TWideInt (Int64) type }
function HiLong(const N: TWideInt): LongInt;
{ The LoLong function returns the lowest long word of the N parameter
of TWideInt (Int64) type }
function LoLong(const N: TWideInt): LongInt;
{ The HiWord function returns the highest word of the integer N parameter}
function HiWord(N: Integer): word;
{ The LoWord function returns the lowest word of the integer N parameter}
function LoWord(N: Integer): word;
{ The HiByte function returns the highest byte of the word N parameter}
function HiByte(W: Word): Byte;
{ The LoByte function returns the lowest byte of the word N parameter}
function LoByte(W: Word): Byte;
{ The AbsSub function return the absolute value of the difference between
values of the N1 and N2 parameters}
function AbsSub(N1, N2: Integer): Integer;
{ The Bit function returns True in case of the Value parameter bit with number defined as
Index parameter is 1, or FALSE otherwise }
function Bit(Value, Index: Integer): Boolean;
{ The SwapWords function exchanges high order word with the low order
word of a 32-bit integer value}
function SwapWords(Value: Integer): Integer;
{ The AbsInt function returns the absolute value of an integer}
function AbsInt(Value: Integer): Integer;
{ The FmtString function returns a formatted string based on a template string
specified as the Str parameter and an open array of TString specified as the
Value parameter. A template string should contain several occurences of
¬1, ¬2 etc. Each occurence of ¬n would be replaced with the corresponding item
of the Values array }
function FmtString(const Str: TString; const Values: array of TString): TString;
{ The FindChars function searches a character from the Chars set inside a Source
string. The CurrentPosition parameter specifies the originating position to search
a character and the Direction parameter specifies the search direction. If Direction
is less than zero, the function searches toward the first char, or toward the end of
a string otherwise. This function returns the index of a found character }
function FindChars(const Source: TString; const Chars: TSetChar;
CurrentPosition: Integer = 1; Direction: Integer = 1): Integer;
{ The FindLastChar function returns the position of the last occurence of a character
Ch in a string S }
function FindLastChar(const S: TString; Ch: Char = chSpace): Integer;
{ The LeftTrim function trims all characters from the first char of a string
Str until the first character that is not equal to a character Chr}
function LeftTrim(const Str: TString; const Chr: Char = chSpace): TString;
{ The RightTrim function trims all characters from the end of a string Str
until the last characted that is not equal to a character Chr}
function RightTrim(const Str: TString; const Chr: Char = chSpace): TString;
{ The LeftExpand function places Count characters Chr into the origin of
a string Str}
function LeftExpand(const Str:TString; Count: Integer;
const Chr: Char = chSpace): TString;
{ The RightExpand function places Count characters Chr into the end of
a string Str}
function RightExpand(const Str:TString; Count: Integer;
const Chr: Char = chSpace): TString;
Gostei + 0
11/12/2008
Daniel Martins
Gostei + 0
11/12/2008
Edno
vou testar e dou um resposta.
Gostei + 0
18/08/2009
Pedroso
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)