How to do bulk -transformation of form to frame- in Delphi?
Asked Answered
S

3

6

I have a form with aprox with 200 visual components on it, with a lot of events assigned, and I need to change it now to a frame.I don't have enough time to copy all the components,re-arrange all the visual components and re-assign all the events, align, etc. So, I've copied the pas and the dfm, opened and start to edit them in a text editor(change TForm to Tframe, etc) but it seems that this don't get the expected results.

Has anyone an idea on how to solve this?

Selection answered 27/1, 2011 at 9:43 Comment(5)
When I last did this it worked. Can you elaborate on precisely what goes wrong?Autoerotism
what is your problem? I take a .pas and .dfm, do a global replace of form to frame; fix the "uses" clause; remove all form properties from dfm; and everything is alright to me. Please debug down to single problems.Maestricht
Also, make sure you copy the variables into the class definition. Things behave oddly when this is not done.Halette
Re-arranging will only be necessary if your frame initially is smaller than the form from which you are copying the components. Make sure your frame has the same (design time) dimensions as the form and a select all, copy, paste should work just fine in the IDE.Core
Marjan, if I make a copy-paste all the events assigned will be deleted, no?Selection
G
9

Observe the differences of a Form and a Frame in your project.

First the project.dpr source:

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit3 in 'Unit3.pas' {Frame3: TFrame};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Differences:

  1. Frame as a more elaborated comment to tell the IDE which designer it should use
  2. Form can be autocreate

Dfm files:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 348
  ClientWidth = 643
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
end

and

object Frame3: TFrame3
  Left = 0
  Top = 0
  Width = 320
  Height = 240
  TabOrder = 0
end

Frame does not have these properties:

  • Caption
  • ClientHeight
  • ClientWidth
  • Color
  • Font.Charset
  • Font.Color
  • Font.Height
  • Font.Name
  • Font.Style
  • OldCreateOrder
  • PixelsPerInch
  • TextHeight

Sidenote: Frame does not have these events:

  • OnCreate
  • OnDestroy

A Frame has not global variable like this:

var
  Form1: TForm1;

And a Frame descends from TFrame, whereas a form descends from TForm.

Note: with Frame/Form inheritence, your steps become a bit longer.

--jeroen

Giesser answered 27/1, 2011 at 11:8 Comment(2)
First I wanted to flag the question for deletion(because I was in a hurry and didn't observed my mistake with file's name mismatch), but after you answer, I believe someone will learn from it.Selection
Thanks; these seemingly simple changes can backfire really badly if not done 100% properly :-)Giesser
F
2

TForm will have additional properties and events which TFrame wont have. You need to remove those properties and events manually to change to form to frame.

Be sure to followed these steps;

  1. Change base class type to TFrame i.e., change TForm1 = class(TForm) to TForm1 = class(TFrame).
  2. On the Form, Right click and Select View as Text option.
  3. Remove the properties and events that TFrame doesn't have and then select View as Form option.
  4. Now you should be able to view the form as frame.
Fleury answered 27/1, 2011 at 10:2 Comment(1)
that's what i did, but i changed by mistake the name of the dfm file and it was a mismatch between. +1. thank youSelection
D
0

Take time to develop once and for all an IDE expert doing the bulk operation if there is not any working out of the box (proprietary/open source) and you are done.

Doublepark answered 13/1, 2012 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.