?
Solved

adding parameters to ShowModal event

Posted on 2003-03-12
4
Medium Priority
?
2,033 Views
Last Modified: 2008-02-01
I am calling a form stored in another unit with the following code:

  with TfrmStaffDetails.Create(self) do
  begin
    try
    ShowModal;
    Visible:=True;
    finally free;
    end; {try}
  end; {with}

The form I'm opening here has four different variations of what components are enabled/disabled when it is opened, I would like to be able to pass an integer (1,2,3 or 4) to it in the ShowModal or create event so that I can sort out all aspects of the layout without the new form having to access global variables to decide on the layout. i.e. I do not want global variables.
I tried overriding the ShowModal event and adding a parameter like so:
procedure ShowModal(layout:integer); override;
but I realise this is naive and won't work. Any ideas how I can pass paramaters to a form as I open it?
0
Comment
Question by:jazzygm
[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
4 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 8121292
TShowType = (stType1, stType2, stType3);
TfrmStaffDetails2 = class(TfrmStaffDetails)
  private
    FShowType: TShowType;
  protected
    procedure SetShowType(Value: TShowType);virtual;
  public
    property ShowType: TShowType read FShowType write FShowType;
end;


procedure TfrmStaffDetails.SetShowType(Value: TShowType);
begin
  FShowType:=Value;
  case FShowType of
    stType1:;
    stType2:;
    stType3:;
  end;
end;

then use it like this:

with TfrmStaffDetails.Create(Self) do
 begin
   try
   Parent:=?? set parent here
   ShowType:=stType1;
   ShowModal;
   finally
     Free;
   end;
 end;


ziolko.
0
 
LVL 2

Accepted Solution

by:
steve_hsk earned 240 total points
ID: 8123247
Hi Jazz ...

Instead of Overriding, try Overloading. Overridding is when the function declaration is exactly the same. Overloading is when the function name is the same, but it's arguments or return type differ.

Check out the delphi help on OverRide, OverLoad, and ReIntroduce.

So with just a slight change, this compiles nicely.

Your 2nd form can be declared like this :-

type TForm2 = class(TForm)
public
    PROCEDURE ShowModal(iGUIMode : Integer); OVERLOAD;
end;

implementation
{$R *.DFM}

PROCEDURE TFORM2.ShowModal(iGUIMode : Integer);
BEGIN
    // Change GUI Mode according to function argument
    If IGUIMode = 1 THEN
    Begin
       // do stuff to gui, checkboxes, etc
    End
    Else If IGUIMode = 2 THEN
    Begin
       // do stuff to gui, checkboxes, etc
    End

    // Remember to call the default functionality to show the form
    inherited ShowModal;    
END;

procedure TForm1.Button1Click(Sender: TObject);
VAR Form2 : TForm2;
begin
    Form2 := TForm2.Create(self);
    Form2.ShowModal(1); // pass gui option as argument
    Form2.Free;
end;

There is another alternative. Instead of overloading ShowModal, write a 'wrapper' for it. The only difference for your project code is that if this form is inherited or treated as a sequential child object, it wont have the showmodal function, but instead a new function :

type TForm2 = class(TForm)
public
    PROCEDURE ChangeGuiState(iNewState : Integer);
end;

implementation
{$R *.DFM}

PROCEDURE TFORM2.ChangeGuiState(iNewState : Integer);
BEGIN
    // Change GUI Mode according to function argument
    // ...
   
    // Now show GUI
    ShowModal;    
END;

procedure TForm1.Button1Click(Sender: TObject);
VAR Form2 : TForm2;
begin
    Form2 := TForm2.Create(self);
    Form2.ChangeGuiState(1); // pass gui option as argument
    Form2.Free;
end;

Hope this helps,
Steve
0
 

Author Comment

by:jazzygm
ID: 8123649
Picking up on exactly what i was trying to do and helping that way got you the browny points, the other way is pretty much the same as other comment
0
 
LVL 2

Expert Comment

by:steve_hsk
ID: 8126052
Happy I could help Jazz !

Steve
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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