Let's suppose that you want a simple dialogbox that looks like the one above. You want to call that dialog from your code just like you call Delphi's dialogs, for example call it from clicking Button1 on your main form: procedure TFormMain.Button1Click(Sender: TObject);
begin
if UserDialog.Execute then
Label1.Caption := UserDialog.UserName
else
Label1.Caption := 'Error: no User ID entered';
end;
Here's a quick and simple solution:
So far, most of the interface section is written by Delphi itself, you only added the two short lines from step 4! (shown in bold): unit UserDlg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TUserDialog = class(TForm)
edUserName: TEdit;
btnOK: TBitBtn;
btnCancel: TBitBtn;
private
{ Private declarations }
public
{ Public declarations }
UserName: string; // added by you
function Execute: Boolean; // added by you
end;
var
UserDialog: TUserDialog;
Next, let's have a look at what you add to the implementation section -- it's surprisingly short: function TUserDialog.Execute: Boolean; begin Result := (ShowModal = mrOK); UserName := edUserName.Text; end; That's all! How does Delphi's magic work? The function Execute shows the UserDialog form in a "modal" way, that
means: the window will open on top of the other window(s) and the application does
not continue before UserDialog is closed. uses ..., ..., UserDlg; |
|
| Crash Course Delphi | Become member of the DelphiLand Club and get our Crash Course Delphi, plus the fully commented source code of numerous projects, plus guaranteed answers from our Q/A Forum. Membership is for life! |
TOP DelphiLand Club Membership DC Library Forum Forum Archives Crash Course Delphi Tips Source Code Downloads Links
© Copyright 1999-2006
Studiebureau Festraets