Question

Why is this not working (frames) ???

Asked by: senad

Two panels on a form.On panel1 two buttons-panel2 is for showing frames:
The code:

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, dxsbar, dxGDIPlusClasses, ImgList, StdCtrls;
type
TFrames = (Frame2, Frame3);
    TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
  Frame2, Frame3 : TFrame;
  fActiveFrame: TFrames;
  procedure SetActiveFrame(const Value: TFrames);
  { Private declarations }
  public
  property ActiveFrame : TFrames read fActiveFrame write SetActiveFrame;
 { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
Uses Unit2,Unit3;
procedure TForm1.SetActiveFrame(const Value: TFrames);
var
  LastFrame : TFrames;
 begin
  if fActiveFrame <> Value then
    begin
      LastFrame := fActiveFrame;
      fActiveFrame := Value;
            case LastFrame of
        Frame2 : Frame2.Parent := nil;
        Frame3 : Frame3.Parent := nil;
      end;
      case fActiveFrame of
        Frame2 : Frame2.Parent := Panel2;
        Frame3 : Frame3.Parent := Panel2;
      end;
    end;
    end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Frame2 := TFrame.Create(nil);
Frame3 := TFrame.Create(nil);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(Frame2);
FreeAndNil(Frame3);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ActiveFrame := Frame2;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ActiveFrame := Frame3;
end;
end.


I get :
[Error] Unit1.pas(51): Constant expression expected
[Error] Unit1.pas(81): Incompatible types: 'TFrames' and 'TFrame'

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-11-03 at 23:26:32ID23873447
Topic

Delphi Programming

Participating Experts
3
Points
225
Comments
40

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Add my property to TForm
    i would like to add my property to TForm properties page, can i and how ? Please give an example code here..
  2. TWinControl <-> TForm
    Hello there, The question is - what makes TWinControl behave as TCustomForm? I.e. what should be done to make TWinControl (TCustomControl) descendant act as TCustomForm (TForm). I.e. it must be popup window (come without Parent assigned) and at the same time it should accept...
  3. DFM is needed for final package. Workaround?
    I'm using Delphi 7. I've created a component which has a form, and compiled/installed the component with all debugging options turned off. After installing, I removed the component's source files, and tried to use that component, but Delphi said the DFM file is missing. Why d...
  4. Constructor on TObject descendant
    The cReate for a TObject descendant is not getting fired, in fact it's not trecognised by the complier (no blue dots). here's some sample code. What have I done wrong? Thanks, Tom. TOne = class(TObject) private protected public published end; TTwo = class(TO...
  5. Examining TObjects
    Hello, I'm (temporarily) coding in delphi 6 and using the Borland Delphi Enterprise IDE. In php we have a function called print_r() that will display the contents of a nested array in an easily understandable manner. In the current project I have a TStringList object with ...
  6. SAVE EVENTS IN TEXT DFM FILES
    SAVE EVENTS IN TEXT DFM FILES To save TForm or TComponent with 1 or more components on it I have to use insertcomponent and removecomponent to set owner. But how to save EVENTS because they don't appear on saved files. Is there some kind of mistake that I did or is some meth...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Geert_GruwezPosted on 2008-11-03 at 23:32:09ID: 22874125

try this

ps you don't need to declare TFrames

just fActiveFrame: TFrame;

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, dxsbar, dxGDIPlusClasses, ImgList, StdCtrls;
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Frame2: TFrame;
    Frame3: TFrame;
    fActiveFrame: TFrame;
    procedure SetActiveFrame(const Value: TFrame);
  public
    property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
Uses Unit2,Unit3;
procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrames;
begin
  if fActiveFrame <> Value then
  begin
    LastFrame := fActiveFrame;
    fActiveFrame := Value;
    LastFrame.Parent := nil;
    fActiveFrame.Parent := Panel2;
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame.Create(nil);
  Frame3 := TFrame.Create(nil);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Frame2);
  FreeAndNil(Frame3);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
ActiveFrame := Frame2;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ActiveFrame := Frame3;
end;
end.

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:

Select allOpen in new window

 

by: mokulePosted on 2008-11-03 at 23:48:55ID: 22874188

no const needed here I think
procedure SetActiveFrame(const Value: TFrame);

 

by: Geert_GruwezPosted on 2008-11-03 at 23:51:02ID: 22874199

that line is created automaticly by Delphi after hitting Ctrl-Shift C with class completion

 

by: mikelittlewoodPosted on 2008-11-04 at 01:08:23ID: 22874524

Always wonder why delphi does that because it is strictly incorrect.

 

by: Geert_GruwezPosted on 2008-11-04 at 10:05:04ID: 22878759

i believe it's for the interfaces
when you pass a interface to a procedure and don't use const
the interface gets nil'ed

so they got lazey and added const to every property getter/setter

 

by: senadPosted on 2008-11-05 at 08:50:51ID: 22887251

Geert_Gruwez:
I copy&pasted your example and  compiler gave me error:
[Error] Unit1.pas(32): Undeclared identifier: 'TFrames'
[Error] Unit1.pas(38): Missing operator or semicolon
[Fatal Error] Project1.dpr(7): Could not compile used unit 'Unit1.pas'


It stopped on :
procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrames;  ..........

 

by: mokulePosted on 2008-11-05 at 10:02:49ID: 22888035

should be
var
  LastFrame : TFrame;

 

by: senadPosted on 2008-11-05 at 20:17:23ID: 22892331

Mokule
I got a nasty crash (debugger notification) on compiling this one.
 It died on :
 LastFrame.Parent := nil;

The code:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, dxsbar, dxGDIPlusClasses, ImgList, StdCtrls;
type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Frame2: TFrame;
    Frame3: TFrame;
    fActiveFrame: TFrame;
    procedure SetActiveFrame(const Value: TFrame);
  public
    property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}

