Delphi Stuff
Delphi Shortcuts
Here is a list of the most frequently used shortcuts by Delphi programmers
Ctrl+Space
Code Completion (window resizeable/sortable)
Video
Ctrl+Shift+A
Find Unit - Add to Implementation or Interface
Ctrl+Shift+C
Class Code Completion at Cursor
Ctrl+Shift+V
Declare Vaiable
Ctrl+Shift+D
Declare Field
Ctrl+Shift+Space
Code Parameter Hints (invoke tooltip help)
Video
Ctrl+J
Code Templates (window resizeable)
Video
Ctrl+Shift+J
Sync Edit
Video
Ctrl+Left Click
Alt+Up Arrow
Code Browsing (requires $YD)
Ctrl+Shift+Up Arrow
Ctrl+Shift+Dn Arrow
Code Jumping Between Declaration/Implementation
Alt+Left Click+Drag
Select Block
Tab
Indent Selected Code
Indent Selected Block
Shift+Tab
Outdent Selected Code
Outdent Selected Block
Ctrl+D
Format Selected Code
Format Selected Block
F9
Run
Ctrl+Shift+F9
Run Without Debugging
F4
Run To Cursor (Build Debug)
Ctrl+F9
Compile
F5
Set/Remove Breakpoint
Video
F7
Trace Into
F8
Step Over
Ctrl+F2
Program Reset
Delphi Miscellaneous Tips
→ Display message in "Event Log"
{$MESSAGE '*** ATTENTION *** - Your message goes here.'}
→ Move to next control
Perform(WM_NEXTDLGCTL, 0, 0); // move to next control
→ Delphi Directives
{$IFDEF DEBUG}
DoDevSetup;
{$ELSE}
DoProdSetup;
{$ENDIF}
Enum <==> String
uses RTTI;
type
TAlign = (alNone, alTop, alBottom, alLeft, alRight, alClient, alCustom); procedure frmMainForm.FormCreate(Sender: TObject); var sAlign: string; eAlign: TAlign; begin //Enum to string sAlign := TRttiEnumerationType.GetName(eAlign); //string to enum eAlign := TRttiEnumerationType.GetValue<TAlign>(sAlign); end;
Popup Menu @ Cursor
uses System.UITypes;
type
frmMainForm= class(TForm)
btnOk: TButton;
pmnuEnregistrer: TPopupMenu;
end;
procedure frmMainForm.btnOkClick(Sender: TObject);
var
pntCursor: TPoint;
begin
if GetCursorPos(pntCursor) then
pmnuEnregistrer.Popup(pntCursor.X, pntCursor.Y);
end;
Delphi TStringList
Example 1
var slDelphi: TStrings; begin slDelphi := TStringList.Create; // Add string values... slDelphi.Add('Delphi'); slDelphi.Add('2.01'); // slDelphi.Strings[0] will return 'Delphi' MessageDlg(slDelphi.Strings[0], mtInformation, [mbOk], 0); slDelphi.Free; end;
Example 2
var slDelphi: TStrings; begin slDelphi := TStringList.Create; // set string values... slDelphi.Values['Program') := 'Delphi'; slDelphi.Add('Version') := '2.01'; // slDelphi.Values['Program'] will return 'Delphi' MessageDlg(slDelphi.Values['Program'], mtInformation, [mbOk], 0); slDelphi.Free; end;
Example 3
var slDelphi: TStrings; begin slDelphi := TStringList.Create; // set string values... slDelphi.Add('Program=Delphi'); slDelphi.Add('Version=2.01'); // slDelphi.Values['Program'] will return 'Delphi' MessageDlg(slDelphi.Values['Program'], mtInformation, [mbOk], 0); slDelphi.Free; end;