Recent

Author Topic: How to get at files that I've incorporated into a project...  (Read 438 times)

tfurnivall

  • Jr. Member
  • **
  • Posts: 87
How to get at files that I've incorporated into a project...
« on: December 07, 2025, 10:28:56 pm »
I want to create a new project to test the first iteration of my SDLTrace routine. Along the way I really munged up the files in the project, my very definitely bad!

However,

I have a form that I'd like to use - and in which I've invested a lot of time. So,
1)  Create a new project - comes complete with a form (not much of a form, but I know where I can find a better one)
2)  I add the .frm and .pas of the nice form (which I shall call <newform>) from my not-so-nice attempt, using Project Inspector.

what I want to do now is:

Somehow open up the copied in form and either
a) Rename the files so that <badform>.frm and <badform>.pas now get named <newform>/frm and <newform>.pas
or
b) Copy the controls off <badform> into <newform>

(Admission - I didn't think of option a) until I was typing it just now. I'll try it and see...)

No luck - Lazarus is protecting me from my attempt at perverting the natural course of software development.

And I can't use option b), because I can't get <badform>.frm to open and show me a form.

A long time ago, and in another environment, I could open as many forms as I liked and copy controls between them. All forms could be 'opened' and would display both the graphical part of the form (equivalent to a realized instance of *.frm), and, if I wanted it, the code. It seems that with Lazarus I can't have more than one form per project open to editing and changing.

I know this can't be true, but how do I bring another form into the IDE so I can copy controls from FormA into FormB.

Tony

PS And to repeat an earlier plaint - is there anywhere a good description of what the IDE does and doesn't do, and how it works and doesn't work, written in English (rather than code)?



Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12031
  • Debugger - SynEdit - and more
    • wiki
Re: How to get at files that I've incorporated into a project...
« Reply #1 on: December 07, 2025, 10:41:19 pm »
1) Backup (so you don't damage anything)

2) Revision control (better than backup)

3) Menu: Project > Publish Project.
That will create a copy of your project in a new folder.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12031
  • Debugger - SynEdit - and more
    • wiki
Re: How to get at files that I've incorporated into a project...
« Reply #2 on: December 07, 2025, 10:43:05 pm »
If you have to "recover" forms (lfm files).

You can edit them, but
- only if they are not open in the IDE
- if you closed the form, by doing "view form as lfm" => giving you the lfm in the editor (and then save and close the lfm editor before opening the form with F12 in design mode).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12031
  • Debugger - SynEdit - and more
    • wiki
Re: How to get at files that I've incorporated into a project...
« Reply #3 on: December 07, 2025, 10:47:18 pm »
The "frm" file should (if needed) get auto created.

The 2 files you need are the .pas and the .lfm file.

You can copy them, and rename them outside the IDE (and then all you need is to rename the "unit foo;" at the start of the Pascal code.

If you "import" them into a new project, you must make sure that
- all used units can be found (all required packages must be added)
- The IDE (codetools) can parse the entire source (if you edited it, you did not introduce syntax errors, that prevent the file from being understood by the IDE)


tfurnivall

  • Jr. Member
  • **
  • Posts: 87
Re: How to get at files that I've incorporated into a project...
« Reply #4 on: December 08, 2025, 12:17:19 am »
Thanks, Martin,

I took a walk to get riud of my frustration, and I have now (I hope) a clear) exposition of what I want.

In Lazarus, we have a Source Editor. This is a convenient way of modifying files that are made part of the project. Those files may well be removed from the project, but while they are "in" the project, we can use the Source Editor - with the MDI interface to manage the files. Including copying and pasting between files.

What I'd like to see is a Form Editor (with the necessary MDI interface) so that I can copy and paste between forms, even if one of them is subsequently removed from the project. All the examples deal with adding an existing form and retaining it. My existing form is in a pitiable state, but it still has some structure (and time investment on my part) that I'd like to copy out and transfer into the new form that gets created with a project.

I think that's it - allowing me to manage multiple forms within a project and copying and pasting between them.

Any thoughts?

Tony

PS Yes - copying and pasting text between source files is on order of magnitude less complex than copying and pasting controls onto a form. However, at first blush it seems to me that I'd need to be able to:

i) Copy control specifications - including the hierarchy (as far as I have included it in the copy).

ii) Copy Event Handlers - at least to some extent, particularly if there is boilerplate involved.

iii) Do all the work of incorporating it into the target form (this is the hidden IDE stuff that allows a name change to flow through the whole IDE environment).

I can understand if there is no such capability at present (if there is, how do I learn about it), but I think this would be a useful capability, especially when there are templates involved, rather than simple duplication of references to an existing form.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12031
  • Debugger - SynEdit - and more
    • wiki
Re: How to get at files that I've incorporated into a project...
« Reply #5 on: December 08, 2025, 12:29:47 am »
What I'd like to see is a Form Editor (with the necessary MDI interface) so that I can copy and paste between forms, even if one of them is subsequently removed from the project. All the examples deal with adding an existing form and retaining it. My existing form is in a pitiable state, but it still has some structure (and time investment on my part) that I'd like to copy out and transfer into the new form that gets created with a project.

For the interface, you can enable or disable "DockedFormEditor" - with Lazarus 4.n this in in Tools >Options > Docked From Editor.
If docked,each form editor will be with its Source editor.

As for copy and paste, what exactly does not work?

Select a component, e.g. a Panel and right click => select copy from the menu. Then right click the target (on the other form) and do "Paste" => the panel with all its children should appear.

It should also work with selecting multiple elements... But I must say, I have not used it much myself, so don't know all the details.


If you use the docked editor, and want source and target form both visible, then you need to open a 2nd source editor window. Right click the tab of the target unit (where it has the name, where you click to view the unit), and from the context menu "clone to new window".

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12031
  • Debugger - SynEdit - and more
    • wiki
Re: How to get at files that I've incorporated into a project...
« Reply #6 on: December 08, 2025, 12:33:32 am »
OK, done some testing. It doesn't copy any of the events. So that is missing.

Either recreate them, and then copy the code.
 
Or, right click each of the 2 forms "view as lfm", and then in the lfm find the events and copy them. And then copy the source too.
(Just the events, not the components, those are better copied as in my previous post / otherwise their declaration in the source is missing)

 

TinyPortal © 2005-2018