Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Managing Forms in Delphi

Posted on 2005-05-12
11
Medium Priority
?
463 Views
Last Modified: 2013-12-03
Hello everybody I have a problem. My App's main form is hide with Application.ShowMainForm:=false and other form called ControlForm has all the control. All forms have the roperty Borderstyle set to bsNone. The problem is that when i open 2 forms or more, when i change to other app and i return back to mine, my app shows the last form. I need to show all forms. ControlForm First, over the first form i opened, then over first, the second ..etc. when my app is activated. I tried using ShowModal but it doesn't work i think because of Borderstyle property. Is there any way to do this?
0
Comment
Question by:lmmedina
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:Voodooman
ID: 13991202

Hi

I had similar problems.

The best way (for me) was to keep the main form shown and show other forms modal.

My Main form was my Splash which I then hid.

The problem seems to be when the main form/Splash was hidden.

I work around this by showing the splash before the Main Form is created.

It surprises me that Delphi alows you to do all sorts of things before the application is created.

Here is an Example Project File where all sorts of things happen before the main form is shown - including showing the spalsh!

program GetRichQuick;



uses
  FastShareMem in 'Code\FastShareMem.pas',
  Forms,
  SysUtils,
  Dialogs,
  FormMain in 'Code\FormMain.pas' {F_Main},
  DataObject in 'Code\DataObject.pas' {DataObj: TDataModule},
  Useful_Functions in 'Code\Useful_Functions.pas',
  FormOpening in 'Code\FormOpening.pas' {F_Opening},
  FormDeleteEstimate in 'Code\FormDeleteEstimate.pas' {F_DeleteEstimate},
  FormEditItem in 'Code\FormEditItem.pas' {F_EditItem},
  FormAreaWizard in 'Code\FormAreaWizard.pas' {F_AreaWizard},
  FormEditSummaryItem in 'Code\FormEditSummaryItem.pas' {F_EditSummaryItem},
  FormSelectEstimate in 'Code\FormSelectEstimate.pas' {F_SelectEstimate},
  FormNewItem in 'Code\FormNewItem.pas' {F_NewItem},
  FNewUnit in 'Code\FNewUnit.pas' {F_NewUnit},
  FormUnitManager in 'Code\FormUnitManager.pas' {F_UnitManager},
  FormRenameArea in 'Code\FormRenameArea.pas' {F_RenameArea},
  FormAddAreaWizard in 'Code\FormAddAreaWizard.pas' {F_AddAreaWizard},
  FormAddUnit in 'Code\FormAddUnit.pas' {F_AddUnit},
  FormProperties in 'Code\FormProperties.pas' {F_Properties},
  FormEditNote in 'Code\FormEditNote.pas' {F_EditNote},
  FormAddNote in 'Code\FormAddNote.pas' {F_AddNote},
  FormAreaManager in 'Code\FormAreaManager.pas' {F_AreaManager},
  FormAddArea in 'Code\FormAddArea.pas' {F_AddArea},
  FormLookup in 'Code\FormLookup.pas' {F_Lookup},
  FormSplashTrial in 'Code\FormSplashTrial.pas' {F_SplashTrial},
  SPAppInf in 'Code\SPAppInf.pas',
  FormAbout in 'Code\FormAbout.pas' {F_About},
  FormCopyProject in 'Code\FormCopyProject.pas' {F_CopyProject},
  FormNewProject in 'Code\FormNewProject.pas' {F_NewProject},
  FormLimitedTrial in 'Code\FormLimitedTrial.pas' {F_LimitedTrial},
  FormSplash in 'Code\FormSplash.pas' {F_Splash},
  Encrypt in 'Code\Encrypt.pas',
  FormRegister in 'Code\FormRegister.pas' {F_Register};

{$R *.res}

