[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to jump from Form to TMainFrm-procedure ?

Posted on 2004-10-26
16
Medium Priority
?
310 Views
Last Modified: 2010-04-05
Hi,

I need solutions to some small problem I am having with Delphi. Please provide a detailed resolutions (if possible)

1. Please give an illustratation on how to jump to TMainFrm procedure XYZ from Form1.
2. Also how can I disable a form (event driven) so its not created with TMainFrm (OnCreate) event?

Thanks!

- Adnan Afzal
0
Comment
Question by:mdadnan
[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
  • 9
  • 3
  • 3
16 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12410990
>Please provide a detailed resolutions
too less time, too less points

>1. Please give an illustratation on how to jump to TMainFrm procedure XYZ from Form1.
......
implementation
uses MainFormUnitNameHere;

procedure foo;
begin
  MainFormNameHere.SomeMethod(Params);  //call a mainform-method
end;


>2. Also how can I disable a form (event driven) so its not created with TMainFrm
>(OnCreate) event?

have a global var maybe named
CreateFormX : Boolean;

use in the onCreate-event

....
  If CreateFormX then
    //Create the Form
....

meikl ;-)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12411084
//............................ MainForm
type
  TMainForm=class(TForm)
      MainMenu1: TMainMenu;
      Panel1: TPanel;
      Label1: TLabel;
      Button1: TButton;
      procedure Button1Click(Sender: TObject);
    private  
    { Private declarations }
    public    
      procedure XYZ; // it must be created into the public section or above private section as procedure Button1Click();
    { Public declarations }
  end ;
//........

procedure TMainForm.XYZ;
// var ........
begin
//........
end;

//............................ Form1
procedure TForm1.Button1Click(Sender: TObject);
begin
  MainForm.XYZ;                            // calling this procedure from MainForm
  MainForm.Button1Click(MainForm) // calling this procedure from MainForm
end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12411144
It does not matter where is a TForm created, it could be disabled for example:
 
procedure TMainForm.XYZ;
begin
  Form2.Enabled := False;
end;
0
Industry Leaders: 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 12

Expert Comment

by:esoftbg
ID: 12411307
Hi kretzschmar,

excuse me, can you take a look at:

http://experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21173968.html

http://experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21180393.html

There I got all the points, but I didn't deserve in fullest ....
You may correct these.
0
 

Author Comment

by:mdadnan
ID: 12412357
Hi again,

I am getting these errors:

 MainFrm.XYZ;                               [Error] Unit2.pas(28): Undeclared identifier: 'MainFrm'
 MainFrm.Button1Click(MainFrm);  [Error] Unit2.pas(29): Missing operator or semicolon

Please note procedure XYZClick(Sender: TObject); is already defined public in unit1.

If possible please zip send me the working  example at mdadnan@gmail.com.

Thanks.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12412617
Ooops, I forgot to mention that before call a mettod from another unit, you need to declare this unit into the uses-clause of the unit where will be the call written:

//............................ Form1

implementation

{$R *.DFM}

uses
  MainUnit; // the unit of the MainForm

procedure TForm1.Button1Click(Sender: TObject);
begin
  MainForm.XYZ;                            // calling this procedure from MainForm
  MainForm.Button1Click(MainForm) // calling this procedure from MainForm
end;
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12412694
I will make and send an example immediately ....
0
 

Author Comment

by:mdadnan
ID: 12412856
Hi again,

I am having a hard time figuring this out. I had already added the main form reference under 'uses' as suggested by kretzschmar in his first post.

esoftbg, I appreciate your prompt responses but this is not working out here. I am receiving the same errors explained in my last post above. :-\

Thanks for all the help.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12412921
i'm sure you get it sorted with esoftbg's advice, so i'm still listening . . .
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 400 total points
ID: 12413348
mdadnan,
I have some problems with my computer, but now I sent an example to your e-mail address ....
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12413391
kretzschmar,
thanks for your responce about my  request.
Emil
0
 

Author Comment

by:mdadnan
ID: 12414906
Thank you esoftbg for sending an excellent example.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12414951
You are welcome mdadnan !
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12415371
you should post your sample here, esoftbg ;-)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12415466
//........ The Project ........
program Q_21182908;

uses
  Forms,
  MainUnit in 'MainUnit.pas' {MainForm},
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

//........ MainUnit ........
unit MainUnit;

interface

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

type
  TMainForm = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    private
    { Private declarations }
    public
      procedure XYZ;
      procedure ZYX;
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

uses
  Unit1, Unit2;

{$R *.dfm}

procedure TMainForm.Button1Click(Sender: TObject);
begin
  if Form1.Visible then
    Form1.Hide
  else
    Form1.Show;
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
  if Form2.Visible then
    Form2.Hide
  else
    Form2.Show;
end;

procedure TMainForm.XYZ;
begin
  Memo2.Lines.Assign(Memo1.Lines);
end;

procedure TMainForm.ZYX;
begin
  Memo2.Clear;
end;

end.

//........ MainForm ........
object MainForm: TMainForm
  Left = 247
  Top = 114
  Width = 570
  Height = 288
  Caption = 'MainForm'
  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
  object Button1: TButton
    Left = 32
    Top = 16
    Width = 96
    Height = 25
    Caption = 'Show Form1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 32
    Top = 64
    Width = 96
    Height = 25
    Caption = 'Show Form2'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Memo1: TMemo
    Left = 160
    Top = 16
    Width = 185
    Height = 224
    Lines.Strings = (
      'Today is a cool, sunny day without '
      'rain. ')
    TabOrder = 2
  end
  object Memo2: TMemo
    Left = 352
    Top = 16
    Width = 185
    Height = 224
    TabOrder = 3
  end
end

//........ Unit1 ........
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  MainUnit, Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  MainForm.XYZ;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  MainForm.ZYX;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Form2.Enabled := not Form2.Enabled;
end;

end.

//........ Form1 ........
object Form1: TForm1
  Left = 243
  Top = 304
  Width = 222
  Height = 204
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 16
    Top = 22
    Width = 75
    Height = 25
    Caption = 'XYZ'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 14
    Top = 62
    Width = 75
    Height = 25
    Caption = 'ZYX'
    TabOrder = 1
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 118
    Top = 110
    Width = 75
    Height = 25
    Caption = 'Enabled ?'
    TabOrder = 2
    OnClick = Button3Click
  end
end

//........ Unit2 ........
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Memo1: TMemo;
    private
    { Private declarations }
    public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

end.

//........ Form2 ........
object Form2: TForm2
  Left = 515
  Top = 335
  Width = 283
  Height = 221
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 6
    Top = 12
    Width = 223
    Height = 143
    Lines.Strings = (
      'You can edit if Form2.Enabled is True.')
    TabOrder = 0
  end
end
0

Featured Post

Industry Leaders: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 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