Is there a Delphi function that will return a unique ID for the computer/terminal/user session? Context: I've got multiple users accessing a common database, and only want each user to see his/her table content (by a SessionID or ComputerID).
Thanks,
Lane Campbell
NW Software
El 12/12/2014 a las 17:34, Lane Campbell escribió:
> 2) Use Now() at startup, to generate a unique character string (with DateTimeToString() function, format
> 'mmddhhmmsszz').
You are using mm for both months and minutes. You shoud use nn for minutes
>
> Any thoughts on preferred alternative, or on the Now() behavior?
>
You can use the following function to create an unique identifier:
{code}
function CreateUniqueID: String;
var
guid: TGUID;
begin
CreateGUID(guid);
Result:= GUIDToString(guid);
end;
{code}
> Thanks,
>
> Lane Campbell
> NW Software
>
> PS: A bit slow on my acronyms today ... what's a "SID"? How do I get it?
>
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Lane wrote:
>
> > Is there a Delphi function that will return a unique ID for the
> > computer/terminal/user session?
>
> No. And there is no single API function, either.
>
> > Context: I've got multiple users accessing a common database,
> > and only want each user to see his/her table content (by a
> > SessionID or ComputerID).
>
> Neither one of those identifies the user. You would have to use usernames
> or SIDs instead.
>
> --
> Remy Lebeau (TeamB)
OK, got that; I'd also looked at the functions getUserName() and getComputerName(), which DO give a result, but not satisfied with the robustness or guarantee of uniqueness. So, looking at a couple other alternatives for creating my unique "sessionID".
(Context: We're using D2010, working with IBObjects on a Firebird DB)
1) Create a single-field table in my DB with an OnInsert trigger to auto-increment the field. This would happen at program start-up, and be cleared when the program shuts down.
2) Use Now() at startup, to generate a unique character string (with DateTimeToString() function, format
'mmddhhmmsszz'). On the subject of Now(), I tried setting a DateTime or Double variable with Now() and nothing happened ... no error, no result. Now() seems to only work in conjunction with DateTimeToString, or directly settting a DB DateTime field via FieldByName().Value in a TIBOQuery. Any thoughts on what's happening here?
Any thoughts on preferred alternative, or on the Now() behavior?
Thanks,
Lane Campbell
NW Software
PS: A bit slow on my acronyms today ... what's a "SID"? How do I get it?
Lane wrote:
> Is there a Delphi function that will return a unique ID for the
> computer/terminal/user session?
No. And there is no single API function, either.
> Context: I've got multiple users accessing a common database,
> and only want each user to see his/her table content (by a
> SessionID or ComputerID).
Neither one of those identifies the user. You would have to use usernames
or SIDs instead.
--
Remy Lebeau (TeamB)