Recent

Author Topic: How to insert a new Form with OI comtrol into an existing unit filled with code?  (Read 304 times)

jamie

  • Hero Member
  • *****
  • Posts: 1990
I would like to know how to create a new form via the IDE where as the OI will design it, into an already existing unit filled with code?

 I may have asked this before but to me it shouldn't be that much of a deal for the IDE to do that upon request of making a new form which normally starts a new unit, I don't want to start a  new unit but use one that has lots of code already in it.

 I think I did this one before but I can't remember how?
 
 the form can have nothing on it, its not like I am trying to revive something.

Edit:

 I managed to do it but there must be a better way to do this?

 I created a lfm file, saved it in the project folder and the forms list saw the new entry however, it wasn't going to introduce a new form in the OI. I had to close the project and restart the project before it would then load the form, empty as it may at least it still a form the OI has control over..

 isn't there a way to insert an empty form into an existing unit and have the OI handle it using the IDE functions?

« Last Edit: August 28, 2019, 12:07:18 am by jamie »

TNoob

  • New member
  • *
  • Posts: 9
I'm not really qualified but this is my two cents:
If you declare TMyForm = class(TForm) end; in interface section, add {$R *.lfm} in implementation, and provide the namesake .lfm with object MyForm: TMyForm / end (on two lines) inside, I *think* the IDE will pick it up (did not try it).
But the way I'd go about it (if you really need to) is, backup your existing unit, create the new form in the IDE with the desired name, copy-paste code from the old unit to the new one.
Then again, I don't know what exactly you are doing but I guess you'd be better off simply using the existing 'code' unit in the new 'form' one, so that form-related code (mostly event handlers) is in one place and program logic (the existing unit) in another file.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 822
I would like to know how to create a new form via the IDE where as the OI will design it, into an already existing unit filled with code?
I may have asked this before but to me it shouldn't be that much of a deal for the IDE to do that upon request of making a new form which normally starts a new unit, I don't want to start a  new unit but use one that has lots of code already in it.
I think I did this one before but I can't remember how?
the form can have nothing on it, its not like I am trying to revive something.
I could not understand you well.
Do you have a PAS file missing its LFM file and want the IDE to build a basic LFM file so you could work on both on design time?

Quote
Edit:
I managed to do it but there must be a better way to do this?
I created a lfm file, saved it in the project folder and the forms list saw the new entry however, it wasn't going to introduce a new form in the OI. I had to close the project and restart the project before it would then load the form, empty as it may at least it still a form the OI has control over..
isn't there a way to insert an empty form into an existing unit and have the OI handle it using the IDE functions?
In this case, do you have a LFM file missing its PAS file and want the IDE to build a basic PAS file so you could work on both on design time?

Thausand

  • Full Member
  • ***
  • Posts: 234
In this case, do you have a LFM file missing its PAS file and want the IDE to build a basic PAS file so you could work on both on design time?
afaik no that is not what TS want.

Now when add new form with Object Inspector then designer always create new .pas unit and add TForm code in new .pas unit file.

I think TS want (design-time) so that Object Inspector add new (TForm) code be in existing .pas file that have many code in it already.

I have same problem many times before and then i make change for my self to solve: Now i separate UI and function and store function inside module or separate (no form) class. If is there some function and require detail form (example specialise dialog) then i make separate dialog (form) unit. But may be that is solution that no work for TS (*)

* if you have programmer that make all function first and make UI later then it difficult to add form and Object Inspector/Code Tools (?) force programmer to copy-paste all function to new (TForm) unit.


jamie

  • Hero Member
  • *****
  • Posts: 1990
Yes, Thausand's understands the problem .

 I just don't understand why there isn't a facility in the IDE to start a new form side an existing unit that doses not have a form ?

 I created a simple do nothing lfm file with the minimum in it, that refreshed the forms for my project but the OI didn't see it, I had to reopen the project for it to load for OI operations.

 Maybe If any of the Laz dev's are listening they can think or how's done already if there is a ready method in the IDE, otherwise maybe they could come up with a practical way to do this.