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: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: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
end
end
file unit1b.lb: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
end
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.