Uses Unit2,Unit3;

procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  if fActiveFrame <> Value then
  begin
    LastFrame := fActiveFrame;
    fActiveFrame := Value;
    LastFrame.Parent := nil;
    fActiveFrame.Parent := Panel2;
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame.Create(nil);
  Frame3 := TFrame.Create(nil);
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Frame2);
  FreeAndNil(Frame3);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
ActiveFrame := Frame2;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ActiveFrame := Frame3;
end;
end.

 

by: Geert_GruwezPosted on 2008-11-05 at 21:14:19ID: 22892507

procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  if fActiveFrame <> Value then
  begin
    LastFrame := fActiveFrame;
    fActiveFrame := Value;
    if LastFrame <> nil then
      LastFrame.Parent := nil;
    fActiveFrame.Parent := Panel2;
  end;
end;

 

by: Geert_GruwezPosted on 2008-11-05 at 21:16:04ID: 22892511

probably this too:

procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  if fActiveFrame <> Value then
  begin
    LastFrame := fActiveFrame;
    fActiveFrame := Value;
    if LastFrame <> nil then
      LastFrame.Parent := nil;
    if fActiveFrame <> nil then
      fActiveFrame.Parent := Panel2;
  end;
end;

 

by: Geert_GruwezPosted on 2008-11-05 at 21:16:51ID: 22892514

this is the same behaviour you want as ActiveControl
the form which has focus is in ActiveControl

 

by: senadPosted on 2008-11-05 at 22:43:33ID: 22892766

Frames not showing !?

 

by: Geert_GruwezPosted on 2008-11-06 at 01:21:10ID: 22893294

Frames not showing ?!

would you care to explain ?
somehow there are some more lines missing with more clarification as what you mean :)

 

by: senadPosted on 2008-11-06 at 02:18:06ID: 22893536

Clicking on the either button does not display the frame.
If I click button one ,there should be Frame2 showing on Panel2.
If I click button two ,there should be Frame3 showing on Panel2.
It does not do anything now :-)


 

by: Geert_GruwezPosted on 2008-11-06 at 02:20:22ID: 22893543

what about not checking for
fActiveFrame <> Value

procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  LastFrame := fActiveFrame;
  fActiveFrame := Value;
  if LastFrame <> nil then
    LastFrame.Parent := nil;
  if fActiveFrame <> nil then
    fActiveFrame.Parent := Panel2;
end;

 

by: Geert_GruwezPosted on 2008-11-06 at 02:21:42ID: 22893547

and why not

procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame.Create(Self);
  Frame3 := TFrame.Create(Self);
end;

 

by: Geert_GruwezPosted on 2008-11-06 at 02:22:21ID: 22893552

