no const needed here I think
procedure SetActiveFrame(const Value: TFrame);
Main Topics
Browse All TopicsTwo 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(cons
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:
begin
FreeAndNil(Frame2);
FreeAndNil(Frame3);
end;
procedure TForm1.Button1Click(Sender
begin
ActiveFrame := Frame2;
end;
procedure TForm1.Button2Click(Sender
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.
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.
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.
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.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
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.
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(cons
var
LastFrame : TFrames; ..........
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(cons
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:
begin
FreeAndNil(Frame2);
FreeAndNil(Frame3);
end;
procedure TForm1.Button1Click(Sender
begin
ActiveFrame := Frame2;
end;
procedure TForm1.Button2Click(Sender
begin
ActiveFrame := Frame3;
end;
end.
probably this too:
procedure TForm1.SetActiveFrame(cons
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;
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
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
fActiveFra
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
Form
implementation
{$R *.dfm}
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
begin
inherited
fActiveFram
Frame2 := nil;
Frame3 := nil;
end;
function TForm1.GetFrame2: TFrame;
begin
if not Assigned(Frame2) then
begin
Frame2 := TFrame.Create(Self);
Frame2
Frame2.Align := alClient;
end;
Result := Frame2;
end;
function TForm1.GetFrame3: TFrame;
begin
if not Assigned(Frame3) then
begin
Frame3 := TFrame.Create(Self);
Frame3
Frame3.Align := alClient;
end;
Result := Frame3;
end;
procedure TForm1.SetActiveFrame(cons
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
begin
ActiveFrame := DisplayFrame2;
end;
procedur
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...
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
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?
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 ?
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.
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.
Business Accounts
Answer for Membership
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;
Select allOpen in new window