I'm using delphi 7 and I'm trying to make a wizard interface. I don't know if there is an easier way to make a wizard, so I was thinking of making separate forms for each step of the wizard, and when the user clicks "Next" the active form closes and the next one opens.
Here's a screen-shot of two successive forms:
I've made a procedure that take 2 forms as parameters: the form that will be closed and the next form of the wizard
class Procedure Tspad.nextForm(showForm, closeForm: TForm);
begin
closeForm.Close;
showForm.Showmodal;
end;
When I click the "Next" Button the folowing code is executed:
Tspad.nextForm(echipContractForm, clientContractForm);
When i run the program, and i press the "Next" button, the next form apeares but the curent one dosen't close.
How can i make this work, or is there another more efficient way to create a wizard?
One very common way to make a wizard is to use a page control. Each distinct page of the wizard is a different page/tabsheet in the page control. I believe that this is effectively how Windows implements wizards.
Naturally you want to hide all the tabs. Do this by setting TabVisible to False for each tabsheet. When you wish to move forwards and backwards through the wizard, e.g. when the user clicks the next or previous buttons, effect this by setting ActivePage or ActivePageIndex depending on your preference.
A good practise for the division of content being displayed on a single form is the use of Frames.
A Frame is a lot like a form, except it has no Window of its own, but rather sits inside a host Form.
When combined with (as David Heffernan has suggested) a TPageControl or even a TNotebook (which is pretty-much exactly the same as TPageControl, only it doesn't have Tabs to begin with), you end up with an easily-maintainable Wizard.
JVCL has a good control to make a wizard in a very simple and effective way (TJvWizard). See http://jvcl.delphi-jedi.org/
You can give a try to these :
Balmsoft Wizard released under LGPL.
Delphi Wizard Framework by SO member Steven R. Kamradt.
You can test some components that can help you with this task (internally using tPageControl or TNotebook). See this link.
Regards.
You may also consider TMS TAdvSmoothStepControl (not free !).
Another solution, but only 'external' to your program, is to use Inno Setup to make a Wizard, even for 'non installation setup' purposes.
In fact with Inno Setup you can make a lot of thinks ( modify .ini file and registry, start/stop programs...) that can be usefull for a wizard without 'installing' a program.
Related
I am working on a project but I faced a problem in making a form stay always on top like task manager in delphi
I used this code but didn't work
SetWindowPos(Form1.Handle, HWND_TOPMOST, 0,0,0,0, SWP_NOACTIVATE+SWP_NOMOVE+SWP_NOSIZE);
Modern task manager uses internal private Windows functionality for its stay on top behaviour. The system does not make this available to user windows. The functionality that task manager uses simply isn't available to you.
Related question: Is Task Manager a special kind of 'Always on Top' window for windows 10?
Just use the Object Inspector at design time to set the form's FormStyle property to fsStayOnTop.
The code from the original post might work on a main form, but will not work on a secondary form. fsStayOnTop is only part of the solution for a secondary form. Below is an easy solution for making a secondary form stay on top while the main form is obscured by other applications - without resorting to showmodal or form creation hacks.
Put this in the "Form B" OnCreate event:
FormStyle:= fsStayOnTop;
but that alone won't do the trick...
Drag a TApplicationEvents onto your "Form B"
In the OnDeactivate event for ApplicationEvents1, add the following:
SetForegroundWindow(Handle);
I keep an eye on a small status window while my main form is crunching data out of site. Works beautifully!
Since I know you guys are exceptional people with awesome talents, maybe someone might be able to help me with this.
This is the situation:
I have an Application that calls a DLL. The catch here is that I'm opening the DLL in a TAdvPanel (it belongs to a TMS library, but I believe it works for the standard Panels too), and it works perfectly fine.
Whenever I close the tab, I can always call the DLL again and recreate its Form, but when I close the Form, the tab where the DLL was stays open, with no content inside of it.
Is there a way for me to "warn" the Application that the DLL was closed and that I can close the tab where the DLL was?
(Note: whenever I write Form, I mean the DLL's Form.)
This is how I call the DLL from inside the Application:
CallCompany(<Parameters..>,Panel.Handle);
And this code below belongs to the DLL:
library Company
uses
...,
U_Form in 'U_Form.pas' {Form}, Windows,
... ;
{$R *.res}
procedure CallCompany(<Parameters..>; ParentForm: THandle); export; stdcall;
var
...
begin
... <Preparing the form to open> ...
Form.Show;
Windows.SetParent(Form.Handle, ParentForm);
end;
exports
CallCompany;
I'm new with DLL's and the way they work. I know I could just not give the user the "Exit" button inside the DLL, forcing him to close the tab, but I wanted to give him that option too.
Ah, and I don't have any code for the OnClose event of the DLL's Form.
If you need any other information in order to help, just tell me and I'll post here whatever is needed.
BTW, I'm using Delphi XE7.
Thanks for the attention.
Complementing the Question:
I have a TAdvPageControl, in which I create TAdvTabSheets, and inside this TAdvTabSheets I put a TAdvPanel (set as alClient).
The DLL I call has a Form, does that categorize as "more that a DLL" ?
I'm posting an image so that might clear things a little bit. If it's still confusing, just say it and I'll drop the question.
When I close the form, the tab where the form was stays open, with no content inside of it.
Don't ever close the form without also closing the tab. That way this situation never arises.
As for specifics, I've got none to offer since the question has no real detail, no MCVE. But it's fairly obvious that the tab and the form that it hosts must be shown and hidden in unison.
I'm using Delphi XE3 in a complex application that has MDI forms, and forms that stays on top also.
Sometimes a simple ShowMessage('...') does not appear and stays behind the main application window.
Either people think that the application has crashed, or go to task manager and put back the application on top, and then showmessage windows come back on top.
This is occuring in XP, I haven't seen that under Win8 so far.
Any idea why?
You can try this:
Wrote your own myShowMSG function. In this function wrote the simple custom message form and some code to control - "Are this form are visible to user?" In control code write to error.log all tracelog information about this problem. Include the list of actually created forms and their states to .log
Replace all ShowMessage in your project to myShowMSG
Run all tests
Read your error.log's. Post it here to disquss
I'm developing a Word addin, and somehow the shortcuts defined in TAction.ShortCut are always trigged more than one time, and this is tricky to me and hard to solve, so I resort to TForm.OnKeyDown event and cleared all TAction.ShortCut properties, this approach works well, except that the shortcuts are not shown on the corresponding menu items, but I want them to be displayed on those menu items.
So I come up this idea: Set values for TMenuItem.Shortcut so that the program can show the shortcut hint to the end user, and does not allow VCL to handle these shortcuts, instead, handle them in TForm.OnKeyDown. So my question is how to disable TAction.Shortcut or TMenuItem.Shortcut? Thank you in advance.
For a start, you have an Enabled property on both TAction and TMenuItem. Just set it to False.
Next, one of the possible causes of your event being triggered more than once is that you may be using Application.ProcessMessages; or at least a badly written component that you're using is doing so. One should be very wary of using that Delphi feature because it can cause 're-entrant' code (unintentional recursion).
The root cause of your problem is the events being triggered more than one time. You could try to workaround this problem offcourse but I would suggest to:
Place a breakpoint in your eventhandler.
Copy the Call Stack's content [CTRL+ALT+S] to whatever editor you like for every time you hit the breakpoint.
Start brainstorming as to why the calls lead to hitting the event multiple times.
Fix your code if it is your code to fix.
Hacker way (usually not recommended):
copy unit that contain TAction in separate folder, modify source of TAction that makes ShortCut method do nothing. Put this folder to search path as first item.
rebuild your app.
I use this technique to fix bugs in VCL, but after installing Delphi patches you should not forget to update 'hacked' version of modified units.
I put a TLinkLabel on my form, filled it in with a caption including a valid HTML link, and got some nice blue underlined text. When I ran the program, I expected it to invoke Firefox (my default browser) and open the link automatically. Apparently that's not the case.
The helpfile says I have to code this in an OnLinkClick event handler. It doesn't say anything about how to do that, though. It'll pass in a string value called "Link". How do I say "invoke the default browser and have it open Link"?
You can call ShellExecute.
I wrote this method for generic calls, and should works in your case.
procedure ShellOpen(const Url: string; const Params: string = '');
begin
ShellAPI.ShellExecute(0, 'Open', PChar(Url), PChar(Params), nil, SW_SHOWNORMAL);
end;
In your code you should call this
procedure TForm1.LinkLabelClick(Sender: TObject);
begin
ShellOpen(LinkLabel.Caption);
end;
I have all sorts of problems with TLinkLabel that ships with delphi 2010.
a) The control does not render as a hyperlink but as a simple label text on the form. b) the cursor does not change to point out this is a link even though I set the Cursor property. c) the OnLinkClick event does not fire at all.
I am working on windows 7.
So, as far as I am concerned, TLinkLabel does nothing as it should and is useless. ShellExecute is the only solution and must be placed in the OnClick event.
TLinkLabel provides a label that looks like a link. It's your job as the programmer to make it act like a link because only you can know what links are supposed to act like in your program. You wanted the label to automatically open the user's default Web browser using the URL in the label, but that's not the only thing links do. For example:
Internet Explorer is not my default browser, but when I click a link in Internet Explorer, I do not expect the linked page to open in Firefox.
When I click a link in the help program, I expect the linked topic to appear in the help program, not in any Web browser at all.
The preference pages in Eclipse are very complicated. Settings on one page are sometimes related to settings on another page. There are links on those pages that take the user directly to the related page. There is no URL and no HTML involved in this case, and yet they're still labels with underlined text.
Some programs try to offer a choice between opening links in new windows versus re-using old windows. You can't implement that feature without knowing which browser is in use. Your program might offer the user a choice to ignore the default browser setting and always use a specific one. To do that, your UI control can't make too many assumptions about what the program is supposed to do.
I'm guessing you're referring to a TLinkLabel control that comes with Delphi. (My versions don't have such a component.) I imagine that the Delphi control is meant to mimic the one in the .Net class library. It can hold multiple links, and each link can do something different.
If you want a control that always does the shell's default action for URLs, then consider using a different TLinkLabel; the one by Alexander Bach does exactly what you expected. It's from Delphi 3, but it should work unmodified in all later versions as well, including Delphi 2009. If you look at the code, you'll see how it works. It simply calls ShellExecute, as Cesar's answer demonstrates.
LOL, it's funny. So instead of setting crHandPoint as cursor, colored and underlined font and filling the OnClick event to standard TLabel we have component that knows link tag and which at all I need to supply with same On(Link)Click event :))
Only thing it is good for is that it makes easier to embed link into some text and that it is using system style of link...
p.s.: really you have to put Some text with link into the Caption and setup OnLinkClick to that ShellExecute...
I use a control called TInternetLabel instead. It does exactly what you want: on click it opens the browser so you don't have to put code in the OnClick event.
I tried this solution but it still gave problems in Delphi XE4, probably becasue ShellOpen does not understand the HTML-code in the Caption.
What worked for me was a combination of Cesar Romero (the basic code), Adam Feistner (The HTML-code in the Caption) and an older solution:
Put the URL in the HINT field.
Change the line: ShellOpen(LinkLabel.Caption);
to
ShellOpen(LinkLabel.Hint);
This worked for me.