elGringo Posted November 24, 2016 Share Posted November 24, 2016 Having in MainForm procedure TMainForm.UniFormCreate(Sender: TObject); begin FGenerateUniqueCode:=TGenerateUniqueCode.Create(Self); end; in other module procedure TGenerateUniqueCode.DataModuleCreate(Sender: TObject); begin // if (Sender is TMainForm) then begin MainForm_UnitVar:=(Sender as TMainForm); qSelectAllCodes.Connection:=MainForm_UnitVar.DBConnection.FDConnection; qInsertNewCode.Connection:=MainForm_UnitVar.DBConnection.FDConnection; end; end; How to give correct link to TMainForm? On Debug it acts like it doesn' see it, but in TMainForm.UniFormCreate i give link to Self... Link to comment Share on other sites More sharing options...
elGringo Posted November 25, 2016 Author Share Posted November 25, 2016 Does anyone give link to other modules through Sender in UniGUI? Problem I faced on TGenerateUniqueCode.DataModuleCreate App doesn't see the link to MainForm. Link to comment Share on other sites More sharing options...
skafy Posted November 28, 2016 Share Posted November 28, 2016 why dont you use function and return option. Link to comment Share on other sites More sharing options...
elGringo Posted November 28, 2016 Author Share Posted November 28, 2016 skafy, please give example, i usually give links through properties or sender param Link to comment Share on other sites More sharing options...
skafy Posted November 28, 2016 Share Posted November 28, 2016 Something like this DataModule: function TGenerateUniGuiCode.GenereteSomeCode : string; var SomeCode: string; begin SomeCode:= 'SomeCode'; Result:= SomeCode; end; MainModule: procedure TMainForm.UniFormCreate(Sender: TObject); var CodeGenerator: TGenerateUniqueCode; begin CodeGenerator: TGenerateUniqueCode.Create(Self); FGenerateUniqueCode:= CodeGenerator.GenereteSomeCode; //function returns string and saves it to property end; Link to comment Share on other sites More sharing options...
elGringo Posted November 28, 2016 Author Share Posted November 28, 2016 Thank you! As I can see this code gives result of function to the var FGenerateUniqueCode which is string? But I need to give link to whole the instanse, like it would be FGenerateUniqueCode:TGenerateUniqueCode Or am I wrong? Link to comment Share on other sites More sharing options...
skafy Posted November 28, 2016 Share Posted November 28, 2016 Ok, maybe I understood. I usually hold FDConnection inside DataModule and not MainForm. In your case I would create setup function right after creating DataModule. I give to this setup method pointers of components as parameters from main form that i'll be using in datamodule. procedure TGenerateUniGuiCode.SetUp(ASomeConnection: TFDConnection; AAnotherConnection: TFDConnect); begin //Connection1 and Connection2 are TFDConnetion Connection1:= ASomeConnection; Connection2:= AAnotherConnection; end; procedure TMainForm.UniFormCreate(Sender: TObject); var CodeGenerator: TGenerateUniqueCode; begin FGenerateUniqueCode: TGenerateUniqueCode.Create(Self); FGenerateUniqueCode.SetUp(ASomeConnection, AAnotherConnection); end; Link to comment Share on other sites More sharing options...
elGringo Posted November 28, 2016 Author Share Posted November 28, 2016 Yes! You created instance of your data module and use it in MainModule - that's normal situation. In my case i need to give link to MainForm to instance created in uMainForm. My temporary decision is uGenerateUniqueCode ... type TGenerateUniqueCode = class(TDataModule) qSelectAllCodes: TFDQuery; qInsertNewCode: TFDQuery; procedure DataModuleCreate(Sender: TObject); private { Private declarations } FSessionID:integer; FMainForm:TObject; /// <<< Look here, this field to give link to instance of MainForm ... public { Public declarations } function GenerateUniqueCode:integer; property SessionID:integer read FSessionID write FSessionID; property MainForm:TObject read FMainForm write FMainForm; // Look here, this property to give link to instance of MainForm uMainForm ... FGenerateUniqueCode:=TGenerateUniqueCode.Create(Self); FGenerateUniqueCode.MainForm:=Self; // <<< Giving link here ... So, it works, but it is strange that it doesn't work through Sender param like I wrote before ! Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 29, 2016 Administrators Share Posted November 29, 2016 Please DO NOT directly refer to Form instances from other Forms or other Modules. Forms are temporary objects with a limited lifetime. Please keep your session shared data in MainModule or other DataModules. Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 Farshad - thank you for joining. So if I have something on my MainForm that I can't move to MainModule - what can I do in that situation - what will be the proper way? Could you give small example of giving link to MainForm in some other Form? Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 29, 2016 Administrators Share Posted November 29, 2016 What sort of object do you have which you can't move to MainModule? Link to comment Share on other sites More sharing options...
jaromir Posted November 29, 2016 Share Posted November 29, 2016 I think that You should re-organize architecture. If MainForm contains something important - maybe You can make simple factory in MainModule which hold this data together with session object. So during MainForm start You make something like this: MainModule.Factory.Register(ThisSession, MyData). Next other objects (forms) can call MainModule.Factory.GetData(ThisSession). At the end Unregister should be of course. This is theory - I don't know Your needs. Regards Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 ok, little program for SMS confirmation, on MainForm i have tuniedits and tunibuttons like this (on the picture attached, all in Russian but nevermind for the question) I need info from tuniedits that I need in other module, so I need access to tuniedits on MainForm. I usually just give link to instance of main form and use proper info. So what would be decision here? Maybe to put all controls on Separate frame? Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 29, 2016 Administrators Share Posted November 29, 2016 You can define a shared data structure in MainModule's public section and populate it with data from Edits on MainForm. Link to comment Share on other sites More sharing options...
jaromir Posted November 29, 2016 Share Posted November 29, 2016 It is not so happy when You take action results from edit fields. You should have this data in memory structure and singleton factory for holding this datas in MainModule. After action execute data is pushed to factory and from then it is available for everyone (for edit fields and other system elements). Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 So u mean send info to Special Structure on MainModule and then use it? Just there is no books or manual about such things and I used usual coding style as in Delphi. As I can understand you that's needed cause all forms in UniGUI have shorter life time than MainModule ? So info will be more safe? Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 Than not only safe but also available to other forms in other sessions? Link to comment Share on other sites More sharing options...
jaromir Posted November 29, 2016 Share Posted November 29, 2016 Hmm I'm just beginner in UniGui but maybe I will have luck You have two DataModules in project - MainModule and ServerModule. MainModule is one for session and ServerModule is one for whole application - simple. So when Your data is important cross sessions that You should put it in ServerModule. When You need data access only for current session You should go to MainModule. Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 29, 2016 Administrators Share Posted November 29, 2016 Each form is erased from memory when user closes it. There is a danger here if you try to access it from other modules/forms after it is freed. Try following a design pattern which doesn't rely on accessing data stored on other forms. Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 That's clear for the moment. So, forms are just interface elements that collect data and send it to MainModule which is 1 per session or to Server Module which is 1 per App. Data from forms should be collected in special Structures in Memory which are like mirror to form elements. The same is with connection to DB - should be 1 per App, so it should be in ServerModule for example. So, thats clear now. Thank you, dear all !!! Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 29, 2016 Administrators Share Posted November 29, 2016 No! Never put a connection on a ServerModule! ☺ Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 Why? What will be wrong with that? New day new info))) Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 That is very intersting moment here ! Initially I put FDConnection to MainForm or special unit for FDConnection that I called in Main form and connected to DB. I use FireDAC and MySQL so I just put libmysql.dll to EXE folder and it is OK if I use Stand Alone Mode. Yesterday I tried to convert my EXE to DLL and started UniAPP on IIS - so UniAPP could not find libmysql.dll I tried to put it to the folder where IIS start itself, but no effect, then to system32, also no effect, Then I tried to use FDManager - who knows that is special component in FireDAC to set up persistent connections, but nevermind here - it should be used 1 per APP, so if to put FDManager and other FD components to MainForm - than it errors that 1 FD Manager should be used... Than I put all FD components to Server Module - and it works - and now you say Never put it to Server Module ))) It is kind of quest for me. Link to comment Share on other sites More sharing options...
delagoutte Posted November 29, 2016 Share Posted November 29, 2016 Yesterday I tried to convert my EXE to DLL and started UniAPP on IIS - so UniAPP could not find libmysql.dll I tried to put it to the folder where IIS start itself, but no effect, then to system32, also no effect, Do you try c:\windows\SysWow64\ if your dll is 32bits. Have you got your FDGUIxWaitCursor.screencursor set to grcnone. I'm using unigui with firedac and isapi on iis without problem Link to comment Share on other sites More sharing options...
elGringo Posted November 29, 2016 Author Share Posted November 29, 2016 delagoutte hello! Thank you for joining. No, i tried to put to C:\Windows\System32 but it nevermind i have special folder on C:\MySQLDriver where i keep libmysql.dll FDConnectionDefs.ini and FDDrivers.ini Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now