Auto create data controls based on fields editor lazarus / 6-IDE-CodeTools ---------------------------------------------------------------------- cybervoigt · 2008-07-24 13:48 Hi, I´ve been working with Borland Delphi since 2000 year, and Borland Delphi 7 Product Certified since 2005, but never did "migrate" to the .NET framework. I´ve been studing the Lazarus since I knew it, and now I think it´s time to contribute to the project. In my first experience with Lazarus, introducing it to a "partner", we missed a very useful Delphi IDE´s feature: data controls auto creation by drag and drop fields from the Fields Editor to a form. Analyzing the Lazarus IDE´s source code, i have found the fieldseditor.pas unit and noticed this implementation is possible. :-) What do you suggest? I´m thinking to do this implementation by myself and hopefully start contributing to the project. Regards, Ricardo Voigt ---------------------------------------------------------------------- cybervoigt · 2008-07-29 20:29 Hi, I want to continue with this topic, sharing some initial code mde by me. This code add the IDE feature of Data controls autocreation based on a Fields Editor´s TSQLQuery component owned by a TForm. First, yout need to add a new action (and a new MenuItem) on the Fields Editor source code (/lazarus/ideintf/fieldseditor.pas) with this code (under) on the OnExecute event. After that, rebuild Lazarus (menu Tools / Build Lazarus). Now is possible auto create the data controls on a Form (including the DataSource) selecting all fields and clicking on this new menu item (but it does not work yet when the TDataset is on a DataModule). Code: [Select]   function findDTS(frm: TCustomForm): TDataSource;   var     i : Integer;     found : Boolean;     tmpDts : TDataSource;   begin     i := 0;     found := False;     tmpDts := nil;     while (i <= frm.ComponentCount-1) and (not found) do begin           if (frm.Components[i] is TDataSource) then         tmpDts := TDataSource(frm.Components[i])       else         tmpDts := nil;       if Assigned(tmpDts) and (tmpDts.DataSet = Self.LinkDataset) then         found := True       else         inc(i);     end;         if (not found) then begin       tmpDts := TDataSource.Create(frm);//LinkDataset.Owner);       tmpDts.Name := FDesigner.CreateUniqueComponentName('DataSource');       tmpDts.DataSet := Self.LinkDataset;       Self.FDesigner.PropertyEditorHook.PersistentAdded( tmpDts, false);     end;         Result := tmpDts;   end; var   i,y : integer;   fld : TField;   dts : TDataSource;   lbl : TLabel;   edt : TDBEdit; begin   if (Self.FieldsListBox.SelCount > 0) and     (not Self.FDesigner.Form.ClassNameIs('TNonControlDesignerForm')) then begin     dts := findDTS(Self.FDesigner.Form);     if Assigned(dts) then begin       y := 8;       for i := 0 to FieldsListBox.Items.Count - 1 do begin         if FieldsListBox.Selected[i] and           (LinkDataset.FindField(FieldsListBox.Items[i]) <> nil) then begin           fld := LinkDataset.FieldByName(FieldsListBox.Items[i]);           // TLabel           lbl := TLabel.Create(Self.FDesigner.Form);           lbl.Parent := Self.FDesigner.Form;           lbl.Name:= FDesigner.CreateUniqueComponentName('Label');           lbl.Caption:= fld.DisplayLabel;           lbl.Left := 8;           lbl.Top := y + 8;           y := lbl.Top + lbl.Height;           Self.FDesigner.PropertyEditorHook.PersistentAdded( lbl, false);           // TDBEdit           edt := TDBEdit.Create(Self.FDesigner.Form);           edt.Parent := Self.FDesigner.Form;           edt.Name := FDesigner.CreateUniqueComponentName('DBEdit');           edt.Left :=8;           edt.Top := y;           y := edt.Top + edt.Height;           if (fld.DataType = ftString) then             edt.Width:= 10 + (fld.Size * 10);           edt.DataSource := dts;           edt.DataField:= fld.FieldName;           Self.FDesigner.PropertyEditorHook.PersistentAdded( edt, false);         end;       end; //for     end;     SelectionChanged;   end; end; So, i hope someone can help to continue and grow up this (RAD) ideia...