[SOLVED] Custom form lazarus / 31-LCL ---------------------------------------------------------------------- pcurtis · 2021-12-16 18:59 I want to make a custom form with a few extra properties, no problem. My question is how can I make this form the default in Lazarus? ---------------------------------------------------------------------- Lulu · 2021-12-16 19:29 If by 'default form' you means the main form, simply move the line where it is created to the first position in your project .lpr file. It must be created first. ---------------------------------------------------------------------- pcurtis · 2021-12-17 08:17 By default I mean create this by default Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, [b]MyForm[/b], Controls, Graphics, Dialogs; type  TForm1 = class([b]TMyForm[/b])  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} end.  and automatically add MyComponents to the projects requirements. ---------------------------------------------------------------------- Mr.Madguy · 2021-12-17 08:21 I guess, it requires modifying Lazarus sources. ---------------------------------------------------------------------- pcurtis · 2021-12-17 08:22 Any idea where? ---------------------------------------------------------------------- zeljko · 2021-12-17 12:56 Maybe you should look into "New..." command in ide (just below New Form). You can register your own customform as package in ide and then create it via "New..." cmd (so no need to touch lazarus sources), or of course you can override "New Form" cmd with your own in lazarus sources. ---------------------------------------------------------------------- pcurtis · 2021-12-17 15:40 @zeliko Looks like the way to go. How do I add my form there as a project? ---------------------------------------------------------------------- dsiders · 2021-12-17 16:26 Quote from: zeljko on December 17, 2021, 01:56:16 pmMaybe you should look into "New..." command in ide (just below New Form). You can register your own customform as package in ide and then create it via "New..." cmd (so no need to touch lazarus sources), or of course you can override "New Form" cmd with your own in lazarus sources. Are you referring to the facilities in components/custform package? If so, it needs to be installed into the IDE. ---------------------------------------------------------------------- balazsszekely · 2021-12-17 16:46 @pcurtis QuoteLooks like the way to go. How do I add my form there as a project?You cannot add your form as project. That doesn't even make sense. 1. Open your project 2. Create a new form(uMyNewForm/fMyNewForm), save unit 3. Go to File->New->Inherited Item->Inherited Project component 4. Select fMyNewForm, press OK 5. The IDE will create a new form, which inherits from fMyNewForm Is this what you are after? ---------------------------------------------------------------------- pcurtis · 2021-12-17 17:20 Can I make a project template and add it there? (don't mention Tools => Project Templates. That completely sucks) ---------------------------------------------------------------------- jamie · 2021-12-18 11:28 I guess a question would be is, are you trying to add these properties to all forms ever created in the system or just the initial form? ---------------------------------------------------------------------- pcurtis · 2021-12-18 12:36 Just the initial form ---------------------------------------------------------------------- jamie · 2021-12-18 15:08 What I do for something like that is use the "New project From File" option. that lets you go select a PAS file unit which can be your first unit..   You create a simple project with all of your properties added, uses etc. Save that project as a base project for example and when ever you need a new project you can use the "new project From File" then you can navigate over to that project you created and load the unit file, it will start you off from that point on and should not affect the base project you grabbed that from. ---------------------------------------------------------------------- pcurtis · 2021-12-18 15:52 OK thanks for the tip, but that only solves half the problem. What if my unit has certain package requirements? How do I add them? ---------------------------------------------------------------------- jamie · 2021-12-18 16:32 if you have a folder full of special base projects you can simply open any one of those to start a new project and then use the SaveProjectAs to a new folder before you start editing.  I think that maybe the Tools menu has the Template option to set a path to a template folder section where you can fetch these from but I am not so sure if laz has built in safeguards to keep you from over writing them. ---------------------------------------------------------------------- pcurtis · 2021-12-18 16:50 Project templates would solve everything, but as normal it doesn't work correctly. IMHO development of Lazarus should pause a few cycles and work should taken out to iron out issues, not add more. But I'm just a user. ---------------------------------------------------------------------- JuhaManninen · 2021-12-18 16:52 Quote from: pcurtis on December 17, 2021, 06:20:14 pmCan I make a project template and add it there? (don't mention Tools => Project Templates. That completely sucks) The ProjTemplates package got improved in trunk recently. It should do the job for you. As Jamie mentioned, Tools menu only has "Project templates options ..." with one path setting. You must place the template files under that path. I don't know why you think it sucks, but the options entry is in a wrong place. The package should register its own pane in the global Options window just like other packages do. [Edit] QuoteProject templates would solve everything, but as normal it doesn't work correctly.Please test with the development version. See: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38244 ---------------------------------------------------------------------- pcurtis · 2021-12-18 17:09 It sucks because it doesn't work as expected. Try the attached template. When creating a project don't fill in anything just push OK, OK and kaboom. If nothing is filled in defaults should be used as in new project. Not rocket science. Even if the fields are filled in it complains about other things. ---------------------------------------------------------------------- JuhaManninen · 2021-12-18 17:57 Quote from: pcurtis on December 18, 2021, 06:09:31 pmIt sucks because it doesn't work as expected. Try the attached template. When creating a project don't fill in anything just push OK, OK and kaboom. In your project.ini file the Variables section is empty. I added this and it works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [Variables]MAINUNIT=New filename for the Unit1.pas fileTITLE=Form CaptionBTNCAPTION=Button Caption QuoteIf nothing is filled in defaults should be used as in new project. True. It could be improved. Any non-defined variable should get a sensible value, for example the variable name itself. Thus variable MAINUNIT would have value MAINUNIT. It would work and prevent crashes. Also the initial dialog asking for project name and directory should have OK button disabled as long as the necessary info is not given. See also the example template in the issue I linked earlier. Patches are still welcome... ---------------------------------------------------------------------- pcurtis · 2021-12-18 18:24 For me it complains the lpi file is not a lpi file ---------------------------------------------------------------------- pcurtis · 2021-12-18 18:26 Do you know where the relevant code is in the ide? ---------------------------------------------------------------------- JuhaManninen · 2021-12-18 18:38 Quote from: pcurtis on December 18, 2021, 07:24:04 pmFor me it complains the lpi file is not a lpi file Strange. For me it compiles and runs fine. The attached screenshot shows your form in both design time and runtime. I filled the variable names when creating the project. What is your Lazarus version? QuoteDo you know where the relevant code is in the ide?Code for reading the .lpi project info file? It is somewhere in the project.pp file. You can search with the error message you got. ---------------------------------------------------------------------- pcurtis · 2021-12-18 18:44 2.0.12 See tag line ---------------------------------------------------------------------- jamie · 2021-12-18 18:51 Quote from: pcurtis on December 18, 2021, 07:44:38 pm2.0.12 See tag line I see you have a space in the file path, I try to avoid those at all cost because I've seen strange things happen.. could you rename the path without the SPACE in it? ---------------------------------------------------------------------- JuhaManninen · 2021-12-18 18:58 Quote from: pcurtis on December 18, 2021, 07:44:38 pm2.0.12 I asked you to test with the latest development version. It has an improved Project Templates package. In 734cf1a136 I disabled the OK button while necessary information is not given. This and the earlier important change will be merged to 2.2. ---------------------------------------------------------------------- pcurtis · 2021-12-18 19:23 @jamie now i get a file not found. the directory is empty ---------------------------------------------------------------------- jamie · 2021-12-18 19:27 Quote from: pcurtis on December 18, 2021, 08:23:08 pm@jamie now i get a file not found. the directory is empty Did you update the Template path too ? I don't know, you may need to restart laz after those changes, they could be cached. ---------------------------------------------------------------------- pcurtis · 2021-12-18 19:33 @juham IMHO that logic is only half right. the filename should be the default project output directory, the project name should default to project1. that way you dont force a user to enter anything, just like when you create a new project. latter the user can save project as ---------------------------------------------------------------------- pcurtis · 2021-12-18 19:42 @jamie after restart the files are created but i go back to the strange lpi error. i wonder if this has ever been tested? many people on this forum have issues with templates ---------------------------------------------------------------------- JuhaManninen · 2021-12-18 21:41 Quote from: pcurtis on December 18, 2021, 08:42:43 pmafter restart the files are created but i go back to the strange lpi error. Are you now testing with the latest development version? [Edit]  In 7e1fcc4033 I gave variables default values. Please test. ---------------------------------------------------------------------- pcurtis · 2021-12-19 01:17 whats the url for 7e1fcc4033 ---------------------------------------------------------------------- dsiders · 2021-12-19 03:15 Quote from: pcurtis on December 19, 2021, 02:17:39 amwhats the url for 7e1fcc4033 gitlab does not provide a url for a commit. It does have them for the source: https://gitlab.com/freepascal.org/lazarus/lazarus/- /archive/main/lazarus-main.zip Or a specific path: https://gitlab.com/freepascal.org/lazarus/lazarus/- /archive/main/lazarus-main.zip?path=components/projecttemplates ---------------------------------------------------------------------- pcurtis · 2021-12-19 06:29 OK. ive downloaded https://gitlab.com/freepascal.org/lazarus/lazarus/- /archive/main/lazarus-main.zip unzipped it to a new dir what next? ---------------------------------------------------------------------- JuhaManninen · 2021-12-19 10:34 Quote from: pcurtis on December 19, 2021, 07:29:19 amwhat next? Assuming you have FPC installed, build the new sources with "make". You can also copy the Project Templates package directory into your existing Lazarus installation and rebuild that. In long-term I recommend you learn to use Git and build the sources. It is important for testing new features and for reporting bugs. Now trunk is so much ahead of 2.12 that you will be positively surprised. Hint: TortoiseGit seems to work well on Windows. ---------------------------------------------------------------------- pcurtis · 2021-12-19 11:00 isnt make a -nix thing? what package templates directory? have i downloaded the right thing? https://gitlab.com/freepascal.org/lazarus/lazarus/- /archive/main/lazarus-main.zip How do I install \components\packagetemplates" into the IDE? Ive got a clean install of 2.0.12 I overwrite c:\lazarus\components\packagetemplates with \components\packagetemplates from the zip I try to rebuild the IDE and get the error projtemplates.pas(11,3) Fatal: Cannot find LazarusPackageIntf used by ProjTemplates. Check if package FCL is in the dependencies of package ProjTemplates. ---------------------------------------------------------------------- JuhaManninen · 2021-12-19 12:22 Quote from: pcurtis on December 19, 2021, 12:00:23 pmHow do I install \components\packagetemplates" into the IDE? Ive got a clean install of 2.0.12 I understood you have it installed already. How could you test it otherwise? After replacing the packagetemplates directory, just rebuild the IDE. When you get a compilation error, first try a clean build. If it does not help, then you must build the trunk sources which I strongly recommend anyways. It is super easy. FPC being installed, just run "make" (*) and then start lazarus.exe from its location. No installation is needed. I am actually surprised you didn't try it during your 8+ years at this forum. (*) Delphi comes with its own incompatible "make". You must delete or rename it if you have Delphi. ---------------------------------------------------------------------- pcurtis · 2021-12-19 12:34 first must add FCL to project requirements, then it builds OK. Where do I set the project templates directory? ---------------------------------------------------------------------- JuhaManninen · 2021-12-19 12:37 Quote from: pcurtis on December 19, 2021, 01:34:19 pmWhere do I set the project templates directory? Tools -> Project templates options ... It should be moved under the global options window but that is not urgent. ---------------------------------------------------------------------- pcurtis · 2021-12-19 12:46 Menu not there ---------------------------------------------------------------------- pcurtis · 2021-12-19 12:57 Quote from: JuhaManninen on December 19, 2021, 01:22:51 pmI am actually surprised you didn't try it during your 8+ years at this forum. My iPad still has iOS 7. I'm not a person who must have the latest version. Just prefer a working version. ---------------------------------------------------------------------- dbannon · 2021-12-19 13:09 Quote from: pcurtis on December 19, 2021, 01:46:15 pmMenu not there Hmm, did you build with "bigide" ?  If not, you can easily add it as a package, Package->Install/Uninstall and find "ProjTemplates 1.0" on the right hand side, select it, click "Install Selection" and do the rebuild thing. Davo ---------------------------------------------------------------------- JuhaManninen · 2021-12-19 13:33 Quote from: dbannon on December 19, 2021, 02:09:35 pmHmm, did you build with "bigide" ?  If not, you can easily add it as a package, Package->Install/Uninstall and find "ProjTemplates 1.0" on the right hand side, select it, click "Install Selection" and do the rebuild thing. Yes, that applies when building Lazarus trunk sources. I thought he is still building the old 2.0.12 with a new copy of ProjTemplates. ---------------------------------------------------------------------- pcurtis · 2021-12-19 13:39 I AM STILL USING 2.0.12 After doing what dbannon suggested I still dont get the menu item, and the package is installed. ---------------------------------------------------------------------- JuhaManninen · 2021-12-19 13:48 Quote from: pcurtis on December 19, 2021, 02:39:55 pmI AM STILL USING 2.0.12 After doing what dbannon suggested I still dont get the menu item, and the package is installed. There must be a change in the menu registration system. Don't know. Then you must build trunk sources (which I recommended many times). Quote from: pcurtis on December 19, 2021, 01:57:57 pmI'm not a person who must have the latest version. Just prefer a working version. That sounds funny after reading this whole forum thread. ---------------------------------------------------------------------- jamie · 2021-12-19 14:39 After reviewing your post here it seems you are looking to use lazarus in a controlled environment where you can selectively force a default base project.  Delphi has or had premade Dialog forms you could start with that had some buttons already on them and from there you could just add on to it.  Years I took and made a Project manager tool where as you can select premade base projects as new projects and force the programmer to fill in some basic needs like company info, date info etc.   In your case you could do the same, make a Project manager tool that would either select a new project from one of your own premade starters which would simply make a copy of all contents over to a new folder and then ask for a few details to fill in the blanks.  Also This same tool preps a project and configures which fields need to be filled in on first time around so that each time a new project is started using one of these starters, these fields get filled out. This is all GUI interface stuff.  The manager also allows you to simply start an existing project too of course. The manager from here on would simply start the IDE DEV system with the project to open on the command line , new or existing one..  Is this what you are looking for ? ---------------------------------------------------------------------- dbannon · 2021-12-19 23:40 Quote from: pcurtis on December 19, 2021, 02:39:55 pmI AM STILL USING 2.0.12 But you have established that version 2.0.12 does not do what you want. Its a released and therefore frozen product, its not going to change. You need to either use a version that might do what you want or do something different. As you mentioned earlier, its not rocket science. Davo EDIT: Actually, on my system, its is there on even 2.0.10 (I don't have ~12 installed). I suggest you try rebuilding your 2.0.12 with the bigide option, https://wiki.freepascal.org/Installing_Lazarus_on_Windo ws#Building_Lazarus clearly says - Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i make bigide That being said, Juha has said, again, pretty clearly, that this area of Lazarus will work better with trunk. I would believe him ... I have made, perhaps, 20 releases of tomboy-ng using trunk Lazarus. I have NEVER got into trouble doing so.   Davo ---------------------------------------------------------------------- pcurtis · 2021-12-20 08:20 I'm currently debugging the project templates code. I've nearly got what I want. I don't want to use an unofficial release. I'm not a hard core programmer, and find it hard to deal with new issues because of slight changes. I'll stick to what I know, and wait for the official release, plus while I'm delving into the IDE workings I'm learning. ---------------------------------------------------------------------- pcurtis · 2021-12-20 10:02 Ok, I've done it. Just a few changes and it works for me. idetemplateproject.pp comment out line 158   //FileReplaceText(fn+'.lpi',Desc.FTemplate.ProjectFile,Desc.FProject Name); frmtemplatevariables.pas add Sysutils to uses and change Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TProjectVariablesForm.FormCreate(Sender: TObject);begin  if not DirectoryExists('c:\lazarus\temp') then    // <- add this    MkDir('c:\lazarus\temp');                               // <- add this  Caption := STitle;  ProjNameLabel.Caption:= SNameforProject;  DEDestDirLabel.Caption:= SCreateinDir;  PDescription.Caption:= SThisProject;  ButtonPanel1.CancelButton.Caption:= SbtnCancel;  ButtonPanel1.OKButton.Caption:= SbtnOK;  DEDestDir.Text := 'c:\lazarus\temp';    // <- add this  EProjectName.Text := 'project1';    // <- add thisend; procedure TProjectVariablesForm.ProjectVariablesFormShow(Sender: TObject);begin  SGVariables.Cells[0,0]:=SVariable;  SGVariables.Cells[1,0]:=SValue;  SGVariables.Cells[2,0]:=SDescription;  SGVariables.cells[1, 1] := 'untMain';  // <- add thisend;