Forum > Designer

Changing a property in entire project

(1/1)

ramutau:
Hi all,

I have several grids that I have copied from one project to another.

The have a lot of DBEdit components on them, and the datasource in all are now blank.

Is there a way I an 'find and replace' the content of the datasource property without having to manually select each one?

Many thanks

howardpc:
It's not recommended to change an .lfm 'outside' of the IDE, but the following could work.
Declare a private procedure in the form's declaration, and call it in the form's OnCreate as follows.
Once you've run the procedure once, remove the call from the OnCreate, close Lazarus and reopen the project.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin  AddSourceToAllDBEditsInLFM('unit1.lfm', DataSource1); // change this to suit your caseend; procedure TForm1.AddSourceToAllDBEditsInLFM(const anLFM: string;  aDatasource: TDataSource);var  sl, slNew: TStringList;  s: String;   function IsDBEditDefinition(aLine: string): Boolean;  begin    aLine:=Trim(aLine);    Exit((Copy(aLine, 1, 6)='object') and (Copy(aLine, Length(aLine)-6, 7)='TDBEdit'));  end; begin  sl:=TStringList.Create;  slNew:=TStringList.Create;  try    sl.LoadFromFile(anLFM);    for s in sl do begin      slNew.Add(s);      if IsDBEditDefinition(s) then        slNew.Add('    Datasource = ' + aDatasource.Name);    end;    slNew.SaveToFile(anLFM);  finally    sl.Free;    slNew.Free;  end;end;

Navigation

[0] Message Index

Go to full version