Delphi 通过连接到 SQLite 数据库使用 App Tethering 登录表单
Delphi Login Form using App Tethering by Connecting to SQLite Database
大家好!
我是编程新手!
我需要你的帮助
我有 2 个项目:
1.项目登录页面。 使用 App Tethering 和 2 个按钮(连接按钮 => 连接到服务器和登录按钮 => 向服务器发送请求以检查有效的用户名和密码)。
2。项目服务器页面。在使用应用程序网络共享和 FDQuery +(SQLite 数据库 test.db) 的服务器页面中。
当客户端连接到服务器并向服务器发送请求以检查有效的用户名和密码时,它会给出错误的结果。 请帮助我正确地完成工作。
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 :
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' 的服务器资源。
在服务器中
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;
大家好!
我是编程新手!
我需要你的帮助
我有 2 个项目:
1.项目登录页面。 使用 App Tethering 和 2 个按钮(连接按钮 => 连接到服务器和登录按钮 => 向服务器发送请求以检查有效的用户名和密码)。
2。项目服务器页面。在使用应用程序网络共享和 FDQuery +(SQLite 数据库 test.db) 的服务器页面中。 当客户端连接到服务器并向服务器发送请求以检查有效的用户名和密码时,它会给出错误的结果。 请帮助我正确地完成工作。
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 :
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' 的服务器资源。
在服务器中
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;