Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internet Connection

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How my delphi-program can know when my computer is connected to internet?
 
Hi,
You can know whether computer is connected to net or not using Windows system registry.
Just explore the following using code

HKEY_LOCAL_MACHINE
\System\CurrentControlSet\Services\RemoteAccess

and from RemoteAccess access the binary value
'Remote Connection'.
if values obtained is "1" then computer is connected.

Hope it will help you.

Ali Naqvi


 
How i can read the binary value?
Debugger says:
[Error] Unit1.pas(44): Constant object cannot be passed as var parameter
[Error] Unit1.pas(16): Unsatisfied forward or external declaration: 'TForm1.ReadBinaryData'
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'
 
Hi,
Seems from your message errors that you didnt' understand what i meant to. Acutally all you've to do is use registry unit in your uses clause, create an instance of TRegistry and use TRegistry's ReadBinaryData function.

for example


var
reg : TRegistry;
begin
reg := TRegistry.Create;
try
//Set the registry's root path and use openkey to open
the key i've mentioned in my previous msg.
//use reg.ReadBinaryDate(Key,buffer,sizeof(buffer)
// check the value of buffer as buffer parameter is
// passed by reference. if it is '1' then connected
finally
reg.Free;
end;
end;
 
Hi,
Seems from your message errors that you didnt' understand what i meant to. Acutally all you've to do is use registry unit in your uses clause, create an instance of TRegistry and use TRegistry's ReadBinaryData function.

for example


var
reg : TRegistry;
begin
reg := TRegistry.Create;
try
//Set the registry's root path and use openkey to open
the key i've mentioned in my previous msg.
//use reg.ReadBinaryDate(Key,buffer,sizeof(buffer)
// check the value of buffer as buffer parameter is
// passed by reference. if it is '1' then connected
finally
reg.Free;
end;
end;


Hope it will help you.

Ali Naqvi
 
Why this code doesn't work?
The registry unist is in uses clause.


var
Form1: TForm1;
Reg : TRegistry;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
X : Integer;
begin
Reg.ReadBinaryData('Remote Connection', 12, 12): X;
Label1.Caption := IntToStr(X);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('System\CurrentControlSet\Services\RemoteAccess', False);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Reg.Free;
end;

end.
 
Hi,
the only problem with your code is with the use of ReadBinaryDate function.
that function in delphi is defined as

function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;

as here u can see the 2nd parameter is passed by reference and you can't pass it constant.

change your Reg.ReadBinaryData function to sth. like this

Reg.ReadBinaryData('Remote Connection',X,Sizeof(X));

Ali Naqvi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top