?
Solved

adding parameters to ShowModal event

Posted on 2003-03-12
4
Medium Priority
?
2,171 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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

612 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