Guest Posted January 31, 2011 Share Posted January 31, 2011 Message from: "zilav" Greetings Farshad! I need your advice. Like your megademo, I have dynamically created uniframes in my application with datasources/grids, and frame opens additional forms with data controls on them. However, I can't bind those controls to datasource in frame. I can do it in runtime (and must do it, since frames are dynamically created), but writing fieldnames in dbedits and lookups manually in designer is tedious and a waste of time. Is there a way to trick designer to see datasources in frames? Or create UniModule for each frame, and place all datasets/sources there and make all bindinds, but how do I manually create unimodule along with frame creation, and destroy it when frame is destroyed in runtime? Or perhaps there is a better way? p.s. In Dephi XE . Quote Link to comment Share on other sites More sharing options...
Guest Posted January 31, 2011 Author Share Posted January 31, 2011 Message from: "Farshad Mohajeri" "zilav" wrote in message news:TmHi22UwLHA.2720@anaxagvs227... > Greetings Farshad! > > I need your advice. Like your megademo, I have dynamically created > uniframes in my application with datasources/grids, and frame opens > additional forms with data controls on them. However, I can't bind those > controls to datasource in frame. I can do it in runtime (and must do it, > since frames are dynamically created), but writing fieldnames in dbedits > and lookups manually in designer is tedious and a waste of time. Is there > a way to trick designer to see datasources in frames? This is a Delphi limitation which is by design. Only Forms and DataModules are visible to designer for binding DataSources. Frames is not a good place for datasources. If you want to create everything at runtime then I think you must do the bindings in runtime too. >Or create UniModule for each frame, and place all datasets/sources there >and make all bindinds, but how do I manually create unimodule along with >frame creation, and destroy it when frame is destroyed in runtime? In runtime, you must be able to create a regular DataModule and Destroy it in a normal way, but I haven't used it this way and can't guarantee that it works. > Or perhaps there is a better way? Why aren't you using static designtime DataModules? . Quote Link to comment Share on other sites More sharing options...
Guest Posted January 31, 2011 Author Share Posted January 31, 2011 Message from: "zilav" > Why aren't you using static designtime DataModules? My app will grow later and will have dozens of frames, each will have their own datasets, so I don't want to mess everything in one module. If I place db components in different modules, then I have a few questions: 1) when are they created: at program startup? 2) at start of each session? 3) are they all created separately for each session, or common for all sessions? 4) what exactly does UniMainModule.GetModuleInstance do: create instance of datamodule and return it? if I call it again for the same datamodule - does it create a new instance, or return a previous one? How to free them properly - as usual, or call some special method from UniMainModule as with creation? In the end, I want to have datasets at runtime only for current frame, in different datamodules, free them when frame switches, and be able to bind in designer. Is it possible at all? . Quote Link to comment Share on other sites More sharing options...
Guest Posted February 1, 2011 Author Share Posted February 1, 2011 Message from: "Farshad Mohajeri" "zilav" wrote in message news:mlSPoVYwLHA.2160@anaxagvs227... >> Why aren't you using static designtime DataModules? > > My app will grow later and will have dozens of frames, each will have > their own datasets, so I don't want to mess everything in one module. If I > place db components in different modules, then I have a few questions: > 1) when are they created: at program startup? no > 2) at start of each session? yes > 3) are they all created separately for each session, or common for all > sessions? yes, separately for each session. > 4) what exactly does UniMainModule.GetModuleInstance do: create instance > of datamodule and return it? No, it used internally to retrieve an existing instance of a TDataModule descendant. > if I call it again for the same datamodule - does it create a new > instance, or return a previous one? it returns a previous one. >How to free them properly - as usual, or call some special method from >UniMainModule as with creation? > If you want to create DataModules dynamically do it like this. 1-Create DataModule at design time from *uniGUI Wizard*. 2-In DataModule source code comment the below line so Module is not created automatically when session starts: // RegisterModuleClass(TDataModulexxx); 3-Put whatever Data components you have and make the necessary bindings to frame. 4-At runtime create the DataModule *before* you create your frame and destroy it *after* your frame is destroyed. You can use nil as owner for DataModule. > In the end, I want to have datasets at runtime only for current frame, in > different datamodules, free them when frame switches, and be able to bind > in designer. Is it possible at all? You need to do it as I described above. If you create and destroy DataModules in right place and correct order it must work. good luck! . Quote Link to comment Share on other sites More sharing options...
Guest Posted February 1, 2011 Author Share Posted February 1, 2011 Message from: "zilav" >You need to do it as I described above. If you create and destroy >DataModules in right place and correct order it must work. >good luck! Thanks Farshad, I'll try it later. Keep up a great work, you web framework is the best. . 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.