Solved

How to do Delphi 7 Frames.

Posted on 2010-08-28
9
3,488 Views
Last Modified: 2013-11-11
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.
0
Comment
Question by:IT79637
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Accepted Solution

by:
systan earned 144 total points
ID: 33551372
try that;
frametest1.zip
0
 
LVL 14

Assisted Solution

by:systan
systan earned 144 total points
ID: 33551383
>>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
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 143 total points
ID: 33551754
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 143 total points
ID: 33551852
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
 
LVL 13

Assisted Solution

by:aflarin
aflarin earned 142 total points
ID: 33551941
>> 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
 
LVL 13

Assisted Solution

by:aflarin
aflarin earned 142 total points
ID: 33551969
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
 
LVL 13

Assisted Solution

by:rfwoolf
rfwoolf earned 71 total points
ID: 33552700
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
 
LVL 1

Author Comment

by:IT79637
ID: 33712105
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
 
LVL 1

Author Comment

by:IT79637
ID: 33712113
Found solution in Delphi help.  See above.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question