Using inherited components for web modules lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- Leledumbo · 2011-04-09 16:39 I'm writing a web app using template driven web style, where modules only handle the content part, while layouting etc. is handled by parent module. This approach requires inheritance, as can be seen in the attached diagram. In this case, IndexModule acts as the one responsible for layouting, with some default simple actions (usually with only static content). ProblemModule and ProfileModule should fill the content part corresponds to the request. For example, if the request is problem/browse, the content should be filled with a list of problems. While if it's profile/edit, then an editable form containing user information should be displayed. I try to do the inheritance via File->New->Inherited project component and it's compilable, but when I try to request actions in problem module, I got this error: QuoteDuplicate name: A component named "IndexModule" already existsRequesting IndexModule's actions are fine. In case anyone needs to see the source, I've attached it as well. It requires embweb package. ---------------------------------------------------------------------- bobo · 2011-04-15 02:16 I did check out your sample project and tried to understand your terminology and what you try to achieve. I think, that to accomplish what you want you don't need any kind of inheritance. You do not even need multiple webmodules, just one. Note, you can use more than one by adding them with File->New->Webmodule,  which is the correct way to be able to use "index/home", "problem/browse" instead of what you have tried (index and problem are the webmodule names). So basically you would have two webmodules, one called "index" another called "problem" and you could call the actions in these webmodules the way you have tried. But this is not needed, you can just use one webmodule with as many actions as you need. For example, instead of "index/home" the action would be "ihome" or just "home" and you would not even need to use the webmodule name in your urls. Ex: Right now, to call your "index/home" probably looks something like http://127.0.0.1:8080/cgi-bin/mycgi.exe/index/home (webmodule is "index" and the action that is called is "home") but it could be http://127.0.0.1:8080/cgi-bin/mycgi.exe/home instead (by doing this way, fbweb uses the default webmodule and just calls the action "home" from there). Same for problem/browse (calling action "browse" in webmodule "problem"), it could be just defined in the same webmodule, and called by http://127.0.0.1:8080/cgi-bin/mycgi.exe/browse The action names are really irrelevant and for users it does not matter what the calling URL is. In fact, you can have just one single webmodule action, handling all screens by simply using an ID parameter that you can pass. Ex: http://127.0.0.1:8080/cgi-bin/mycgi.exe/getscreen?id=2  could call for the content of the current problems/browse action. Inside the "getscreen" action, you can just check what the passed "ID" was and generate the response accordingly. You can even use additional templates for the different screen parts by using fptemplate. One more thing, instead of initiating the template settings in the DataModuleGetAction, you should do it in the DataModuleCreate because that is only called once, and not for every call (this only matters for Apache modules and FCGI programs though). ---------------------------------------------------------------------- Leledumbo · 2011-04-15 02:46 QuoteYou do not even need multiple webmodules, just one. ... But this is not needed, you can just use one webmodule with as many actions as you need. For example, instead of "index/home" the action would be "ihome" or just "home" and you would not even need to use the webmodule name in your urls. ...I need modularity, and using just one web module isn't a logical way to group actions. index may also have login and logout action, problem may also have submit and statistic action. I don't think your suggestion is the intended way to develop web applications beautifully. QuoteThe action names are really irrelevant and for users it does not matter what the calling URL is.It is relevant for the web service part (on the way). QuoteOne more thing, instead of initiating the template settings in the DataModuleGetAction, you should do it in the DataModuleCreate because that is only called once, and not for every call (this only matters for Apache modules and FCGI programs though).Unexpectedly, somehow the actions doesn't get called if I put it there. I know because there's a postprocessing after the OnReplaceTag, see ~Content in the template, an this ~Content doesn't get replaced. That's why I put in OnGetAction (already tried to put it OnCreate before) and the ~Content got replaced. ---------------------------------------------------------------------- bobo · 2011-04-16 01:09 QuoteUnexpectedly, somehow the actions doesn't get called if I put it there. I know because there's a postprocessing after the OnReplaceTag, see ~Content in the template, an this ~Content doesn't get replaced. That's why I put in OnGetAction (already tried to put it OnCreate before) and the ~Content got replaced. Then you are doing something wrong. It is working properly with fpweb for sure. Do not forget, that if you are using multiple webmodules, then you need to do the Template init things in all of them, because the Template property you use is a global property of each webmodule, and not the Template property of the webactions. For example, doing a  Code: [Select]ResponseStr := Template.GetContent;in a webaction event handler within the "Index" webmodule will access the Template global property of the "Index" webmodule, and not the "Template" property of the given webaction (the one you see in the Object Inspector for every webaction). Also, you need to create the actions within the proper webmodule for them to work in the way you've tried to use them in your example. ---------------------------------------------------------------------- Leledumbo · 2011-04-16 18:29 QuoteThen you are doing something wrong. It is working properly with fpweb for sure.You mean, it 'should'. QuoteDo not forget, that if you are using multiple webmodules, then you need to do the Template init things in all of them, because the Template property you use is a global property of each webmodule, and not the Template property of the webactions. ... in a webaction event handler within the "Index" webmodule will access the Template global property of the "Index" webmodule, and not the "Template" property of the given webaction (the one you see in the Object Inspector for every webaction). Also, you need to create the actions within the proper webmodule for them to work in the way you've tried to use them in your example.Yeah, I know. But since problem module inherits index, I suppose calling Template.GetContent would call GetContent of Template defined in index module. I'll try to single-step the code to know the request flow.