DELPHI: Basics
 


INPUT & OUTPUT

An integral property of computer hardware is the idea of input, processing and output - this is also used in software. When getting input variables are often used.

Input is usually done using the following components:
Edit
RichEdit
Memo
RichEdit
MaskEdit
StringGrid

Output is usually done using the following components:
Label
Panel
Memo
ListBox
RichEdit
StringGrid


Input and output from windows created during runtime

a) ShowMessage
• This calls up a small window that can be used to give the user extra information.
• The only parameter (value typed in by programmer) is the message that needs to be displayed.
• It usually uses the name of the project file as form caption.
• An example of coding would be:
ShowMessage('This is a ShowMessage!');

b) InputBox
• This dialog box allows the user to enter data that can be used in the program.
• The coding for an InputBox requires the following:
StringResult := InputBox(‘Window caption, ‘Prompt’, ‘Default value’);
• For example to enter data into the string variable sName and then transfer this to a label:

procedure TForm1.Button1Click(Sender: TObject);
var
  sName : string;
begin
  sName := InputBox('Name', 'Enter your name', '');
  lblName.Caption := sName;
end;

c) MessageDlg (Message Dialog box)
• Message Dialog boxes are used to provide the user with certain options or warnings and let the user then accept the message or make decision.
• This is often used to display errors or ask whether a user wants to save a file or exit the program or not.
• The code structure for a MessageDlg:
MessageDlg(StringDisplayed, MessageType, Buttons, HelpTopic);
• Here are three examples of the usage of the MessageDlg:

MessageDlg('Invalid input!', mtWarning, [mbOK],0);

if MessageDlg('This is an error', mtError, [mbOK, mbAbort],0) = mrOK then
  lblOutput.caption := 'User pressed OK'
else
  lblOutput.caption := 'User pressed Abort';

if MessageDlg('Do you want to exit', mtConfirmation, [mbYes, mbNo],0) = mrYes then
  Application.Terminate;
{Close form with Form1.Close}

Message types: mtWarning, mtError, mtInformation, mtConfirmation, mtCustom.

Button types: mbYes, mbNo, mbCancel, mbHelp, mbAbort, mbRetry, mbIgnore, mbAll. (There are also groupings such as: mbYesNoCancel, mbOKCancel and mbAbortRetryIgnore.)

 


Back to Delphi Basics site




Return to Home Page

© JAK Olivier (2008)

Website: http://www.jako.nom.za/
E-mail: olivier@teachitza.com