Jump to content

MainForm global variable define


billyChou

Recommended Posts

thanks logisticasoft.

 

 

 

my test

//--------------------------

 

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses, uniGUIFrame,
  uniGUIRegClasses,  uniguiclasses, uniGUIForm, uniGUIBaseClasses, uniButton
  ;

type
  TMainForm = class(TUniForm)
   
  private
    { Private declarations }
   
  public
    { Public declarations }

 

    //1.  global variable  in Session is  stand-alone  , can not use in MainModule.

 

     sUserid, sUserName  : string;
     sSsid : string;


  end;

function MainForm: TMainForm;

 

 //2.  global variable  is  Session  set/get variable  , get last Session  variable
var
 // sUserid, sUserName ,
  sCompanyid, sMpath, sRpath : string;
  sIp, sBrowseTYpe , sBrowseVer, sOS, sLong, sLati, sCstate : string;
  sSsd, sSsd_date, sSsd_time : string;
 
  iTimeOut : Integer;

implementation

{$R *.dfm}

Link to comment
Share on other sites

 

type
  TMainForm = class(TUniForm)
   
  private
    { Private declarations }
   
  public
    { Public declarations }

 

    //1.  global variable  in Session is  stand-alone  , can not use in MainModule.

 

     sUserid, sUserName  : string;
     sSsid : string;


  end;
 

Actually, you can use those "global" variables (which are, in fact, "public properties") in MainModule (you just have to add your MainForm in uses clause).

Btw, MainForm is instanciated from MainModule, so for each session, you'll get one MainForm and one MainModule.  There is no difference between a MainForm "global variable" (=public property) and a MainModule "global variable".

 

I don't recommend to use your second way of declaring variables : those are not owned by an object, and are not safe in a multi-sessions/multi-thread development.

Link to comment
Share on other sites

 //  "global" variables (which are, in fact, "public properties") in MainModule (you just have to add your MainForm in uses clause).

 

  Test   "global" variables ( "public properties") in MainModule  (  add  MainForm  unit )  can not use .

 

  //-------------------------------------------------

  in MainModule

 

  try

   q_syslog1.Insert;

   q_syslog1.FieldByName('n_user').Value := MainForm.sUserName; // TComponent dose not contain a member names 'sUserName'.
   q_syslog1.FieldByName('n_user').Value := sUserName;  // Undeclared identifier 'sUserName'.


   q_syslog1.FieldByName('f_ssid').Value := aSsid;
   q_syslog1.FieldByName('d_enter').Value:= now;
   q_syslog1.FieldByName('d_upda').Value := DTOS2(now);
   q_syslog1.FieldByName('t_upda').Value := Time2S2(now);
   q_syslog1.FieldByName('c_stat').Value := aState;
   q_syslog1.FieldByName('f_ip').Value   := sIp;

   q_syslog1.FieldByName('f_brwt').Value := sBrowseTYpe;
   q_syslog1.FieldByName('f_brwv').Value := sBrowseVer;
   q_syslog1.FieldByName('f_plat').Value := sOs;

  // q_syslog1.FieldByName('f_eclass').AsString:=E.ClassName;
   q_syslog1.FieldByName('f_log').AsString:= aMsg;

   // ClientDataSet1.Post;
     q_syslog1.Post;
  except
   // ClientDataSet1.Cancel;
     q_syslog1.Cancel;
  end;

 

  //------------------------------------------------

 

 

thanks ZigZig.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...