begin
  Application.Initialize;
  Application.Title := 'Quick Estimator';
  Application.CreateForm(TF_Main, F_Main);
  Application.CreateForm(TDataObj, DataObj);
  Application.CreateForm(TF_Opening, F_Opening);
  Try
  //need to check if its licensed
  //*****************************
  dataobj.isRegistered:=False;
  dataObj.DBISAMSession.AddPassword('voodoo');
  dataObj.tbSys.Active:=True;
  if dataobj.TBSys.RecordCount=0 then
     Begin
     dataObj.TBSys.Append;
     dataObj.TBSys.Post;
     end;
  if dataobj.TBSys.FieldValues['isRegistered']=false then
     Begin
     dataobj.isRegistered:=False;
     Application.CreateForm(TF_SplashTrial, F_SplashTrial);
     F_SplashTrial.ShowModal;
     end
     else
     Begin
     dataobj.isRegistered:=True;
     Application.CreateForm(TF_Splash, F_Splash);
     F_Splash.ShowModal;
     end;

  except on E:Exception do
  Begin
  MessageDlg('Error checking registration status.', mtError, [mbOK], 0);
  Application.Terminate;
  end;

  end;

  F_main.show;
  F_Opening.ShowModal;
  Application.Run;

end.


Avoid hiding your main form and your problems should go away.

Voodooman


0
 

Author Comment

by:lmmedina
ID: 14023409
Hi, thanks for reply, but Thats the problem. I really need My main form hidden. So, i was testing and i think the problem comes when i modify creation parameters in createParams mehod... maybe it could be the problem. Is there anyway to solve this ???
0
 
LVL 17

Expert Comment

by:geobul
ID: 14025162
Hi,

Would you show us your CreateParams method implementation?
Are you having different taskbar buttons for all your currently opened forms? What do you mean by 'return back to my application' - tab key, clicking on a taskbar button (project, ControlForm or another form button)?

Regards, Geo
0
Technology Partners: 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!

 

Author Comment

by:lmmedina
ID: 14028225
Some forms are standard forms, others, have itself taskbar button. I create them with something like this

void __fastcall MyForm::CreateParams(Controls::TCreateParams &Params)
{
    TForm::CreateParams(Params);
    Params.ExStyle = WS_EX_APPWINDOW;
    Params.WndParent = GetDesktopWindow();
    Params.Style    =   WS_POPUP|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX;//|WS_SIZEBOX;
}
//---------------------------------------------------------------------------
0
 
LVL 17

Expert Comment

by:geobul
ID: 14028389
Surprise! What the hell is this. Are you sure you're using Delphi? This looks like C++ to me. I can't help you with that language. Sorry.
0
 

Author Comment

by:lmmedina
ID: 14028534
Sorry... i make a mistake... Delphi and C++ Builder are similar. This is the code in delphi

type

  TMyForm = class(TForm)

  protected

    procedure CreateParams(var Params: TCreateParams); override;

  end

 

procedure TMyForm.CreateParams(var Params: TCreateParams);

begin

  inherited CreateParams(Params);
  Params.ExStyle := WS_EX_APPWINDOW;
  Params.WndParent := GetDesktopWindow;
  Params.Style := WS_POPUP or WS_SYSMENU or WS_MAXIMIZEBOX or WS_MINIMIZEBOX;

end;
0
 
LVL 17

Accepted Solution

by:
geobul earned 172 total points
ID: 14028748
OK. Comment
Params.WndParent := GetDesktopWindow;
line for all forms and try again.

Regards, Geo
0
 
LVL 5

Assisted Solution

by:Voodooman
Voodooman earned 164 total points
ID: 14029135

Hi

I've seen this put forward before relating to hiding the main form and it seems to cause more problems than it cures.

After all, you're doing pretty much the same as Borland.... re-inventing th wheel perhaps.

I think you have to avoid permanently hiding the Main Form (in my poor experience anyway...)..

Don't use this >>Application.ShowMainForm:=false

Instead, just hide the main form with self.hide;

then, show the next form;

MyForm.show;

Followed by showing your other forms Modally.

No offense to anyone.

Voodooman
0
 
LVL 1

Assisted Solution

by:tammoz
tammoz earned 164 total points
ID: 14075909
Hi
try to use an API function [showWindow()] for me I use a Hidden memo in my mainform and when the program creates any other form it sends its handle as a new line in the memo (I use show not showmodal) and in the onpaint of the mainform the program triggers the showwindow(SHOW-NOT-ACTIVE) (this code is not accurate 100% but I wish you get the idea) for all the memo lines, for you while your mainform is hidden you can put the code somewhere else

bon chance
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

564 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