Delphi Mysql user login and set premession for each user

Posted on 2014-09-22
Last Modified: 2014-09-29
i have multi user chat program and iam using mysql to define each user has logged in and give him premession

i have 2 forms main and login

in login form here is my code to allow user to login and start using the application

 SQL := Tloginclass.Create;
    SQL.Login:= trim(Usrnm.Text);
    SQL.passwd := trim(passwd.Text);
    if SQl.logins then
      LoginSuccess := True;

Open in new window

but how to sort each user how to show that there is a user joined the room also how to implement the tracking of online users. Second is how to enable/disable some functionality of my application based on the specific user

iam using indy tcp as chat server and client .
Question by:drama22
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40338857
when your user do succesful login - read permission field(s) for that user and store it somewhere (record)
Logic for user activity can be kept in same record on server side:
TChatUserInfo = record
  UserCredential: Integer; //maybe level of user
  LastActivity: TDateTime; // on last login, send message, ... here keep current date/time

Open in new window

Using distance from Now and LastActivity - you can get how many time elapsed and decide about online status.

few examples: (this one have simple user menagement)

Author Comment

ID: 40340232
Example if I want to store his user name what should I do ? Can you tell me an example with my code it will be more understandable for me and I walk on the logic. Thanks for your comment.

Author Comment

ID: 40346516
i make   a public variable in the main form and set this variable string from login form

like this

Main.usernmo := username;

Open in new window

then i did somthing like this to store username

TMember = class(TObject)
Name : string;

Open in new window

then call it like this

mame : TMember;
mame := TMember.Create;
mame.Name := usernmo;
Memo.Lines.Add(mame.Name + '' +' Joined');

Open in new window

is that right way i feel its wrong , could you correct me ?
LVL 27

Accepted Solution

Sinisa Vuk earned 500 total points
ID: 40350793
this is more correct:
  TMember = class(TObject)
    FName: String;
    property Name: String read FName write FName;

Open in new window

... and when you create new member - put it in Tlist for later. On destroy - free all TList members:
UserList: TList;
UserList := TList.Create;
mame := TMember.Create;
mame.Name := usernmo;
//add to list

///server destroy
p: TMember;
for i:=1 to UserList.Count do
   p := UserList.Item[i-1];
   UserList.Item[i-1] := nil;

Open in new window

... you can add/remove some member dynamically  - when user do login/logout...

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
issue with DB import 1 51
MySQL limit and not so limited 13 60
How to extract database info from current month and year 7 45
How to use 2 ON statements in inner join 3 44
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (  Today ( you would not use MySQL…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question