[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Changing Frames in your form like with IFrames in html

hi, i have 2 Frame Forms, I have 1 Main Form, I'd like to be able to switch between Frame Form 1 & Frame Form 2 With a Button Click to display within the Frame on the Main Form.

how do I do this, could you provide examples.

I would like to do the same as Iframes in HTML, you click a link and it will display that page within the iframe you click another link it will display another page within the iframe.

Sal.
0
SaLz
Asked:
SaLz
  • 2
  • 2
1 Solution
 
vadim_tiCommented:
if i understand you right this is a segment of code you wanted


//UNIT1.PAS
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Unit3, Unit2;

type
  TForm1 = class(TForm)
    Frame11: TFrame1;
    Frame21: TFrame2;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if frame11.Visible then begin
    frame11.Visible := false;
    frame21.Visible := true;
  end
  else begin
    frame21.Visible := false;
    frame11.Visible := true;
  end
end;

end.

// UNIT1.DFM
object Form1: TForm1
  Left = 192
  Top = 133
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  inline Frame11: TFrame1
    Left = 32
    Top = 8
    Width = 320
    Height = 241
    Color = clNavy
    ParentColor = False
    TabOrder = 0
    Visible = False
  end
  inline Frame21: TFrame2
    Left = 32
    Top = 5
    Width = 320
    Height = 240
    Color = clGreen
    ParentColor = False
    TabOrder = 1
  end
  object Button1: TButton
    Left = 112
    Top = 296
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 2
    OnClick = Button1Click
  end
end
0
 
SaLzAuthor Commented:
show/hide 2 frames :( is there any other way of using just 1 frame in the main to display the 2 fame forms within the 1 frame main?
0
 
vadim_tiCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Unit3, Unit2;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Frame: TFrame;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Frame is TFrame1 then begin
    Frame.Destroy;
    Frame := TFrame2.Create(Self);
    Frame.Parent := Self;
  end
  else begin
    Frame.Destroy;
    Frame := TFrame1.Create(Self);
    Frame.Parent := Self;
  end
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Frame := TFrame1.Create(Self);
  Frame.Parent := Self;
end;

end.
0
 
SaLzAuthor Commented:
by creating a new and deleteing the old frame, it flickers with each click, the hide/show is looking better tho, lol

thanks.
Sal.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now