the you can delete

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FreeAndNil(Frame2);
  FreeAndNil(Frame3);
end;

 

by: senadPosted on 2008-11-06 at 05:38:22ID: 22894770

Did you try and compile this?
Please try and let me know if it works for you...
To me it does not.

 

by: Geert_GruwezPosted on 2008-11-06 at 07:20:22ID: 22895884

I typed this in the browser
never opened Delphi to create this

i'll do it now :D

 

by: Geert_GruwezPosted on 2008-11-06 at 07:31:28ID: 22896036

I recreated an example of this myself

started from scratch
the result is in the snippet :

the differences you still need for your code
is that you are using TFrame
and none of the descendants you created in Unit2 and Unit3
you are displaying empty, clean, transparent frames !

procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame.Create(nil);
  Frame3 := TFrame.Create(nil);
end;

should be

procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame2.Create(Self);
  Frame3 := TFrame3.Create(Self);
end;

if the frames are called TFrame2 and TFrame3 off course !

I thought you were still going to adjust this
I guessed wrong

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    fActiveFrame: TFrame;
    fFrame2: TFrame;
    fFrame3: TFrame;
    function GetFrame2: TFrame;
    function GetFrame3: TFrame;
    procedure SetActiveFrame(const Value: TFrame);
  public
    constructor Create(AOwner: TComponent); override;
    property DisplayFrame2: TFrame read GetFrame2;
    property DisplayFrame3: TFrame read GetFrame3;
    property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
 
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
{ TForm1 }
 
constructor TForm1.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fActiveFrame := nil;
  fFrame2 := nil;
  fFrame3 := nil;
end;
 
function TForm1.GetFrame2: TFrame;
begin
  if not Assigned(fFrame2) then
  begin
    fFrame2 := TFrame.Create(Self);
    fFrame2.Color := clGreen;
  end;
  Result := fFrame2;
end;
 
function TForm1.GetFrame3: TFrame;
begin
  if not Assigned(fFrame3) then
  begin
    fFrame3 := TFrame.Create(Self);
    fFrame3.Color := clRed;
    fFrame3.Align := alClient;
    with TLabel.Create(fFrame3) do
    begin
      Caption := 'Frame3';
      Top := 20;
      Left := 20;
      Parent := fFrame3;
    end;
  end;
  Result := fFrame3;
end;
 
procedure TForm1.SetActiveFrame(const Value: TFrame);
var LastFrame: TFrame;
begin
  LastFrame := fActiveFrame;
  if Assigned(LastFrame) then
    LastFrame.Parent := nil;
  fActiveFrame := Value;
  if Assigned(fActiveFrame) then
    fActiveFrame.Parent := Panel1;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ActiveFrame := DisplayFrame2;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
  ActiveFrame := DisplayFrame3;
end;
 
end.
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:

Select allOpen in new window

 

by: Geert_GruwezPosted on 2008-11-06 at 07:35:46ID: 22896088

why my own example ?

yours wouldn't compile as I don't have all DevExpress modules
in particular dxGDIPlusClasses

 

by: senadPosted on 2008-11-06 at 20:24:01ID: 22901942

Nothing from devexpress here...Two panels,two frames and two butttons...
dx.. was a leftover and was taken out.

 

by: senadPosted on 2008-11-06 at 20:49:35ID: 22901997

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
fActiveFrame: TFrame;
Frame2: TFrame;
Frame3: TFrame;
function GetFrame2: TFrame;
function GetFrame3: TFrame;
procedure SetActiveFrame(const Value: TFrame);
public
constructor Create(AOwner: TComponent); override;
property DisplayFrame2: TFrame read GetFrame2;
property DisplayFrame3: TFrame read GetFrame3;
property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fActiveFrame := nil;
Frame2 := nil;
Frame3 := nil;
end;

function TForm1.GetFrame2: TFrame;
begin
if not Assigned(Frame2) then
begin
Frame2 := TFrame.Create(Self);
Frame2.Color := clGreen;
Frame2.Align := alClient;
end;
Result := Frame2;
end;

function TForm1.GetFrame3: TFrame;
begin
if not Assigned(Frame3) then
begin
Frame3 := TFrame.Create(Self);
Frame3.Color := clRed;
Frame3.Align := alClient;
end;
Result := Frame3;
end;

