使用方法の小さなデモを作成しました
コードをダウンロードするには、ここをクリックしてください
以下に、コードの一部を示します。
まず、資格情報を保持するためのレコードと、それらのリストが必要です。
Type
TCredential = record
Username, Password, Domain: string;
constructor Create(const aUsername, aPassword, aDomain: string);
function AreEqual(const aUsername, aPassword, aDomain: string): Boolean;
end;
TCredentialList = class(TList<TCredential>)
public
function IsValidCredential(const aUsername, aPassword, aDomain: string): Boolean;
end;
次に、これを呼び出すコンテキストを定義する必要があります。これは、各ログイン機能を識別するアプリケーション固有の文字列です。
const
Context = 'TForm1';
フォーム作成で、リストを作成し、それにダミーデータを追加します
procedure TForm1.FormCreate(Sender: TObject);
begin
CredentialList := TCredentialList.Create;
//Add Dummy data
CredentialList.Add(TCredential.Create('AA', 'AA', 'DomainAA'));
CredentialList.Add(TCredential.Create('BB', 'BB', 'DomainAA'));
CredentialList.Add(TCredential.Create('CC', 'CC', 'DomainAA'));
// Register your Login handler in a context.
// This method is called when you try to login
// by caling TLoginCredentialService.GetLoginCredentials();
TLoginCredentialService.RegisterLoginHandler(Context, LoginCredentialEvent);
end;
フォームにボタンを配置しました。そこからログインを呼び出します。
procedure TForm1.Button1Click(Sender: TObject);
begin
// The actual call to login
// First param is the context
// Second Parameres is a callback function given to the event handler.
TLoginCredentialService.GetLoginCredentials(Context,
function { LoginFunc } (const Username, Password, Domain: string): Boolean
begin
//The actual user validation
Result := CredentialList.IsValidCredential(Username, Password, Domain);
end);
end;
最後に、loginhandler を実装する必要があります。
//This is the "onLogin" event handler.
//This is called durring a login attempt
//The purpose of this event handler are to call tha callBack function with correct information
//and handle the result
procedure TForm1.LoginCredentialEvent(Sender: TObject; Callback: TLoginCredentialService.TLoginEvent; var Success: Boolean);
begin
//Call the callback
Callback(Sender, LabeledEdit1.Text, LabeledEdit2.Text, LabeledEdit3.Text, Success);
//Handle the success.
if Success then
Label1.Caption := 'Yes'
else
Label1.Caption := 'No';
end;
これが質問に答えてくれることを願っています。完全なコードをここからダウンロードすることを忘れないでください