webimage OnPasswordRequest event
Return to Introduction  Previous page  Next page
Applies to
acWebImage, acHTTP and acAutoUpgrader components.  

Declaration
type  
  TacHTTPPasswordRequestEvent = procedure(Sender: TObject;  
     const Realm: Stringvar TryAgain: Boolean) of object;  
 
property OnPasswordRequest: TacHTTPPasswordRequestEvent;  

Description
The OnPasswordRequest event can be used to implement the dialog which asks user for his username and password to access the password protected Web area.  
 
Set TryAgain parameter to True to retry the HTTP query with correct username and password. (Don't forget to specify correct login information in this event handler to Username and Password properties.)  

Note
iiwarning If you leave this event unhandled (set TryAgain parameter to False), the component will generate error code #401 (Access Denied) and OnError event occur.  

Example
Delphi:
procedure TForm1.WebImage1PasswordRequest(Sender: TObject;  
  const Realm: Stringvar TryAgain: Boolean);  
begin  
  { UserPassForm is any form with two edit boxes used for entering the login information (username and password) }  
  UserPassForm.RealmLabel := Realm;  
  if UserPassForm.ShowModal = ID_OK then  
  begin  
    acHTTP1.Username := UserPassForm.UsernameEdit.Text;  
    acHTTP1.Password := UserPassForm.PasswordEdit.Text;  
    TryAgain := True; // Retry HTTP query (download attempt)  
  end;  
end;  



C++ Builder:

void __fastcall TForm1::acHTTP1PasswordRequest(TObject *Sender,  
      AnsiString Realm, bool &TryAgain)  
{  
  UserPassForm->RealmLabel = Realm;  
  if (UserPassForm->ShowModal() == ID_OK)  
  {  
    acHTTP1->Username = UserPassForm->UsernameEdit->Text;  
    acHTTP1->Password = UserPassForm->PasswordEdit->Text;  
    TryAgain = True; // Retry HTTP query (download attempt)  
  };  
}  

See also
Username and Password properties; OnHTTPError event;  
HTTP Status Codes.