billyChou Posted May 25, 2016 Share Posted May 25, 2016 How to define MainForm global variable and support in other form , MainModule, Thanks. Quote Link to comment Share on other sites More sharing options...
asapltda Posted May 25, 2016 Share Posted May 25, 2016 There are two global variables types , one for the session and one for the application , session see datamodulo or MainModule.pas , for application see servermodule Quote Link to comment Share on other sites More sharing options...
billyChou Posted May 26, 2016 Author Share Posted May 26, 2016 thanks logisticasoft. my test //-------------------------- unit Main;interfaceuses 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} Quote Link to comment Share on other sites More sharing options...
ZigZig Posted May 26, 2016 Share Posted May 26, 2016 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. Quote Link to comment Share on other sites More sharing options...
billyChou Posted May 27, 2016 Author Share Posted May 27, 2016 // "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. Quote Link to comment Share on other sites More sharing options...
ZigZig Posted May 27, 2016 Share Posted May 27, 2016 From MainModule, try this : q_syslog1.FieldByName('n_user').Value := TMainForm(MainForm).sUserName; Also, be sure that you call your procedure when MainForm is already created. Quote Link to comment Share on other sites More sharing options...
billyChou Posted May 27, 2016 Author Share Posted May 27, 2016 Thanks ZigZig , it is ok. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.