procedure TForm1.SetActiveFrame(const Value: TFrame);
var LastFrame: TFrame;
begin
LastFrame := fActiveFrame;
if Assigned(LastFrame) then
LastFrame.Parent := nil;
fActiveFrame := Value;
if Assigned(fActiveFrame) then
fActiveFrame.Parent := Panel1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ActiveFrame := DisplayFrame2;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ActiveFrame := DisplayFrame3;
end;

end.

Why do you see a flicker of white on panel1 when clicking buttons??

"and none of the descendants you created in Unit2 and Unit3
you are displaying empty, clean, transparent frames !"

correct but >
procedure TForm1.FormCreate(Sender: TObject);
begin
 Frame2 := TFrame2.Create(Self);
 Frame3 := TFrame3.Create(Self);
end;
does not do the trick... So what should the code (myone)be?

Little tiring doing functions for each frame...

 

by: Geert_GruwezPosted on 2008-11-06 at 23:39:19ID: 22902416

Little tiring doing functions for each frame... ?
Then stop programming !
Have you ever condisdered resources like memory ?
If nobody ever pushes Button2 in my example then TFrame3 never gets created (or memory consumed)
But then again, why would you care, you're too tired !
Programming is not only typing (or copy/paste) some text, it's an art !

It's delving in to problems, finding how it works, looking up solutions, reading the help.
And not giving up.

I copied your example and everything works fine !
Have you looked at every piece of code carefully ?
Didn't you miss a single character ?

If you want to see with your own eyes then come over here at my desk and check
I'll even add a screen shot and the whole code, dfm's included, using your example

May the source be with you
Cause i'm nearly giving up

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Panel2: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Frame2: TFrame;
    Frame3: TFrame;
    fActiveFrame: TFrame;
    procedure SetActiveFrame(const Value: TFrame);
  public
    property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
Uses Unit2,Unit3;
 
procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  LastFrame := fActiveFrame;
  fActiveFrame := Value;
  if Assigned(LastFrame) then
    LastFrame.Parent := nil;
  if Assigned(fActiveFrame) then
    fActiveFrame.Parent := Panel2;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame2.Create(Self);
  Frame3 := TFrame3.Create(Self);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ActiveFrame := Frame2;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
  ActiveFrame := Frame3;
end;
 
end.
 
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;
 
type
  TFrame2 = class(TFrame)
    Panel1: TPanel;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
implementation
 
{$R *.dfm}
 
end.
 
unit Unit3;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls;
 
type
  TFrame3 = class(TFrame)
    ListBox1: TListBox;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
implementation
 
{$R *.dfm}
 
end.
 
object Form1: TForm1
  Left = 192
  Top = 160
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 45
    Top = 25
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 45
    Top = 65
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Panel2: TPanel
    Left = 60
    Top = 115
    Width = 586
    Height = 361
    Caption = 'Panel2'
    TabOrder = 2
  end
end
 
object Frame2: TFrame2
  Left = 0
  Top = 0
  Width = 320
  Height = 240
  TabOrder = 0
  object Panel1: TPanel
    Left = 55
    Top = 35
    Width = 196
    Height = 136
    Caption = 'Panel1'
    Color = clRed
    TabOrder = 0
  end
end
 
object Frame3: TFrame3
  Left = 0
  Top = 0
  Width = 320
  Height = 240
  TabOrder = 0
  object ListBox1: TListBox
    Left = 35
    Top = 40
    Width = 236
    Height = 161
    Color = clLime
    ItemHeight = 13
    TabOrder = 0
  end
end

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:

Select allOpen in new window

 

by: senadPosted on 2008-11-07 at 00:22:21ID: 22902520

Sorry to disapoint you but it does not work.

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Panel2: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    Frame2: TFrame;
    Frame3: TFrame;
    fActiveFrame: TFrame;
    procedure SetActiveFrame(const Value: TFrame);
  public
    property ActiveFrame: TFrame read fActiveFrame write SetActiveFrame;
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
Uses Unit2,Unit3;
 
procedure TForm1.SetActiveFrame(const Value: TFrame);
var
  LastFrame : TFrame;
