Reconnecting to network shares with the help of a Component
IF YOU ALLREADY KNOW THE LOCATION OF THE SHARE YOU SHOULDN’T USE THIS COMPONENT AS IN LARGE NETWORKS WILL BE SLOW. THIS IS ONLY IF YOU DON’T KNOW THE EXACT LOCATION BUT CAN LOCATE IT BY USING A MARKER SUCH AS A SPECIFIC FILE OR FOLDER. TIP: Use the BeforeConnect Event to specify whether a connection should be made.
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 |
unit Reconnect; interface uses Windows, Messages,StdCtrls, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,FileCtrl; type TSIsType=(itDir,itIniFile,itApp,itOther); TBeforeConnectEvent=procedure(Owner:TObject;AssignPath:string;var Accept:boolean) of object; TAfterConnectEvent=procedure(Owner:TObject;AssignedPath:string) of object; TOnFail=procedure(Owner:TObject;FailMessage:string) of object; TReconnect = class(TComponent) private { Private declarations } DidAssign:boolean; FItemToLookFor:String; FUserName:String; FPassword:String; FLetterToAssign:Char; FIsType:TSIsType; FOutputLabel:TLabel; FFailMessage:String; FBeforeConnect:TBeforeConnectEvent; FAfterConnect:TAfterConnectEvent; FOnFail:TOnFail; function DoEnum(NetResT:PNetResourceA):integer; function addbs(g:string):string;OVERLOAD; function addbs(g:string;SLASH:CHAR):string;OVERLOAD; function SearchFor(NetResT:NETRESOURCE;Path,param:string):boolean; protected { Protected declarations } public { Public declarations } published { Published declarations } function SearchAndAssign:boolean; property ItemToLookFor:String read FItemToLookFor write FItemToLookFor; property LetterToAssign:Char read FLetterToAssign write FLetterToAssign; property IsType:TSIsType read FIsType write FIsType default itDir; property OutputLabel:TLabel read FOutputLabel write FOutputLabel; property UserName:String read FUserName write FUserName; property Password:String read FPassword write FPassword; property BeforeConnect:TBeforeConnectEvent read FBeforeConnect write FBeforeConnect; property AfterConnect:TAfterConnectEvent read FAfterConnect write FAfterConnect; property OnFail:TOnFail read FOnFail write FOnFail; end; |