PageRenderTime 46ms CodeModel.GetById 17ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/components/datadict/frmselectcodegenerator.pp

http://github.com/graemeg/lazarus
Pascal | 101 lines | 75 code | 20 blank | 6 comment | 0 complexity | 2d26a070befd192f3a79d27cf83d9e30 MD5 | raw file
  1unit frmSelectCodeGenerator;
  2
  3{$mode objfpc}{$H+}
  4
  5interface
  6
  7uses
  8  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, fpddcodegen,
  9  ButtonPanel, ldd_consts;
 10
 11type
 12
 13  { TSelectCodeGeneratorForm }
 14
 15  TSelectCodeGeneratorForm = class(TForm)
 16    BPButtons: TButtonPanel;
 17    RGGenerators: TRadioGroup;
 18    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
 19    procedure FormCreate(Sender: TObject);
 20    procedure FormShow(Sender: TObject);
 21  private
 22    FHaveFields: Boolean;
 23    FHaveSQL: Boolean;
 24    FSelF: TCodeGeneratorItem;
 25    procedure ShowAvailableGenerators;
 26    { private declarations }
 27  public
 28    { public declarations }
 29    Property HaveSQL : Boolean Read FHaveSQL Write FHaveSQL;
 30    Property HaveFields : Boolean Read FHaveFields Write FHaveFields;
 31    Property SelectedGenerator : TCodeGeneratorItem Read FSelF Write FSelF;
 32  end; 
 33
 34var
 35  SelectCodeGeneratorForm: TSelectCodeGeneratorForm;
 36
 37implementation
 38
 39{$R *.lfm}
 40
 41{ TSelectCodeGeneratorForm }
 42
 43procedure TSelectCodeGeneratorForm.FormShow(Sender: TObject);
 44begin
 45  ShowAvailableGenerators;
 46end;
 47
 48procedure TSelectCodeGeneratorForm.FormClose(Sender: TObject;
 49  var CloseAction: TCloseAction);
 50begin
 51  If (ModalResult=mrOK) then
 52    With RGGenerators do
 53      FSelF:=Items.Objects[ItemIndex] as TCodeGeneratorItem;
 54end;
 55
 56procedure TSelectCodeGeneratorForm.FormCreate(Sender: TObject);
 57begin
 58  Caption := ldd_Selectcodetobegenerated;
 59  RGGenerators.Caption:= ldd_Availablecodegenerators;
 60end;
 61
 62procedure TSelectCodeGeneratorForm.ShowAvailableGenerators;
 63
 64  Function AllowGenerator(G : TCodeGeneratorItem) : Boolean;
 65  
 66  begin
 67    Result:=True;
 68    If G.GeneratorClass.NeedsSQL then
 69      Result:=HaveSQL;
 70    If Result then
 71      If G.GeneratorClass.NeedsFieldDefs then
 72        Result:=HaveFields;
 73  end;
 74
 75Var
 76  I,J: Integer;
 77  G : TCodeGeneratorItem;
 78
 79begin
 80  RGGenerators.Items.Clear;
 81  J:=-1;
 82  For I:=0 to CodeGenerators.Count-1 do
 83    begin
 84    G:=CodeGenerators[i];
 85    If AllowGenerator(G) then
 86      begin
 87      RGGenerators.Items.AddObject(G.Description,G);
 88      If (G=FSelF) then
 89        J:=I;
 90      end;
 91    end;
 92  With RGGenerators do
 93    If (J<>-1) then
 94      ItemIndex:=Items.IndexOfObject(CodeGenerators[J])
 95    else
 96      If Items.Count>0 then
 97        ItemIndex:=0;
 98end;
 99
100end.
101