Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:44:11+00:00 2026-06-09T16:44:11+00:00

I want to ask the user to input a password. As the password is

  • 0

I want to ask the user to input a password. As the password is sometimes needed in a different thread than the main thread where VCL runs, I tried to send a Message to the main window and ask for the password. Then the main window asks the user.

How I ask the user:

procedure TMainForm.WMGetPassword(var Msg: TMessage);
var
  Password: String;
begin
  if QueryPassword(Password) then // function QueryPassword(out Password: String): boolean;
  begin
    Password := Password + #0; // Add #0-Terminator
    Move(Password[1], Msg.wParam, Length(Password) * sizeOf(Char)); // Copy the String in my buffer
    Msg.Result := 1;
  end
  else
  begin
    Msg.Result := 0;
  end;
end;

How I ask the main window:

var
  PasswordBuffer: PChar;
  Password: String;
begin
  PasswordBuffer := AllocMem(100 * sizeof(Char));
  PasswordResult := SendMessage(MainFormHWND, WM_GetPassword, Integer(PasswordBuffer), 0);
  Result := (PasswordResult <> -1);
  if not Result then
    Exit;

  SetString(Password, PasswordBuffer, 100);
  ShowMessage(Password);
end;

But Password and PasswordBuffer are empty afterwards. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:44:12+00:00Added an answer on June 9, 2026 at 4:44 pm

    As long as the thread is in the same process (so it shares the same address space) your code should work. It is however needlessly complicated and has a memory leak (PasswordBuffer is never freed).

    You can use a string variable in the thread and pass an address to its internal preallocated buffer to the main thread:

    type
      TTestThread = class(TThread)
      private
        fHwnd: HWND;
      protected
        procedure Execute; override;
      public
        constructor Create(AWnd: HWND);
      end;
    
    constructor TTestThread.Create(AWnd: HWND);
    begin
      fHwnd := AWnd;
      inherited Create(False);
    end;
    
    procedure TTestThread.Execute;
    const
      MAXLEN = 1024;
    var
      s: string;
    begin
      SetLength(s, MAXLEN);
      if SendMessage(fHwnd, WM_GETPASSWORD, MAXLEN, LPARAM(@s[1])) > 0 then begin
        s := PChar(s);
        // don't use VCL here
        Windows.MessageBox(0, PChar('password is "' + s + '"'), 'password',
          MB_ICONINFORMATION or MB_OK);
      end;
    end;
    

    In the main thread the password is put into the buffer, length-limited to the buffer size:

    procedure TForm1.WMGetPassword(var AMsg: TMessage);
    var
      Pwd: string;
    begin
      if InputQuery('Password Entry', 'Please enter the password:', Pwd)
        and (Pwd <> '')
      then begin
        StrPLCopy(PChar(AMsg.LParam), Pwd, AMsg.WParam);
        AMsg.Result := 1;
      end else
        AMsg.Result := -1;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to ask user to input something but not want to wait forever. There
I want to ask the user for input in console. He'll be writing down
Alright so in Java I want to ask the user for a time in
In my GWT application, I want to ask a user confirmation when he navigates
Suppose I ask the user do you want to run in 32bit mode or
I want to have a menu display that accepts user input. However, I want
In my lua program, i want to stop and ask user for confirmation before
What I want to do is ask the user for a number of strings
I want to build a site that will ask if the user is male
I ask for a user to input 4 numbers or letter from 1 -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.