|
Thursday, November 22, 2007
Add a Check Box to a standard dialog box
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;
Tuesday, November 20, 2007
Get Default Printer Name
~~~~~~~~~~~~~~~~~~~~~~~~~
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
Handle the Edit1's OnChange event as:
The Perform method sends the specific LB_SELECTSTRING message directly to ListBox1.
Wednesday, November 14, 2007
Add Row Number In DBGrid
1. create new blank field in dbgrid
2. rename the title with 'No'
3. put this code in OnDrawColumncell
4. Now your Grid has a row number
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DataSource1.DataSet.RecNo > 0 then
begin
if Column.Title.Caption = 'No' then
DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo));
end;
end;
Sunday, November 11, 2007
Drag'n'Drop nodes inside TreeView
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer) ;
var
___AnItem: TTreeNode;
___AttachMode: TNodeAttachMode;
___HT: THitTests;
begin
___if TreeView1.Selected = nilthen Exit;
___HT := TreeView1.GetHitTestInfoAt(X, Y) ;
___AnItem := TreeView1.GetNodeAt(X, Y) ;
___if (HT - [htOnItem, htOnIcon, htNowhere, htOnIndent]<> HT) then
___begin
______if (htOnItem in HT) or (htOnIcon in HT) then
_________AttachMode := naAddChild
______else if htNowhere in HT then
_________AttachMode := naAdd
______else if htOnIndent in HT then
_________AttachMode := naInsert;
______TreeView1.Selected.
______MoveTo(AnItem, AttachMode) ;
___end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Thursday, November 8, 2007
Mengetahui Jumlah Mapping Drive dalam Jaringan Komputer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function GetNetworkDriveMappings (SList: TStrings): integer;
var
____c: Char;
____ThePath: string;
____MaxNetPathLen: DWord;
begin
____SList.Clear;
____MaxNetPathLen := MAX_PATH;
____SetLength(ThePath, MAX_PATH) ;
____for c := 'A' to 'Z' do
____if WNetGetConnection(PChar('' + c + ':'), PChar(ThePath),MaxNetPathLen) = NO_ERROR then ____________sList.Add(c + ': ' + ThePath) ;
____Result := SList.Count;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tuesday, November 6, 2007
Change glyphs of TDBNavigator Buttons
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.FormCreate(Sender: TObject) ;
var
___i : Integer;
___tempGlyph : tBitmap;
begin
___tempGlyph :=TBitmap.Create;
___try
______tempGlyph.LoadFromResourceName(HInstance,'GoFirst') ;
______with DBNavigator1 do
______begin
_________for i := 0 to ControlCount - 1 do
____________if Controls[c] is TNavigateBtn then
____________with TNavigateBtn(Controls[c])
____________do begin
_______________case Index of
_______________nbFirst: Glyph := tempGlyph;
____________end;
_________end;
______end;
___finally
______tempGlyph.Free;
___end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Monday, November 5, 2007
Implementing OnMouseOver for Items in a TComboBox, with custom hints.
Here's how to get the caption of an item in a TComboBox as mouse hovers over an item when the ComboBox is in drop down state. Use this "trick" to get the object associated with the "pre-selected" item in a combo box, or to display a custom hint for each item, for example. | |||
When a TComboBox is in drop down state, and you move around the items with mouse, the item the mouse is over is "pre-selected" (colored in "clHighLight" color). If you ever wanted to get the text of that "pre-selected" item (to show a hint for this item, for example), you probably noticed that such a property does not exist. When a combo box is dropped down, its Items are displayed in a list box type of control. The VCL TListBox component does actually provide an OnMouseOver event, yet, this event will not fire for TComboBox's list box since the list box part of the combobox is not a VCL control. If you were lucky and the TComboBox's list box was TListBox, than you will have no problems to "get ListBox items as mouse hovers over them". TComboBox.Items OnMouseMoveIn order to get the text of the combo box item "under" the mouse, when the combo is in drop down state, you need to send some specific messages to the actual list box displayed. Your best bet is to place the code in the Application.OnIdle event handler since this event is fired when it is waiting for input from the user (not processing application's code).The code provided below is an example of how to get the name of the combo box and the text of the item the mouse hovers over. Firstly, we get the handle of the window under the mouse (WindowFromPoint), we check if the window is a combo box (GetClassName). Secondly, we get the index of the "pre-selected" item (by sending the LB_ITEMFROMPOINT message to the underlying list box). Next, if we have a valid item index, we get the text of the item by sending the LB_GETTEXT message. Finally, the combo box name and the item text are displayed in a TLabel component.
That's it. Tricky yet simple. In the sample application provided for download, there's also code that "activates" the ApplicationIdle procedure when the combo box fires its OnDropDown event; similary the Application.OnIdle is set to nil when the combo box fires the OnCloseUp event. TComboBox.Item custom hint messagesAs you can see from the screen shot, you can attach custom hint text for each combo box item. In general, a class TComboItemHint that derives from THintWindow is used to display custom hint messages for each item. The DoActivateHint procedure calls the ActivateHint method of the THintWindow. ActivateHint displays the hint window at the specified coordinates (where the mouse is).
|
Show any graphics format as Glyph on a SpeedButton
~~~~~~~~~~~~~~~~~~~~~~~~~
var
___bmp: TBitmap;
begin
___bmp:=TBitmap.Create;
___try
______bmp.Width := Image.Picture.Graphic.Width;
______bmp.Height := Image.Picture.Graphic.Height;
______bmp.Canvas.Draw(0, 0, Image.Picture.Graphic) ;
______BitBtn.Glyph:=bmp;
___finally
______bmp.Free;
___end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Thursday, November 1, 2007
How to set system wide Hot Key for a Delphi application
~~~~~~~~~~~~~~~~~~~~~~~~~
//In the main forms OnCreate
//handler assign the hotkey:
If not RegisterHotkey
(Handle, 1, MOD_ALT or MOD_SHIFT, VK_F9) Then
ShowMessage('Unable to assign Alt-Shift-F9 as hotkey.') ;
//In the main forms
//OnClose event remove the handler:
UnRegisterHotkey( Handle, 1 ) ;
//Add a handler for the
//WM_HOTKEY message to the form:
private // form declaration
Procedure WMHotkey( Var msg: TWMHotkey ) ;
message WM_HOTKEY;
Procedure TForm1.WMHotkey( Var msg: TWMHotkey ) ;
Begin
__If msg.hotkey = 1 Then
__Begin
____ If IsIconic( Application.Handle ) Then
______Application.Restore;
____BringToFront;
__End;
End;
~~~~~~~~~~~~~~~~~~~~~~~~~