通过连接到SQLite数据库使用应用程序共享的Delphi登录表单 [英] Delphi Login Form using App Tethering by Connecting to SQLite Database
问题描述
大家好!
Hi, EveryBody!
我是编程新手! / em>
我需要您的帮助。
I need your help plz.
我有2个项目:
1。项目登录页面。 使用应用程序共享网络和2个按钮(连接按钮=>连接到服务器,登录按钮=>将请求发送到服务器以检查有效的用户名和密码)。
1. Project Login page. Using App Tethering and 2 buttons(Connect button =>connects to the server AND Login button=>Sends request to the Server to check Valid username and password).
2。 Project Server页面。在使用App绑定和FDQuery +( SQLite 数据库test.db)的服务器页面中。
当客户端连接到服务器并将请求发送到服务器以检查有效的用户名和密码时,它将给出错误的结果。 请帮助我正常工作。
2. Project Server page. In a Server Page using App tethering and FDQuery +(SQLite database test.db). When Client Connects to the Server and sends request to the Server to check valid username and password it gives wrong result. plz help me to make work correctly.
1个项目代码:
procedure TfAuth.bLogin(Sender: TObject);
begin
tAProfile.SendString(tManager.RemoteProfiles.First,'Login',tLogin.Text);
tAProfile.SendString(tManager.RemoteProfiles.First,'Password',tPassword.Text);
end;
2。项目代码:
我创建了全局变量
private
{ Private declarations }
public
{ Public declarations }
end;
var
aLogin, aPassword:string;
implementation
{$R *.fmx}
然后我将这段代码放在TetherAppProfile => OnResourceReceived 上:
Then I put put this code on TetherAppProfile=>OnResourceReceived :
procedure TfServerPage.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
begin
if AResource.Hint='Login' then
begin
aLogin:=AResource.Value.AsString;
end;
if AResource.Hint='Password' then
begin
aPassword:=AResource.Value.AsString;
end;
rQuery.Close;
rQuery.SQL.Clear;
rQuery.SQL.Add('select * from authoriation where name='+QuotedStr(aLogin)+'and password='+QuotedStr(aPassword));
rQuery.Open;
if rQuery.RecordCount=0 then // No record found for user
ShowMessage('Be sure user name and password is correct')
else
begin
ShowMessage('Success!');
end;
推荐答案
修改代码如下:
在客户端
procedure TfAuth.bLogin(Sender: TObject);
var
s: string;
begin
s := tLogin.Text + #13 + tPassword.Text;
tAProfile.SendString(tManager.RemoteProfiles.First,'Login',s);
// tAProfile.SendString(tManager.RemoteProfiles.First,'Login',tLogin.Text);
// tAProfile.SendString(tManager.RemoteProfiles.First,'Password',tPassword.Text);
end;
注意!这使用名为 Login的服务器资源。
Note!This uses the server resource named 'Login'.
在服务器中
procedure TfServerPage.tAProfileResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
s: string;
begin
// replace current code before rQuery.Close with the following
s := AResource.Value.AsString;
aLogin := copy(s, 1, Pos(#13, s)-1);
aPassword := copy(s, Pos(#13, s)+1, Length(s));
rQuery.Close;
// continue with rQuery
// ...
end;
服务器中使用 SplitString()
uses System.Types, System.StrUtils ...;
procedure TFrmLoginServer.ServTetProfResourceReceived(const Sender: TObject;
const AResource: TRemoteResource);
var
ss: TStringDynArray;
begin
ss := SplitString(AResource.Value.AsString, #13);
aLogin := ss[0];
aPassword := ss[1];
end;
这篇关于通过连接到SQLite数据库使用应用程序共享的Delphi登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!