Suppose you have a confirmation dialog of some kind, where the user can select a checkbox displayinfg "Don't show this message again"). When the user closes the dialog - program can store the state of the check box (checked or not checked) in a global variable - the next time you need to display this dialog - you simply don't show it. The idea of realization is:
1. Create a dialog using CreateMessageDialog
2.This function will return a form object with dialog
3. In this object we can add a checkbox
4. Show dialog using ShowModal
5. Check a result and process a state of the checkbox
6. Destroy the created checkbox and the dialog
procedure TForm1.Button1Click(Sender: TObject) ;
var AMsgDialog: TForm;
ACheckBox: TCheckBox;
begin
___AMsgDialog := CreateMessageDialog('This is a test message.', mtWarning, [mbYes, mbNo]) ;
___ACheckBox := TCheckBox.Create(AMsgDialog) ;
___with AMsgDialog do
___try
______Caption := 'Dialog Title' ;
______Height := 169;
______with ACheckBox do
______begin
_________Parent := AMsgDialog;
_________Caption := 'Don''t show me again.';
_________Top := 121;
_________Left := 8;
______end;
______if (ShowModal = ID_YES) then
______begin
______if ACheckBox.Checked then
_________//do if checked
______else
_________//do if NOT checked
______end;
___finally
______Free;
___end;
end;
|
Thursday, November 22, 2007
Tuesday, November 20, 2007
Get Default Printer Name
Here's how to get the name of the default printer on a computer:
~~~~~~~~~~~~~~~~~~~~~~~~~
uses Printers;
function GetDefaultPrinterName : string;
begin
___if (Printer.PrinterIndex > 0)then
___begin
______Result := Printer.Printers[Printer.PrinterIndex];
___end else
___begin
______Result := '';
___end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
uses Printers;
function GetDefaultPrinterName : string;
begin
___if (Printer.PrinterIndex > 0)then
___begin
______Result := Printer.Printers[Printer.PrinterIndex];
___end else
___begin
______Result := '';
___end;
end;
Saturday, November 17, 2007
Incremental Search for the TListBox Delphi Control

The TListBox Delphi control displays a collection of items in a scrollable list. Items can be selected by clicking on an item, the ItemIndex property gets or sets the index of the selected item. Incremental Searching for a ListBoxImagine a list box with a huge number of (unsorted) items. Finding the one user wants to select might turn into a nightmare. Let's provide the user with an option to immediately locate the item in the list box by adding incremental search functionality. Drop a TEdit and a TListBox on a form. Leave the default names: "Edit1" and "ListBox1".
Handle the Edit1's OnChange event as:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TListBoxSearchForm.Edit1Change(Sender: TObject) ;
const indexStart = -1;
var search : array[0..128] of Char;
begin
___//make sureLength(Edit1.Text) <= 128
___StrPCopy(search, Edit1.Text) ;
___ListBox1.ItemIndex := ListBox1.Perform(LB_SELECTSTRING, indexStart, LongInt(@search)) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The StrPCopy
RTL function copies Edit1.Test string value into a null-terminated string variable "search".The Perform method sends the specific LB_SELECTSTRING message directly to ListBox1.
Subscribe to:
Posts (Atom)