Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Usersession and procedure question
Hi All,

I have a number of vars defined in UserSession, which I use over and over again in many of the forms, and I need to initialize then at the creation of the form. Currently I do that, for every var, in the create or show of every form.

Is it possible to define a procedure in UserSession, to be called from the forms instead ?

NB! the forms don't have UserSession in the Uses clause. Only the ServerController.

If not, would anyone have other proposals of how to archive the same functionallity ?

Hi Soren, i do this in UserSessionUnit:
    { Private declarations }
    xEmpJNP_Id: Integer;
    xEmpJNP_Nome: String;
    { Public declarations }
    property gEmpJNP_Id: Integer  read xEmpJNP_Id   write xEmpJNP_Id;
    property gEmpJNP_Nome: String read xEmpJNP_Nome write xEmpJNP_Nome;

and all your forms:
{$R *.dfm}

uses ServerController;

  UserSession.gEmpJNP_Id   := 123456;
  UserSession.gEmpJNP_Nome := 'Soren';
Hi Jose,

Thanks for your input. That's the way I use when defining classes. What I'm looking for is a bit more classic:

I have a rec defined in UserSession:

ItemRec = Record // could be a class I know
ItemNo : integer;
ItemName : string

I have 3 databases DB1, DB2, DB3 which all has an Items table. The items table has a record structure like my ItemRec. I use the 3 databass in 3 different forms, F1, F2 and F3.

I only have one form open at a time and when opening a form, I read an item from the database (from DB1 when it is Form1 and so on) and temporary save the Itemno and ItemName in Usersession.ItemNo and UserSession.itemname. And to make sure, UserSession.ItemNo and .Itemname are empty before I use them, I add the lines:
Usersession.ItemNo := 0; and UserSession.ItemName := ''; to the formshow event of F1, F2 and F3.

So in all 3 forms, I have the same 2 lines in the Formshow event.

What I'm looking for is a way to keep the emptying in UserSession, or somewhere else, in a procedure like InitializeItemRec; and instead of the 2 lines in every FormEvent, I just call usersession.initializeItemRec; or {unitname}.initializeItemRec;

My problems is I cant see where to put such an initialize procedure.


Forum Jump:

Users browsing this thread: 1 Guest(s)