How to do Delphi 7 Frames.

Hi,
I'm on a WinXP Pro, SP3 using Delphi 7.

I have a fundamental problem starting a new Frame project/program from scratch.

In the IDE, I do:
1.  File, New, Frame.  The unit and frame are displayed.  
2.  Drop  Button1 and  Edit1 on the form.
3.  Double click Button1 and add "Close;" between the "begin" and "end;"  .
4.  Save the code as Unti1.pas.
5. In the project directory, I have two files: Unit1.dfm and Unit1.pas.

Here is what I don't understand:

1.  Why can't I create a Project (dpr) file?   I can't do a File, Save Project As...  because it is grayed out.
2.  Why is the  green "|>" Run button grayed out?

I thought I could save a Frame as a Project and I obviously need to use the "Run" button to compile the code.

What am I fundamentally misunderstanding about Delphi Frames and Projects?


Thanks.
LVL 1
IT79637Asked:
Who is Participating?
 
systanConnect With a Mentor Commented:
try that;
frametest1.zip
0
 
systanConnect With a Mentor Commented:
>>4.  Save the code as Unti1.pas.
Wrong!
Save the code as Unit2.pas
Because Unit1 is Form1 and Unit1.pas

When you Save the frame, it will named as unit2.pas, because there is a unit1.pas already which is the form1

See the frametest code I attached
0
 
Geert GConnect With a Mentor Oracle dbaCommented:
you need to look at a frame as a jigsaw piece
the jigsaw would be the form

you can't save a frame as a project
but you can save a frame as a unit inside a project
a frame can be totally standalone
-> but you can't compile this, you need a project around this

there are a few issues with frames and inheritance
editing a frame after you put it on a form may cause some odd behaviour
mostly there is a problem with a mix of default and non-default property values

the best approach is to put a frame on the form at runtime to prevent this problem

to save frames, i would first create a new standard vcl application
and save them in that application
in my apps, i have a common folder for this
this is sample of my dir structure
development directory : c:\company\dev =dev
delpi structure
dev\general\report
dev\general\label
dev\common\utils
dev\common\frames
dev\test\projectFrames
dev\quickstep\tools\client
dev\quickstep\tools\server

now why this structure ?
well are you going to use frames in different projects ?
probably ...

* then the very first concern is to make sure you don't use units inside your frames of other forms
in my structure from the dir common\frames i can use any unit from common\utils, but not from the general or quickstep dirs
this is the first basic concept for sharing frames amongst projects

after creating a new project (inside dev\test\prjFrames)
add a new frame
and save it in the common\frames
i usually give my units a relevant name -> fraFileList
i would show a frame with a listbox to select a file from

then use this frame in 2 different units

you can add a frame to the component pallet - right click on the frame and click *add to palette*
then it's just like a component to put on your form
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Geert GConnect With a Mentor Oracle dbaCommented:
this is a sample of that frame listing the files with a extension in a directory

and this is my test unit1 code:

always use a distinct name when adding frames to your form
unit uMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TfrmMain = class(TForm)
    BitBtn1: TBitBtn;
    Panel1: TPanel;
    Memo1: TMemo;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

uses frameFiles;

{$R *.dfm}

procedure TfrmMain.BitBtn1Click(Sender: TObject);
var fra: TfraFiles;
begin
  fra := TfraFiles(FindComponent('fraFilesTxt'));
  if fra <> nil then
    fra.Free;
  fra := TfraFiles.Create(Self);
  fra.Parent := panel1;
  fra.Align := alClient;
  fra.BeginUpdate;
  try
    fra.Folder := 'c:\data';
    fra.Ext := '.TXT';
  finally
    fra.EndUpdate;
  end;
  fra.Name := 'fraFilesTxt';
end;

procedure TfrmMain.BitBtn2Click(Sender: TObject);
var fra: TfraFiles;
begin
  fra := TfraFiles(FindComponent('fraFilesTxt'));
  if Assigned(fra) then
  begin
    fra.SelectedFiles(memo1.Lines);
  end;
end;

end.

Open in new window

frameFiles.pas
frameFiles.dfm
0
 
aflarinConnect With a Mentor Commented:
>> 1.  Why can't I create a Project (dpr) file?   I can't do a File, Save Project As...  because it is grayed out.

To create an empty project use File, New, Application. It creates a new project and a new form

>> 2.  Why is the  green "|>" Run button grayed out?

Only projects can be run. You can't run Frames, Forms and other units if they are not included into  project

>> I thought I could save a Frame as a Project and I obviously need to use the "Run" button to compile the code.

You can create a new Project and a new Frame into this project. Then you can save the project (.dpr) and the frame (.pas and .dfm)

>> What am I fundamentally misunderstanding about Delphi Frames and Projects?

Im afraid you confuse Frames and Forms. Usually the simplest Delphi project consists of project unit (.dpr file) and main Form (.pas and .dfm files). You can create the simplest project via File, New, Application

The frames are not used as separate windows, they are used as part of forms.

So, I suppose you need to do :

1.  File, New, Application.  The unit and form are displayed.  
2.  Drop  Button1 and  Edit1 on the form.
3.  Double click Button1 and add "Close;" between the "begin" and "end;"  .
4.  File, Save All. Save the project as Project1, save the code as Unti1.pas.
5. In the project directory, you have three files: Project1.dpr, Unit1.dfm and Unit1.pas.
6. click Run

0
 
aflarinConnect With a Mentor Commented:
If you want to create exactly the Frame, then:

1. File, New, Application.  The unit and form are displayed.  
2. File, New, Frame, The second unit and form are displayed. It's a Frame
3. Drop  Button1 and  Edit1 on the Frame form.
4. Double click Button1 and add "Close;" between the "begin" and "end;"  .
5. Switch to form (the first frame).
6. Drop Frames from the Standard palette to the Form. The frame select dialog will be displayed. Select the Frame1 and click OK
7.  File, Save All. Save the project as Project1, save the form as Unti1.pas and save the frame as Unit2
8. In the project directory, you have 5th files: Project1.dpr, Unit1.dfm and Unit1.pas, Unit2.dfm and Unit2.pas.
9. click Run
0
 
rfwoolfConnect With a Mentor Commented:
In short... when you start Delphi from scratch and close the default new project, and then say New -> Frame, you are not creating a project, you are only creating a frame.
Perhaps what you're looking for is to say New Project, and THEN, say New Frame.
0
 
IT79637Author Commented:
Found out how to create a Frame Project in the help section under the Find tab.

See image below.

When you open the "Create frames" in step three, the following text can be found:

"If you want to create a project that contains only frames and no forms, choose File|New| Application, close the new form and unit without saving them, then choose File|New|Frame and save the project."
DelphiFrame2.jpg
0
 
IT79637Author Commented:
Found solution in Delphi help.  See above.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.