function TServobj.UserExists(const Username, Password: String): Boolean;
var
Exists: Boolean;
begin
TThread.Synchronize(nil,
procedure
begin
connectionmo.userslq.Close;
connectionmo.userslq.SQL.Clear;
connectionmo.userslq.SQL.Add('SELECT * FROM `users` WHERE `username` = "'+ trim(Username) +'" AND `password` = "' + trim(Password) + '"');
connectionmo.userslq.Open;
try
Exists := not connectionmo.userslq.IsEmpty;
finally
connectionmo.userslq.Close;
end;
end);
Result := Exists;
end;
procedure TServobj.TcpServerExecute(AContext: TIdContext);
var
Command: String;
....................
..................
begin
Command := AContext.Connection.Socket.ReadLn; //read command
if Command = 'LOGIN' then
begin
usrnm := Params[1];
passwd := params[2];
if not userexists(usrnm, passwd) then// i want to synchronize this
begin
AContext.Connection.Socket.WriteLn('INVALIDPASSWORD');
end;
end;
is this correct ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ in god i trust with every movement i do graduated student and looking for knowledge
An example of when you would want to use Synchronize is when you want to interact with either a VCL or a FireMonkey component. Use an in-place anonymous method to solve the problem of passing variables to the method you want to sychronize: yazdı:
Synchronize(
procedure
begin
Form1.Memo1.Lines.Add(‘Begin Execution’);
end);
- IMHO do not try to access that AContext unless it is not a member of Thread.
- Only use a procedure for Synchronize which triggers any event.
- Trigger may be an VCL.TEXT that that triggers an event (you write a text to TEdit in procedure and TEdit's OnChange event fires automatically) or a Global Variable which a timer or boolean controlled infinite loop waits for it.
Yes it looks you can.
Try it and inform us with your experience please.
One more other point some issues i stucked with threads before.
When i create a panel or some thing on the fly and make it's parent to the main thread's any win control, finally could not free it.
So be careful like this inter-thread VCL based creations.
i tried to synchronize using tidnotifay but i have bad feeling about it , when i try to use TThread i got complex in my mind and dont know where to start
here is the server project with trying of using Tidnotify