begin
  LastFrame := fActiveFrame;
  fActiveFrame := Value;
  if Assigned(LastFrame) then
    LastFrame.Parent := nil;
  if Assigned(fActiveFrame) then
    fActiveFrame.Parent := Panel2;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame2 := TFrame2.Create(Self);
  Frame3 := TFrame3.Create(Self);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  ActiveFrame := Frame2;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
  ActiveFrame := Frame3;
end;
 
end.
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:

Select allOpen in new window

 

by: Geert_GruwezPosted on 2008-11-07 at 00:23:21ID: 22902527

did you actually try all my code ?

 

by: Geert_GruwezPosted on 2008-11-07 at 00:25:19ID: 22902535

now and then somme funny things happen

Like me giving up on this

Have you seen Achmed, The Dead Terrorist ?
I'm not yelling at my screen the famous words !
"Silence, I ..."

 

by: senadPosted on 2008-11-08 at 05:16:40ID: 22912072



Of course I tried....
(by the way,in your nice picture,what's a panel doing on a frame ?)
Ahmed is lucky...I am banging my head on the monitor asking myself how comes it works for him and not for me?.
'resources like memory ' ...you really miss the old DOS days,aren't you??
Did you try and compile my code,actually?

 

by: Geert_GruwezPosted on 2008-11-10 at 06:34:12ID: 22921760

what's a panel doing on a frame ?

you can design frames any which way you like
you can put a lot of components on a panel
(just like a form actually)

when you right click on the Frame in the Frame/Form Editor
you have the menu option "Add to component palette"
This puts the Frame and *all* it's components on the component palette

When you open a new form, click on the just created component
in the component palette and then click in you form
you will have the frame and all it's components in this new form

How did you think frames were being used ?

 

by: Geert_GruwezPosted on 2008-11-10 at 06:35:00ID: 22921766

I can't compile your code !!!

I don't have units 2 and 3 !!!

 

by: senadPosted on 2008-11-11 at 03:55:42ID: 22929462

Well.to get those units use "New" - "New Frame"  :-)
Once you get them please do (and I mean :do) trie and compile.
No more pictures,please...

 

by: Geert_GruwezPosted on 2008-11-14 at 05:17:55ID: 22959128

i'm not the novice at Delphi here.
if you can't get it to work, i'll be happy to come over and show what yer doing wrong
you just need to mail me the airplane ticket, cab fare and hotel fare for 1 night.

I posted you a complete working sample.
If you can't get this sample to work then there is no point to continue.

The pictures were proof it actually works.





 

by: senadPosted on 2008-11-14 at 10:11:17ID: 22962017

The question was why my code does not work,not yours...

 

by: Geert_GruwezPosted on 2008-11-14 at 23:28:37ID: 22966136

Your code doesn't work because something is obviously wrong with it.
That's why i gave you a *working* example.
You can use it to start and copy your code into it.

Go 1 step/event/procedure at a time, untill you get to the error.

 

by: senadPosted on 2008-11-30 at 02:26:32ID: 23062563

No,this is not it...

 

by: Geert_GruwezPosted on 2008-11-30 at 23:29:06ID: 23066649

senad, I'm giving up on you and frames.
I tried explaining with hands, feet, face, everything.
Obviously you just don't grasp it, do you ?

put you project in .zip, put it on EE-stuff and people can take a look at it.

You're not gonna get any further like this !

 

by: senadPosted on 2008-12-01 at 00:28:08ID: 23066847

That first code was not my code anyway...I found it posted somewhere...dont remember where...
It seemed to me a good idea (so you do not have to do a 'frame.hide and frame.show stuff)
Tried it and it dont seem to work.That is why I tried to have some help with that very same code (in case I was doing something wrong).Since I am a noobie in programming I allways try and find something new,to discover how things work.
As for the frames,I think I am going to give up on them to...Seems a nice idea at first but the more you get into them the more limitations you find.(Also found a nice example at codegear how to put frames on tab control).All in all I found it to be the best practice to use forms.


 

by: Geert_GruwezPosted on 2008-12-01 at 00:29:40ID: 23066853

frame have some pitfalls, especially when modifying the ancestor and deleting controls

 

by: Geert_GruwezPosted on 2008-12-02 at 23:00:40ID: 23083756

well, maybe but the question has been answered.
Because of all the effort i put into this, i object to deletion

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...