RAD development of a GUI application with two versions and a single code base lazarus / 21-General ---------------------------------------------------------------------- simone · 2024-10-02 10:31 I need to create a GUI application developed in RAD way, with a single code base, but having two versions, the first complete with all the functions, the second limited. The limited version, as a consequence, will not have some controls (menus, buttons, etc.) in its GUI. To achieve this result I obviously use conditional compilation, including different .lfm files depending on the version. To show my approach, consider an example of an application in which the full version has two buttons, while the reduced only one . Then I proceed as follows: file unit1.pas: 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;{$DEFINE Full} {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    {$IFNDEF Full}    Button2: TButton;    {$ENDIF}  private   public   end; var  Form1: TForm1; implementation {$IFDEF Full}  {$R unit1a.lfm}{$ELSE}  {$R unit1b.lfm}{$ENDIF}end.  file unit1a.lfm: 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 object Form1: TForm1  Left = 269  Height = 240  Top = 250  Width = 320  Caption = 'Form1'  ClientHeight = 240  ClientWidth = 320  LCLVersion = '3.0.0.3'  object Button1: TButton    Left = 67    Height = 25    Top = 39    Width = 75    Caption = 'Button1'    TabOrder = 0  end  object Button2: TButton    Left = 217    Height = 25    Top = 143    Width = 75    Caption = 'Button2'    TabOrder = 1  endend  file unit1b.lb: 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 object Form1: TForm1  Left = 269  Height = 240  Top = 250  Width = 320  Caption = 'Form1'  ClientHeight = 240  ClientWidth = 320  LCLVersion = '3.0.0.3'  object Button1: TButton    Left = 67    Height = 25    Top = 39    Width = 75    Caption = 'Button1'    TabOrder = 0  endend  The problem with this approach is that in the case of complex applications the code management becomes complicated. In case the controls were created at run time, it would be easy to use conditional compilation, but in case of RAD approach, how should I proceed? As in the example I showed or is there a better approach? Is it possible to use some kind of conditional compilation inside the .lfm files? Thanks. ---------------------------------------------------------------------- MarkMLl · 2024-10-02 10:45 The first thing I found myself wondering was whether frames could be usefully subclassed. I'm not sure that "(optionally) putting a frame inside another frame" would work because of the problem that the IDE has with instantiated frames. However a better idea might be to create "full fat" forms, then to have the optional controls removed when the form was first activated. At that point you would have to consider the extent to which the remaining controls adjusted to fill gaps, /but/ from a support POV you might be better always being able to say "the button at the bottom- middle of the form" irrespective of whether there were three buttons there or just two (with a gap). MarkMLl ---------------------------------------------------------------------- wp · 2024-10-02 11:36 I would do this by means of frames. This splits functional elements off into separate units and moves the related code away from the main form which otherwise would be difficult to maintain due to thousands of line of code. You can design the frames at designtime like any form, but you must insert them into their parent form (or frame) at runtime, otherwise the risk that you damage properties or events is too high. You man want to apply auto-sizing, aligning and/or anchoring to size/position the frames correctly. Look at the charteditor project in the TAChart demo folder, it works with lots of frames, even frames within frames. By all means, I would avoid a "full fat" form which, if I understand correctly, contains all elements and only the needed ones are visible. This would be very hard to design and to maintain. ---------------------------------------------------------------------- vfclists · 2024-10-02 18:56 You should consider getting creative with the object inspector component at runtime. What you do is: 1. Load the full fat form at runtime 2. Use the object inspector to disable the parts you don't want. 3. Save the resulting form to an LFM file. 4. Redesign the program to stream in the LFM with the desired state at runtime. I can't say I have tried this method yet, but I have a feeling it will work. The use of RTTI will probably help. Ask the experts. The previous answers should also help with this. ---------------------------------------------------------------------- Joanna · 2024-10-03 02:28 Putting things only used sometimes into frames should work ok , however you will want to create all the child controls  of frames at runtime. Yes it is possible to have nested frames, I used to do it all the time before I switched to custom controls. ---------------------------------------------------------------------- MarkMLl · 2024-10-03 06:07 Quote from: vfclists on October 02, 2024, 08:56:05 pm3. Save the resulting form to an LFM file. 4. Redesign the program to stream in the LFM with the desired state at runtime. I can't say I have tried this method yet, but I have a feeling it will work. The use of RTTI will probably help. Ask the experts. I'm uncomfortable with that. I've received Stern Warnings from the core team that some fairly Deep Magic happens when a form is created, and that it's best left to the code inserted by the IDE in the .lpr unit. MarkMLl ---------------------------------------------------------------------- af0815 · 2024-10-03 06:23 Working around by bypassing the way of working of the IDE will go wrong. One way, described here earlier, is to deactivate the components/ events by programm. Working with Frames at runtime (NOT designtime) is very good and it is no problem with frames in frames in frames... and also you can made parentframs and inherit to childs. This the same, you can do with normal forms. So you can made a frame with the basic functions and the child can be the fat version. The OOP can here help. But dont deal with changing the lfm's and it is not possible to use conditional compiling inside of the lfm resource.