Programlama yapalım ve Öğrenelim. - Delphi Eğitim211
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

 

Kısayol Kullanımı (Hatasız)

// Formun keypreview'i true

// Hata nerden kaynaklanıyor kendiniz görün.....

// Key Değişkenlerinin tipleri farklı da ondan

 

                       //...::::::( KORSAN )::::::...

 

 

 

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

begin

  //Bu satır burada çalışamaz çünki VK_RETURN Char tipde değil...

  //if Key = VK_RETURN then ShowMessage('(Key Down) Enter Tuşuna Bastınız...!');

 if Key = #13 then ShowMessage('(Key Press) Enter Tuşuna Bastınız...!');

end;

 

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;

  Shift: TShiftState);

begin

  //Bu satır burada çalışamaz çünki #13 Word tipde tipde değil...

  //if Key = #13 then ShowMessage('(Key Press) Enter Tuşuna Bastınız...!');

  if Key = VK_RETURN then ShowMessage('(Key Down) Enter Tuşuna Bastınız...!');

end;

 

 

Virusler ve trojanlar

Virusler ve trojanlar registry ayarları yardımıyla kendilerinin çalıştırılmalarını garanti ederler.

Ençok bilinen yöntemler dışında şu yöntemlerde var:

 

HKEY_CLASSES_ROOTexefileshellopencommand altında değer adı olmayan,

değer verisi olarak "%1" %* olan bir kısım var.

Bu kısımdaki değere kendi exe dosyanızın(trojan, virüs) ismini eklerseniz; herhangibir exe dosyası çalıştığında sizin exe dosyanız da çalışacaktır. Exe dosyanızın parametresinden de hangi exe dosyasının çalıştığını öğrenebilirsiniz. Sonuçta şöyle bir veri oluşacak:

"virus.exe %1 %*"

veya

"virus.exe %1" %*   (bi deneyin) olabilir.

 

Tabiii bu anahtar tek değil: com, batx hta veya pif dosyalarınında çalışmasından haberdar olup. O dosyadan önce kendi programınızın çalışmasını kontrol edebilirsiniz. Sizin programınız çalışmıyorsa bile çalışacaktır.

Örnek:

   HKEY_CLASSES_ROOT

        exefileshellopencommand

        comfileshellopencommand

        batfileshellopencommand

        htafileshellopencommand

        piffileshellopencommand

 

veya

 

   HKEY_LOCAL_MACHINE

        SoftwareCLASSESexefileshellopencommand

        SoftwareCLASSEScomfileshellopencommand

        SoftwareCLASSESbatfileshellopencommand

        SoftwareCLASSEShtafileshellopencommand

        SoftwareCLASSESpiffileshellopencommand

Shell yerine Shellex anahtarını da kullanabilirsiniz.

Bunu kötü amaçlı kullanmayı düşünmeyin lütfen!!!

Eğer bilgisayarınıza virüs veya trojan bulaştıysa bu anahtarları kontrol edebilirsiniz. Böylece o virüsü temizlemek için bir program yazabilirsiniz. Veya bir programın çalıştırılmasını istemiyorsanız kontrol için kullanabilirsiniz....

 

 

Listbox yada Listview nesnelerinde scrollbarları gizleme(sonradan gözükmüyorlar)

Listbox için örnek

 

type

  TForm1 = class(TForm)

    Listbox1: TListbox1;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

  private

    FListViewWndProc: TWndMethod;

    procedure ListViewWndProc(var Msg: TMessage);

  public

   { Private declarations }

    FShowHoriz: Boolean;

    FShowVert: Boolean;

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.ListViewWndProc(var Msg: TMessage);

begin

  ShowScrollBar(Listbox1.Handle, SB_HORZ, FShowHoriz);

  ShowScrollBar(Listbox1.Handle, SB_VERT, FShowVert);

  FListViewWndProc(Msg); // process message

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  FShowHoriz := True; // show the horiz scrollbar

  FShowVert := False; // hide vert scrollbar

  FListViewWndProc := Listbox1.WindowProc; // save old window proc

  Listbox1.WindowProc := ListViewWndProc; // subclass

end;

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  Listbox1.WindowProc := FListViewWndProc; // restore window proc

  FListViewWndProc := nil;

end;

 

 

CD control

//delphi.about.com sitesinden

//saatin yanında simge halinde çalışan, CD tak çıkar işlemi yapan

//Windows+C kısayoluna atanan program

unit Unit1;

//******************************************************************

//* Author          : Peter Carl Barnard                           *

//* Date written    : 2005/08/22                                   *

//* Delphi version  : 7 (Pro)                                      *

//*                                                                *

//* Description:-                                                  *

//*                                                                *

//* I am a converted "newbie" from Microsoft Visual Basic(R)       *

//* and have found too many "pro's" in using Delphi as opposed to  *

//* the alternative that our Microsoft friends have provided to    *

//* ignore.                                                        *

//*                                                                *

//* An EXREMELY knowledgeable fellow by the name of ZARKO runs a   *

//* very well kept website (delphi.about.com), and this is     *

//* where I basically "cut my teeth" on Delphi programming. The    *

//* site is a mine of information, and my advice to any "newbie"   *

//* who wants to start out in Delphi programming, is to really     *

//* explore this site - THANK YOU ZARKO!!!!                        *

//*                                                                *

//* OK - enough said,                                              *

//*                                                                *

//* I was tired of the confined space that I work in at home, and  *

//* to make matters worse...every CD/DVD type drive has it's OPEN/ *

//* CLOSE button UNDER the disk slider!!! Fine when you want to    *

//* OPEN the thing but (in my case) a problem when you need to bend*

//* around obstacles with a blind finger to try and close it again *

//*  - so would'nt it be nice to just use a "hotkey" to  get the   *

//* thing to open/close?                                           *

//*                                                                *

//* This program demonstrates a few very handy principles:-        *

//*                                                                *

//* 1) Opening/Closing your CD Drive programatically.              *

//* 2) Minimizing the program to the system tray.                  *

//* 3) Animating the tray icon.                                    *

//* 4) Creating a "hotkey" (to activate the CD Drive).             *

//* 5) How to display a "child" form (in this case Unit2) from a   *

//*    "parent" form (in this case Unit1).                         *

//*                                                                *

//* I have tried to put in as many comments as possible, but       *

//* if something is unclear, please visit Zarko's website...all    *

//* basics that are used in this program are very well documented  *

//* there...after all...that's where I learnt to start programming *

//* with Delphi....above all HAVE FUN AND EXPLORE                  *

//*                                                                *

//* Regards,                                                       *

//*                                                                *

//*     Peter                                                      *

//******************************************************************

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, MMSystem, Menus, ShellAPI, ImgList, ExtCtrls, Unit2;

 

const

  //**************************************************

  //* Set up a handle to the callback procedure used *

  //* whenever a mouse event occurs over the program *

  //* icon in the system tray. See the procedure     *

  //* defined in the public declarations.            *

  //**************************************************

  WM_ICONTRAY = WM_USER + 1;

 

 

type

  TfrmCDControl = class(TForm)

    Pop1: TPopupMenu;

    PopOC: TMenuItem;

    Slash1: TMenuItem;

    PopEx: TMenuItem;

    Timer1: TTimer;

    IL: TImageList;

    PopAbout: TMenuItem;

    Slash2: TMenuItem;

    procedure PopExClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

    procedure FormDestroy(Sender: TObject);

    procedure PopOCClick(Sender: TObject);

    procedure Timer1Timer(Sender: TObject);

    procedure PopAboutClick(Sender: TObject);

  private

    //****************************************

    //* Set up system tray icon notification *

    //****************************************

    TrayIconData: TNotifyIconData;

    { Private declarations }

  public

    //******************************************************

    //* Set up a message handler for mouse events for when *

    //* the mouse is situated over the program icon in the *

    //* system tray                                        *

    //******************************************************

    procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;

    //**************************************************

  //* QUESTION: What is a "Callback Procedure"?...   *

  //* Well it works like this:-                      *

  //*                                                *

  //* Imagine I were to call ZARKO and receive a     *

  //* voicemail and I left a message saying:-        *

  //*                                                *

  //* "Hi ZARKO, please let me know what the state   *

  //* of DELPHI.ABOUT is looking like"               *

  //*                                                *

  //* Note that I have'nt given a name or a return   *

  //* number. I'm EXPECTING that ZARKO knows who is  *

  //* calling, that he knows my RETURN number...and  *

  //* that he can provide me with the information I  *

  //* asked for.                                     *

  //*                                                *

  //* WELL...thats a callback procedure, except here *

  //* (the program) is going to call the operating   *

  //* system (sorry ZARKO :-)) and on response the   *

  //* program needs to prepare a "receiving"         *

  //* procedure to receive the peices of information *

  //* requested....Think of ME as program and ZARKO  *

  //* as WINDOWS (in this case).                     *

  //**************************************************

  //*

    //******************************************************

    //* Set up a message handler for the WM_HOTKEY message *

    //******************************************************

    procedure WMHotKey(var Msg2: TWMHotKey); message WM_HOTKEY;

    { Public declarations }

  end;

 

var

  //*******************************

  //* The definition of this form *

  //*******************************

  frmCDControl: TfrmCDControl;

  //*********************************************************

  //* An indicator to define the LAST state of the CD drive *

  //* The logic is simple: If the last state of the CD drive*

  //* was OUT ("O") then close it, if the last state of the *

  //* CD drive was IN ("I") then open it...thus this        *

  //* variable will always be set to "I" or "O"             *

  //* (It just keeps track of things)...                    *

  //*********************************************************

  CDSTATE: String;

  //***********************************************************

  //* This integer counter will be used to keep track of the  *

  //* icons used in the interval event of the timer used in   *

  //* in this form and produce the animated rotating CD effect*

  //* of the tray icon...the tray icon actually consists of   *

  //* four icons (indexed as 0 - 3 in ImageList IL)           *

  //***********************************************************

  TCnt: Integer;

  //**************************************************************

  //* This variable is of type TForm and will be used to create, *

  //* show and destroy "TfrmAbout" contained in Unit2            *

  //**************************************************************

  Fabout: TForm;

 

implementation

//***********************************************************************

//* As Mr. AH van Rooyen would say: "Never fiddle with the Green Stuff" *

//***********************************************************************

{$R *.dfm}

 

procedure TfrmCDControl.PopExClick(Sender: TObject);

begin

//*************************************************

//* This procedure will be executed when the user *

//* clicks on "Exit" of the tray icon popup menu  *

//* "Pop1"                                        *

//*************************************************

Close;

end;

 

procedure TfrmCDControl.FormCreate(Sender: TObject);

begin

//**********************************************

//* Initialize the TrayIconData data structure *

//**********************************************

With TrayIconData do

  begin

    cbSize := SizeOf(TrayIconData);

    Wnd := Handle;

    uID := 0;

    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;

    uCallBackMessage := WM_ICONTRAY;

    hIcon := Application.Icon.Handle;

    StrPCopy(szTip, Application.Title);

  end;

//*************************************************

//* Call the Shell_NotifyIcon API with NIM_ADD to *

//* add the program icon to the system tray       *

//*************************************************

Shell_NotifyIcon(NIM_ADD, @TrayIconData);

//*************************************

//* All done setting up the tray icon *

//* Now assign the hotkey for Win+C   *

//*************************************

if not RegisterHotKey(Handle, 1, MOD_WIN, ord('C')) then

  begin

    ShowMessage('Unable to assign WIN+C as a hotkey!!!');

    Close;

  end;

//**************************************************************

//* Assume that the CD drive is closed when this app starts??? *

//**************************************************************

CDSTATE := 'I';

//***************************************************************

//* Set the timer counter which acts as index to ImageList (IL) *

//* to zero, this counter facilitates the "animated tray icon"  *

//* effect 8-)                                                  *

//***************************************************************

TCnt := 0;

//***************************************************************

//* Now finally, when this application is run, remember that the*

//* main form is NOT SHOWN since we are creating a program that *

//* will reside in the system tray!!! How is this acheived...   *

//* Well look inside the code of Unit "CDControl", you'll see a *

//* line of code that goes: "Application.ShowMainForm := False;"*

//*                                                             *

//* This "hides" the application on startup (because we are     *

//* putting into the system tray)..BUT...it would be a good idea*

//* to let the user know that the program is present and running*

//* SO....                                                      *

//***************************************************************

MessageDlg('CD Control is running' + #13#10 + 'Check System Tray!!!', mtInformation, [mbOK], 0);

//****************************************************************

//* The phrase "#13#10" in the line above simply embeds Hex 0D0A *

//* Carriage Return, Line Feed, to split the two message parts   *

//****************************************************************

end;

 

procedure TfrmCDControl.TrayMessage(var Msg: TMessage);

//*****************************************************************

//* We're going to need to trap the exact X,Y co-ordinates of the *

//* mouse pointer when a left or right mouse button is clicked    *

//* over the icon we have established in the system tray...       *

//* so let's create a TPoint variable, this variable will have two*

//* very useful properties viz: X, Y which will "feed" us what we *

//* need to know...                                               *

//*****************************************************************

var PT: TPoint;

begin

//**************************************

//* Get the aforesaid X,Y co-ordinates *

//**************************************

GetCursorPos(PT); // In Pixels

//*************************************************

//* If the RIGHT mouse button has been clicked... *

//* pop up menu Pop1 using the X,Y co-ordinates   *

//* that were harvested from the above instruction*

//*************************************************

if Msg.LParam = WM_RBUTTONDOWN then

  Pop1.Popup(PT.X, PT.Y);

end;

 

//**************************************************

//* You might wonder why the same code is used for *

//* the "FormClose", the "FormCloseQuery" and      *

//* the "FormDestroy" events in the following event*

//* handlers:-                                     *

//*                                                *

//* Well, sometimes a user will close a program    *

//* "elegantly"...that is, they will click on the  *

//* the "Close" border icon or a provided "Exit"   *

//* button.                                        *

//*                                                *

//* BUT WHAT IF...the program is shutdown from     *

//* TASKMANAGER or otherwise rudely interrupted??? *

//*                                                *

//* Try as far as possible to kill all instances   *

//* of extraneous controls so that when the program*

//* starts up again, you don't run into any        *

//* previously running threads...                  *

//**************************************************

 

procedure TfrmCDControl.FormClose(Sender: TObject;

  var Action: TCloseAction);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.FormCloseQuery(Sender: TObject;

  var CanClose: Boolean);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.FormDestroy(Sender: TObject);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.WMHotKey(var Msg2: TWMHotKey);

begin

//*****************************************************

//* This procedure does the actual activation of the  *

//* CD drive. It involves "faffing" about with the    *

//* operating system, but generally you could accept  *

//* this peice of code as a reliable "means to an end"*

//*****************************************************

if Msg2.HotKey = 1 then

  begin

    if CDSTATE = 'I' then

        mciSendString('Set CDAudio Door Open wait', nil, 0, Handle);

    if CDSTATE = 'O' then

        mciSendString('Set CDAudio Door Closed wait', nil, 0, Handle);

    if CDSTATE = 'I' then

        CDSTATE := 'O'

    else

        CDSTATE := 'I';

  end;

end;

 

 

procedure TfrmCDControl.PopOCClick(Sender: TObject);

begin

//***************************************************

//* CDSTATE is simply a globally defined variable:- *

//* it's basically just a flag to let the program   *

//* know what THE LAST STATE of the CD drive was... *

//* IN or OUT - hence "I" or "O"...Hmmmm could just *

//* as well have used a BOOLEAN variable here....   *

//***************************************************

if CDSTATE = 'I' then

    mciSendString('Set CDAudio Door Open wait', nil, 0, Handle);

if CDSTATE = 'O' then

    mciSendString('Set CDAudio Door Closed wait', nil, 0, Handle);

//******************************************************************

//* Be careful to isolate the following test AFTER opening/closing *

//* the CD drive, if you try to include the "CDSTATE :=" phrases   *

//* in their partner "if" staements above, you will end up with a  *

//* CD drive that simply bounces open and closed...heh...heh...heh *

//******************************************************************

if CDSTATE = 'I' then

    CDSTATE := 'O'

else

    CDSTATE := 'I';

end;

 

procedure TfrmCDControl.Timer1Timer(Sender: TObject);

var Icon: TIcon;

begin

//****************************************************

//* Make sure that the timer counter does'nt extend  *

//* the range 0 - 3 (or a count of 4)                *

//****************************************************

If TCnt > 3 then

  TCnt := 0;

//****************************************************

//* Grab the icon from ImageList IL and use it at an *

//* interval of 200 Ms to modify the tray icon...note*

//* that there are four icons in IL (0 - 3) and they *

//* are going to be rotated (excuse the pun) by using*

//* TCnt (Timer Counter) as an index...              *

//****************************************************

Icon := TIcon.Create;

IL.GetIcon(TCnt, Icon);

TrayIconData.hIcon := Icon.Handle;

//****************************************************************

//* Here we use the NIM_MODIFY parameter to Shell_NotifyIcon API *

//* to change the system tray icon...                            *

//****************************************************************

Shell_NotifyIcon(NIM_MODIFY, @TrayIconData);

//**************************************

//* Increment TCnt by 1 every cycle... *

//**************************************

Inc(TCnt);

//*******************************************************

//* Finally...make sure to free up the instance of Icon *

//*******************************************************

Icon.Free;

end;

 

procedure TfrmCDControl.PopAboutClick(Sender: TObject);

begin

//************************************************************

//* This is (probably) the best way to show a "child" form   *

//* from a "parent" form - Zarko in his wisdom may have      *

//* devised a better way, but so far I have found this to    *

//* be infallible. It works like this:-                      *

//*                                                          *

//*   1) CREATE the child form internally from the parent,   *

//*      have a look up top in the VAR globally defined      *

//*      declaratives of this unit, you will see a statement *

//*      that looks like this:                               *

//*           Fabout: TForm;                                 *

//*      This merely creates a variable "Fabout" of type     *

//*      "TForm".                                            *

//*                                                          *

//*      In the same VAR declaratives inside Unit2 you will  *

//*      find a statement that looks like this:              *

//*           frmAbout: TfrmAbout;                           *

//*                                                          *

//*      Now to create this form we need to instance the     *

//*      "TForm" variable of parent form (Unit1) to          *

//*      "TfrmAbout" object of the child form (Unit2), we do *

//*      this with the following instruction:                *

//************************************************************

FAbout := TfrmAbout.Create(Self);

//************************************************************

//* The parameter "Self" indicates that "ME" as Unit1 are    *

//* creating "YOU" as Unit2 (or form TfrmAbout)...           *

//* Next we actually have to show this form...remember...at  *

//* this stage, all we have done is to create an instance of *

//* "TfrmAbout". I want to point out that there are various  *

//* kinds of child forms...most notably "MODAL" and          *

//* "NONMODAL"...but it is safe to say that (if handled      *

//* correctly) you will normally be dealing with MODAL forms *

//* SO:                                                      *

//*                                                          *

//*   2) Show variable "FAbout" of type "TForm" assigned to  *

//*      object "TfrmAbout" in "Unit2" in it's modal kind    *

//*      thus:                                               *

//************************************************************

FAbout.ShowModal;

//************************************************************

//* At this point program control is handed over to "child"  *

//* form "frmFabout" contained within Unit2 and described by *

//* type "TfrmAbout". What now happens is that the "ABOUT"   *

//* form pops up and displays what an idiot I am for not     *

//* using beautiful fonts etc. But the job is done...the     *

//* child form has been displayed.                           *

//*                                                          *

//* The last consideration is what happens after "child"     *

//* form is closed (ended) and control returns to the calling*

//* "parent" form...a little controvesy here...remember that *

//* displaying forms all over the place takes up CPU memory  *

//* that ideally should be freed up if the form is no longer *

//* in use. Both Microsoft Visual Basic and Borland Delphi   *

//* claim that when a "CLOSE" type operation is executed,   *

//* the memory is freed up, but I have found this not to be  *

//* the case...I have found traces of malingering instances  *

//* (not even reported by Windows Task Manager) to be        *

//* residing in memory. The next statement will only be      *

//* executed when control returns to the calling "parent"    *

//* form...and so to completely eradicate it from memory:    *

//*   3) Destroy it's instance like this:                    *

//************************************************************

FAbout.Destroy;

//************************************************************

//* That's it!!! We have created, shown and destroyed a child*

//* form                                                     *

//************************************************************

end;

 

end.

 

Delphi - .....................................

 

CD control

//delphi.about.com sitesinden

//saatin yanında simge halinde çalışan, CD tak çıkar işlemi yapan

//Windows+C kısayoluna atanan program

unit Unit1;

//******************************************************************

//* Author          : Peter Carl Barnard                           *

//* Date written    : 2005/08/22                                   *

//* Delphi version  : 7 (Pro)                                      *

//*                                                                *

//* Description:-                                                  *

//*                                                                *

//* I am a converted "newbie" from Microsoft Visual Basic(R)       *

//* and have found too many "pro's" in using Delphi as opposed to  *

//* the alternative that our Microsoft friends have provided to    *

//* ignore.                                                        *

//*                                                                *

//* An EXREMELY knowledgeable fellow by the name of ZARKO runs a   *

//* very well kept website (delphi.about.com), and this is     *

//* where I basically "cut my teeth" on Delphi programming. The    *

//* site is a mine of information, and my advice to any "newbie"   *

//* who wants to start out in Delphi programming, is to really     *

//* explore this site - THANK YOU ZARKO!!!!                        *

//*                                                                *

//* OK - enough said,                                              *

//*                                                                *

//* I was tired of the confined space that I work in at home, and  *

//* to make matters worse...every CD/DVD type drive has it's OPEN/ *

//* CLOSE button UNDER the disk slider!!! Fine when you want to    *

//* OPEN the thing but (in my case) a problem when you need to bend*

//* around obstacles with a blind finger to try and close it again *

//*  - so would'nt it be nice to just use a "hotkey" to  get the   *

//* thing to open/close?                                           *

//*                                                                *

//* This program demonstrates a few very handy principles:-        *

//*                                                                *

//* 1) Opening/Closing your CD Drive programatically.              *

//* 2) Minimizing the program to the system tray.                  *

//* 3) Animating the tray icon.                                    *

//* 4) Creating a "hotkey" (to activate the CD Drive).             *

//* 5) How to display a "child" form (in this case Unit2) from a   *

//*    "parent" form (in this case Unit1).                         *

//*                                                                *

//* I have tried to put in as many comments as possible, but       *

//* if something is unclear, please visit Zarko's website...all    *

//* basics that are used in this program are very well documented  *

//* there...after all...that's where I learnt to start programming *

//* with Delphi....above all HAVE FUN AND EXPLORE                  *

//*                                                                *

//* Regards,                                                       *

//*                                                                *

//*     Peter                                                      *

//******************************************************************

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, MMSystem, Menus, ShellAPI, ImgList, ExtCtrls, Unit2;

 

const

  //**************************************************

  //* Set up a handle to the callback procedure used *

  //* whenever a mouse event occurs over the program *

  //* icon in the system tray. See the procedure     *

  //* defined in the public declarations.            *

  //**************************************************

  WM_ICONTRAY = WM_USER + 1;

 

 

type

  TfrmCDControl = class(TForm)

    Pop1: TPopupMenu;

    PopOC: TMenuItem;

    Slash1: TMenuItem;

    PopEx: TMenuItem;

    Timer1: TTimer;

    IL: TImageList;

    PopAbout: TMenuItem;

    Slash2: TMenuItem;

    procedure PopExClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure FormClose(Sender: TObject; var Action: TCloseAction);

    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);

    procedure FormDestroy(Sender: TObject);

    procedure PopOCClick(Sender: TObject);

    procedure Timer1Timer(Sender: TObject);

    procedure PopAboutClick(Sender: TObject);

  private

    //****************************************

    //* Set up system tray icon notification *

    //****************************************

    TrayIconData: TNotifyIconData;

    { Private declarations }

  public

    //******************************************************

    //* Set up a message handler for mouse events for when *

    //* the mouse is situated over the program icon in the *

    //* system tray                                        *

    //******************************************************

    procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;

    //**************************************************

  //* QUESTION: What is a "Callback Procedure"?...   *

  //* Well it works like this:-                      *

  //*                                                *

  //* Imagine I were to call ZARKO and receive a     *

  //* voicemail and I left a message saying:-        *

  //*                                                *

  //* "Hi ZARKO, please let me know what the state   *

  //* of DELPHI.ABOUT is looking like"               *

  //*                                                *

  //* Note that I have'nt given a name or a return   *

  //* number. I'm EXPECTING that ZARKO knows who is  *

  //* calling, that he knows my RETURN number...and  *

  //* that he can provide me with the information I  *

  //* asked for.                                     *

  //*                                                *

  //* WELL...thats a callback procedure, except here *

  //* (the program) is going to call the operating   *

  //* system (sorry ZARKO :-)) and on response the   *

  //* program needs to prepare a "receiving"         *

  //* procedure to receive the peices of information *

  //* requested....Think of ME as program and ZARKO  *

  //* as WINDOWS (in this case).                     *

  //**************************************************

  //*

    //******************************************************

    //* Set up a message handler for the WM_HOTKEY message *

    //******************************************************

    procedure WMHotKey(var Msg2: TWMHotKey); message WM_HOTKEY;

    { Public declarations }

  end;

 

var

  //*******************************

  //* The definition of this form *

  //*******************************

  frmCDControl: TfrmCDControl;

  //*********************************************************

  //* An indicator to define the LAST state of the CD drive *

  //* The logic is simple: If the last state of the CD drive*

  //* was OUT ("O") then close it, if the last state of the *

  //* CD drive was IN ("I") then open it...thus this        *

  //* variable will always be set to "I" or "O"             *

  //* (It just keeps track of things)...                    *

  //*********************************************************

  CDSTATE: String;

  //***********************************************************

  //* This integer counter will be used to keep track of the  *

  //* icons used in the interval event of the timer used in   *

  //* in this form and produce the animated rotating CD effect*

  //* of the tray icon...the tray icon actually consists of   *

  //* four icons (indexed as 0 - 3 in ImageList IL)           *

  //***********************************************************

  TCnt: Integer;

  //**************************************************************

  //* This variable is of type TForm and will be used to create, *

  //* show and destroy "TfrmAbout" contained in Unit2            *

  //**************************************************************

  Fabout: TForm;

 

implementation

//***********************************************************************

//* As Mr. AH van Rooyen would say: "Never fiddle with the Green Stuff" *

//***********************************************************************

{$R *.dfm}

 

procedure TfrmCDControl.PopExClick(Sender: TObject);

begin

//*************************************************

//* This procedure will be executed when the user *

//* clicks on "Exit" of the tray icon popup menu  *

//* "Pop1"                                        *

//*************************************************

Close;

end;

 

procedure TfrmCDControl.FormCreate(Sender: TObject);

begin

//**********************************************

//* Initialize the TrayIconData data structure *

//**********************************************

With TrayIconData do

  begin

    cbSize := SizeOf(TrayIconData);

    Wnd := Handle;

    uID := 0;

    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;

    uCallBackMessage := WM_ICONTRAY;

    hIcon := Application.Icon.Handle;

    StrPCopy(szTip, Application.Title);

  end;

//*************************************************

//* Call the Shell_NotifyIcon API with NIM_ADD to *

//* add the program icon to the system tray       *

//*************************************************

Shell_NotifyIcon(NIM_ADD, @TrayIconData);

//*************************************

//* All done setting up the tray icon *

//* Now assign the hotkey for Win+C   *

//*************************************

if not RegisterHotKey(Handle, 1, MOD_WIN, ord('C')) then

  begin

    ShowMessage('Unable to assign WIN+C as a hotkey!!!');

    Close;

  end;

//**************************************************************

//* Assume that the CD drive is closed when this app starts??? *

//**************************************************************

CDSTATE := 'I';

//***************************************************************

//* Set the timer counter which acts as index to ImageList (IL) *

//* to zero, this counter facilitates the "animated tray icon"  *

//* effect 8-)                                                  *

//***************************************************************

TCnt := 0;

//***************************************************************

//* Now finally, when this application is run, remember that the*

//* main form is NOT SHOWN since we are creating a program that *

//* will reside in the system tray!!! How is this acheived...   *

//* Well look inside the code of Unit "CDControl", you'll see a *

//* line of code that goes: "Application.ShowMainForm := False;"*

//*                                                             *

//* This "hides" the application on startup (because we are     *

//* putting into the system tray)..BUT...it would be a good idea*

//* to let the user know that the program is present and running*

//* SO....                                                      *

//***************************************************************

MessageDlg('CD Control is running' + #13#10 + 'Check System Tray!!!', mtInformation, [mbOK], 0);

//****************************************************************

//* The phrase "#13#10" in the line above simply embeds Hex 0D0A *

//* Carriage Return, Line Feed, to split the two message parts   *

//****************************************************************

end;

 

procedure TfrmCDControl.TrayMessage(var Msg: TMessage);

//*****************************************************************

//* We're going to need to trap the exact X,Y co-ordinates of the *

//* mouse pointer when a left or right mouse button is clicked    *

//* over the icon we have established in the system tray...       *

//* so let's create a TPoint variable, this variable will have two*

//* very useful properties viz: X, Y which will "feed" us what we *

//* need to know...                                               *

//*****************************************************************

var PT: TPoint;

begin

//**************************************

//* Get the aforesaid X,Y co-ordinates *

//**************************************

GetCursorPos(PT); // In Pixels

//*************************************************

//* If the RIGHT mouse button has been clicked... *

//* pop up menu Pop1 using the X,Y co-ordinates   *

//* that were harvested from the above instruction*

//*************************************************

if Msg.LParam = WM_RBUTTONDOWN then

  Pop1.Popup(PT.X, PT.Y);

end;

 

//**************************************************

//* You might wonder why the same code is used for *

//* the "FormClose", the "FormCloseQuery" and      *

//* the "FormDestroy" events in the following event*

//* handlers:-                                     *

//*                                                *

//* Well, sometimes a user will close a program    *

//* "elegantly"...that is, they will click on the  *

//* the "Close" border icon or a provided "Exit"   *

//* button.                                        *

//*                                                *

//* BUT WHAT IF...the program is shutdown from     *

//* TASKMANAGER or otherwise rudely interrupted??? *

//*                                                *

//* Try as far as possible to kill all instances   *

//* of extraneous controls so that when the program*

//* starts up again, you don't run into any        *

//* previously running threads...                  *

//**************************************************

 

procedure TfrmCDControl.FormClose(Sender: TObject;

  var Action: TCloseAction);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.FormCloseQuery(Sender: TObject;

  var CanClose: Boolean);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.FormDestroy(Sender: TObject);

begin

//*************************

//* Unregister the hotkey *

//*************************

UnRegisterHotKey(Handle,1);

//************************

//* Remove the tray icon *

//************************

Shell_NotifyIcon(NIM_DELETE, @TrayIconData);

end;

 

procedure TfrmCDControl.WMHotKey(var Msg2: TWMHotKey);

begin

//*****************************************************

//* This procedure does the actual activation of the  *

//* CD drive. It involves "faffing" about with the    *

//* operating system, but generally you could accept  *

//* this peice of code as a reliable "means to an end"*

//*****************************************************

if Msg2.HotKey = 1 then

  begin

    if CDSTATE = 'I' then

        mciSendString('Set CDAudio Door Open wait', nil, 0, Handle);

    if CDSTATE = 'O' then

        mciSendString('Set CDAudio Door Closed wait', nil, 0, Handle);

    if CDSTATE = 'I' then

        CDSTATE := 'O'

    else

        CDSTATE := 'I';

  end;

end;

 

 

procedure TfrmCDControl.PopOCClick(Sender: TObject);

begin

//***************************************************

//* CDSTATE is simply a globally defined variable:- *

//* it's basically just a flag to let the program   *

//* know what THE LAST STATE of the CD drive was... *

//* IN or OUT - hence "I" or "O"...Hmmmm could just *

//* as well have used a BOOLEAN variable here....   *

//***************************************************

if CDSTATE = 'I' then

    mciSendString('Set CDAudio Door Open wait', nil, 0, Handle);

if CDSTATE = 'O' then

    mciSendString('Set CDAudio Door Closed wait', nil, 0, Handle);

//******************************************************************

//* Be careful to isolate the following test AFTER opening/closing *

//* the CD drive, if you try to include the "CDSTATE :=" phrases   *

//* in their partner "if" staements above, you will end up with a  *

//* CD drive that simply bounces open and closed...heh...heh...heh *

//******************************************************************

if CDSTATE = 'I' then

    CDSTATE := 'O'

else

    CDSTATE := 'I';

end;

 

procedure TfrmCDControl.Timer1Timer(Sender: TObject);

var Icon: TIcon;

begin

//****************************************************

//* Make sure that the timer counter does'nt extend  *

//* the range 0 - 3 (or a count of 4)                *

//****************************************************

If TCnt > 3 then

  TCnt := 0;

//****************************************************

//* Grab the icon from ImageList IL and use it at an *

//* interval of 200 Ms to modify the tray icon...note*

//* that there are four icons in IL (0 - 3) and they *

//* are going to be rotated (excuse the pun) by using*

//* TCnt (Timer Counter) as an index...              *

//****************************************************

Icon := TIcon.Create;

IL.GetIcon(TCnt, Icon);

TrayIconData.hIcon := Icon.Handle;

//****************************************************************

//* Here we use the NIM_MODIFY parameter to Shell_NotifyIcon API *

//* to change the system tray icon...                            *

//****************************************************************

Shell_NotifyIcon(NIM_MODIFY, @TrayIconData);

//**************************************

//* Increment TCnt by 1 every cycle... *

//**************************************

Inc(TCnt);

//*******************************************************

//* Finally...make sure to free up the instance of Icon *

//*******************************************************

Icon.Free;

end;

 

procedure TfrmCDControl.PopAboutClick(Sender: TObject);

begin

//************************************************************

//* This is (probably) the best way to show a "child" form   *

//* from a "parent" form - Zarko in his wisdom may have      *

//* devised a better way, but so far I have found this to    *

//* be infallible. It works like this:-                      *

//*                                                          *

//*   1) CREATE the child form internally from the parent,   *

//*      have a look up top in the VAR globally defined      *

//*      declaratives of this unit, you will see a statement *

//*      that looks like this:                               *

//*           Fabout: TForm;                                 *

//*      This merely creates a variable "Fabout" of type     *

//*      "TForm".                                            *

//*                                                          *

//*      In the same VAR declaratives inside Unit2 you will  *

//*      find a statement that looks like this:              *

//*           frmAbout: TfrmAbout;                           *

//*                                                          *

//*      Now to create this form we need to instance the     *

//*      "TForm" variable of parent form (Unit1) to          *

//*      "TfrmAbout" object of the child form (Unit2), we do *

//*      this with the following instruction:                *

//************************************************************

FAbout := TfrmAbout.Create(Self);

//************************************************************

//* The parameter "Self" indicates that "ME" as Unit1 are    *

//* creating "YOU" as Unit2 (or form TfrmAbout)...           *

//* Next we actually have to show this form...remember...at  *

//* this stage, all we have done is to create an instance of *

//* "TfrmAbout". I want to point out that there are various  *

//* kinds of child forms...most notably "MODAL" and          *

//* "NONMODAL"...but it is safe to say that (if handled      *

//* correctly) you will normally be dealing with MODAL forms *

//* SO:                                                      *

//*                                                          *

//*   2) Show variable "FAbout" of type "TForm" assigned to  *

//*      object "TfrmAbout" in "Unit2" in it's modal kind    *

//*      thus:                                               *

//************************************************************

FAbout.ShowModal;

//************************************************************

//* At this point program control is handed over to "child"  *

//* form "frmFabout" contained within Unit2 and described by *

//* type "TfrmAbout". What now happens is that the "ABOUT"   *

//* form pops up and displays what an idiot I am for not     *

//* using beautiful fonts etc. But the job is done...the     *

//* child form has been displayed.                           *

//*                                                          *

//* The last consideration is what happens after "child"     *

//* form is closed (ended) and control returns to the calling*

//* "parent" form...a little controvesy here...remember that *

//* displaying forms all over the place takes up CPU memory  *

//* that ideally should be freed up if the form is no longer *

//* in use. Both Microsoft Visual Basic and Borland Delphi   *

//* claim that when a "CLOSE" type operation is executed,   *

//* the memory is freed up, but I have found this not to be  *

//* the case...I have found traces of malingering instances  *

//* (not even reported by Windows Task Manager) to be        *

//* residing in memory. The next statement will only be      *

//* executed when control returns to the calling "parent"    *

//* form...and so to completely eradicate it from memory:    *

//*   3) Destroy it's instance like this:                    *

//************************************************************

FAbout.Destroy;

//************************************************************

//* That's it!!! We have created, shown and destroyed a child*

//* form                                                     *

//************************************************************

end;

 

end.

 

Delphi - .....................................

 

RichEdit

//Satır Ekledikçe RichEdit Aşağıya Doğru Kaysın

 RichEdit1.Lines.Add('New text');

 RichEdit1.Perform(EM_SCROLL,SB_LINEDOWN,0);

 

Delphi - .....................................

 

RichEdit

//Satır Ekledikçe RichEdit Aşağıya Doğru Kaysın

 RichEdit1.Lines.Add('New text');

 RichEdit1.Perform(EM_SCROLL,SB_LINEDOWN,0);

 

Delphi - .....................................

 

Kısayol Tuşları

//F1,F2 gibi tuşları kullanmak

 

//Formun KeyPreview özelliğini True yapın OnKeyDown olayına aşağıdaki kodu yazın:

 

if Key = VK_F2 then

  begin

  {F2'ye basılırsa burdaki kod çalışır}

  end;

 

Delphi - .....................................

 

Kısayol Tuşları

//F1,F2 gibi tuşları kullanmak

 

//Formun KeyPreview özelliğini True yapın OnKeyDown olayına aşağıdaki kodu yazın:

 

if Key = VK_F2 then

  begin

  {F2'ye basılırsa burdaki kod çalışır}

  end;

 

Delphi - .....................................

 

Bir Dosanın Özelliklerini Gösterme

Procedure Tform1.Button1Click(Sender:TObject);

var

  Sei:TSellExecuteInfo;

begin

  FillChar(sei,SizeOf(sei),#0);

  sei.cbSize:=SizeOf(Sei);

  sei.IpFile:=PChar('c:windowsnotepad.exe');

  sei.IpVerb:='properties';

  sei.fMask:=SEE_MASK_INVOKEIDLIST;

  ShellExecuteEx(@sei);

end;

 

Delphi - .....................................

 

Bir Dosanın Özelliklerini Gösterme

Procedure Tform1.Button1Click(Sender:TObject);

var

  Sei:TSellExecuteInfo;

begin

  FillChar(sei,SizeOf(sei),#0);

  sei.cbSize:=SizeOf(Sei);

  sei.IpFile:=PChar('c:windowsnotepad.exe');

  sei.IpVerb:='properties';

  sei.fMask:=SEE_MASK_INVOKEIDLIST;

  ShellExecuteEx(@sei);

end;

 

Delphi - .....................................

 

ALT+F4 Tuş Kombinasonuyla Programın Kapanması

//Formun KeyPreview özelliğini True yapın, daha sonra formun OnKeyDown

//olayına aşağıdaki kodu yazın...

 

İf ((ssAlt in Shift) and (Key = VK_F4)) then

  Key:=0;

 

Delphi - .....................................

 

ALT+F4 Tuş Kombinasonuyla Programın Kapanması

//Formun KeyPreview özelliğini True yapın, daha sonra formun OnKeyDown

//olayına aşağıdaki kodu yazın...

 

İf ((ssAlt in Shift) and (Key = VK_F4)) then

  Key:=0;

 

Delphi - .....................................

 

Bir String'in başındaki ve sonundaki boşlukları atmak için

Trim(string)

TrimLeft (string) //başındaki boşlukları atar

TrimRight (string) //sonundaki boşlukları atar

 

Delphi - .....................................

 

Bir String'in başındaki ve sonundaki boşlukları atmak için

Trim(string)

TrimLeft (string) //başındaki boşlukları atar

TrimRight (string) //sonundaki boşlukları atar

 

Delphi - .....................................

 

Listbox'a Memo'ya ve Combobox'a bir seferde birden çok eleman eklemek

// I.YOL

 

Listbox1.items.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

Memo1.Lines.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

Combobox1.items.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

 

// II.YOL

 

Procedure TForm1.Button1Click(Sender: TObject);

var

  gelen : TStringList;

begin

  gelen :=TStringList.Create;

  gelen.sorted:=True;

  gelen.Duplicates:=dupIgnore;

  gelen.Add('evli');

  gelen.Add('bekar');

  gelen.Add('Dul');

  ComboBox1.items.Assign(gelen);

  gelen.free;

end;

 

Delphi - .....................................

 

Listbox'a Memo'ya ve Combobox'a bir seferde birden çok eleman eklemek

// I.YOL

 

Listbox1.items.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

Memo1.Lines.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

Combobox1.items.SetText('Ali'#13'Veli'#13'kırkdokuzelli');

 

// II.YOL

 

Procedure TForm1.Button1Click(Sender: TObject);

var

  gelen : TStringList;

begin

  gelen :=TStringList.Create;

  gelen.sorted:=True;

  gelen.Duplicates:=dupIgnore;

  gelen.Add('evli');

  gelen.Add('bekar');

  gelen.Add('Dul');

  ComboBox1.items.Assign(gelen);

  gelen.free;

end;

 

Delphi - .....................................

 

Edit'e Sadece Sayı Girmek

//Bir edit'e sadece istediğiniz karakterlerin girilmesini sağlamak için

//Edit'in OnKeyPress olayına aşağıdaki kodu yazın

 

if not (key in ['0'..'9',#8]) then

begin

  Key:=#0; //girilen karakter rakam veya backspace değilse null(#0)'a dönüştür

  Beep; //bip sesi ile kullanıcıı uyar.

end;

 

Delphi - .....................................

 

Edit'e Sadece Sayı Girmek

//Bir edit'e sadece istediğiniz karakterlerin girilmesini sağlamak için

//Edit'in OnKeyPress olayına aşağıdaki kodu yazın

 

if not (key in ['0'..'9',#8]) then

begin

  Key:=#0; //girilen karakter rakam veya backspace değilse null(#0)'a dönüştür

  Beep; //bip sesi ile kullanıcıı uyar.

end;

 

Delphi - .....................................

 

Bir Menü Öğesini Kullanılmaz Hale Getirmek

MainMenu1.items[0].items[1].Enabled:=False; //ilk menünün, ikinci elemanı

 

Delphi - .....................................

 

Bir Menü Öğesini Kullanılmaz Hale Getirmek

MainMenu1.items[0].items[1].Enabled:=False; //ilk menünün, ikinci elemanı

 

Delphi - .....................................

 

Sistem tarihini ve saatini değiştirmek

// sistemin tarih ve saatini SetLocalTime fonksionu ile değiştirin

 

var

  t:TSystemTime;

begin

  t.wYear:=1998;

  t.wMonth:=5;

  t.Day:=23;

  t.wHour:=12;

  t.wMinute:=34;

  SetLocalTime(t);

end;

 

Delphi - .....................................

 

Sistem tarihini ve saatini değiştirmek

// sistemin tarih ve saatini SetLocalTime fonksionu ile değiştirin

 

var

  t:TSystemTime;

begin

  t.wYear:=1998;

  t.wMonth:=5;

  t.Day:=23;

  t.wHour:=12;

  t.wMinute:=34;

  SetLocalTime(t);

end;

 

Delphi - .....................................

 

Sayıları virgülle yazmak

// Bu iş için FormatFloat fonksionunu kullanabiliriz.

 

procedure TForm1.Button1Click(Sender:TObject);

var

  i:integer;

begin

  i:=12345678;

  Memo1.Lines.Add(FormatFloat('#,',i));

end;

 

Delphi - .....................................

 

Sayıları virgülle yazmak

// Bu iş için FormatFloat fonksionunu kullanabiliriz.

 

procedure TForm1.Button1Click(Sender:TObject);

var

  i:integer;

begin

  i:=12345678;

  Memo1.Lines.Add(FormatFloat('#,',i));

end;

 

Delphi - .....................................

 

Delphi IDE için ipuçları

Form veya Panel üzerindeki bileşenleri toplu olarak seçmek için, CTRL tuşuna basın

ve fare ile sürükleyerek seçin.

 

Nesnelerin iki tür özelliği olabilir:design-time ve run-time.

Tasarım anında değiştirilebilen tüm özellikler çalışma anında da değiştirilebilir.

 

Bileşenleri View->Alignment Palette veya sağ tuş->Alignment veya Edit->Align ile

hizalayabiliriz.

 

Compile menüsünden Syntax Check ile çok hızlı bir şekilde (programı derlemeye göre)

yazmış olduğunuz kodda hata kontrolü yapar.

 

Bileşen paletinde çok fazla sayfanız olduğunda bir bileşene ulaşmak için bunları

kaydırmanız gerekir. Bu durumda sayfaları daha kısa adlarla isimlendirin, böylece

tüm sayfalar ekrana sığar.

 

Delphi projenin tüm kod dosyalarını, son derlemeden bu yana değişip değişmediğini

kontrol eder ve sadece değişen dosyaları derler. Projedeki tüm dosyaları değişikliğe

uğrayıp uğramadığına bakmadan derlemek için Project->Build All komutunu verin.

 

Project->Information ile yapmış olduğunuz en son derleme hakkında bazı bilgileri

görebilirsiniz.

 

Delphi'de hemen hemen her bileşende SpeedMenu ismi verilen menüler vardır.

Bu menüyü görmek için bileşene sağ tıklayın. Bazı işlemleri çok kolay bir şekilde

yapabilirsiniz. Bence buna alışın ve her bileşenin SpeedMenu'sünü kontrol edin.

Mesela QuickReport gibi bir bileşen ile çalışırken SpeedMenu çok işinize yarayacaktır.

 

Bir form üzerindeki birden fazla bileşeni seçmek için Shift tuşunu kullanabilirsiniz.

Seçmek istediğiniz bileşenlerden birine tıklayın, sonra Shift tuşuna basarak seçmek

istediğiniz diğer bileşenlere tıklayın. Shift tuşuna basarken seçili bir bileşene

tıklarsanız seçim iptal edilir. Bu arada Object Inspector seçtiğiniz bileşenlerin

ortak özelliklerini gösterecek şekilde değişir. Bu seçme işlemini fare ile de yapabilirsiniz.

Fareyi tıklayın ve fareyi sürükleyerek seçmek istediğiniz bileşenleri içine alın ve bırakın.

Bu işlem bazen çok faydalı olur. Mesela bir form üzerindeki tüm Edit kontrollerinin

rengini değiştirmek gibi. Hepsiyle tek tek uğraşmazsınız.

 

Bir bileşeni seçtikten sonra Ctrl tuşuna basarak yerini ayarlayabilirsiniz.

Ctrl tuşuna basarak sağ oka basarsanız bileşen sağa doğru kayar. Aynı şekilde

Ctrl tuşu basılı iken sol ok tuşuna basarsanız sola, üst ok tuşuna basarsanız üste

ve alt ok tuşuna basarsanız alta doğru kayar.

Böylece bileşenlerin form üzerindeki yerini ince ayarlarla yapabilirsiniz.

 

Shift + Ctrl + Ok tuşlarına basarsanız bileşen grid aralıkları boyunca ilerler.

Grid form üzerinde görünen noktalardır.

 

Koda yorum veya açıklama eklemek için //, { }, (* *) kullanabilirsiniz.

// tek satır için kullanılır.

{ } ve (* *) arasına yazdığınız her şey yorum olarak kabul edilir.

 

Bileşenlerin form üzerindeki yerini yanlışlıkla değiştirilmesini engellemek için

Edit menüsü altından Lock Controls komutunu kullanabilirsiniz. Bu form tasarımını

bitirdiğiniz zaman örneğin bir bileşeni çift tıklayıp kod yazmak isterken yerini

değiştirmenizi önleyecektir.

 

İki dosyayı karşılaştırmak için View menüsünden New Edit Windows komutunu verin.

Yeni bir editör penceresi açılacaktır.

 

Proje içindeki tüm dosyalarda arama yapmak için Search menüsü altından Find in Files

komutunu kullanabilirsiniz.

 

Menü çubuğuna direk olarak bir komut eklemeyin. Kullanıcılar buna pek alışık değildir.

Ancak herhangi bir nedenle bir komutu menü çubuğuna koymak istiyorsanız bu durumda

kullanılan standart ünlem işaretini de komut sonuna ekleyin. Mesela Çıkış! gibi.

 

Bir bileşeni seçtikten sonra klavyeden ESC tuşuna basarsanız,

seçili bileşenin ebeveyni (parent) olan bileşen seçilir. Bunu üzerine panel vb.

bileşenler olduğu için seçemediğiniz formları seçmek için kullanabilirsiniz.

Formun üzerindeki panele tıklayın ve ESC tuşuna basın. Form seçilecektir.

 

 

Kodunuzu düzenlerken bir kod parçasını blok halinde sağa kaydırmak için kodu seçin

ve CTRL+SHIFT+I tuşlarına basın. Sola kaydırmak için CTRL+SHIFT+U tuşlarına basın.

 

 

Bir procedure ve foksiyonu tanımladıktan sonra gövdesini oluşturmak için CTRL+SHIFT+C tuşlarına basın.

Klavyede olmayan bazı özel karaktereri programınızda kullanmak isteyebilirsiniz.

Mesela © gibi. Bu karakteri yazmak için klavyeden ALT tuşuna basarak 0169'u tuşlayın.

Yalnız 0169'u harflerin üstünde olan rakamlardan değil, klavyenin sağ tarafında yer alan

rakamlardan yazmalısınız. Diğer karakterlerin karşılıklarını öğrenmek için

Windows'un Character Map programını kullanabilirsiniz.

 

 

Varsayılan Form yazıtipini Değiştirme : Delphi'ye yeni bir form eklediğiniz zaman

formun yazıtipi "MS Sans Serif" olur. Eğer siz Tahoma fontunu kullanıyorsanız,

her seferinde değiştirmeniz gerekir. Bu zaman kaybını önlemek için,

varsayılan yazıtipini değiştirebilir, yeni oluşturduğunuz formlar için istediğiniz

yazıtip özelliklerini belileyebilirsiniz.

Başlat -> Çalıştır komutunu verip, regedit yazıp Tamam butonuna basıp Registry Editör'ü açın.

HKEY_CURRENT_USERSoftwareBorlandDelphi6.0 anahtarını açın.

Bunun altına FormDesign isimli (arada boşluk yok) bir anahtar açın.

Bu anahtarı seçip, sağ tuşa tıklatın. New -> String Value komutnu verin.

ismini DefaultFont olarak girin.Bu değer'e çift tıklatıp font özelliklerini girebilirsiniz.

Özelliklerin arasına virgül koyun.

Tahoma, 8

Arial,10,Bold,Italic

 

 

Eğer kod içerisinde ' veya & karakterlerini kullanmak isterseniz, bunları ard arda 2 kere yazmalısınız.

  ShowMessage('Mustafa''nın örneği')

Delphi'de varsayılan Proje klasörü : "C:Program FilesBorlandDelphi7Projects" tir.

Bu varsayılan proje klasörünü değiştirmek için;

Delphi'yi çalıştırdığınız kısayolu sağ tıklayın ve Başlama yeri (Start in) bölümünün

karşısına istediğiniz klasörü yazın.

 

Delphi - .....................................

 

Delphi IDE için ipuçları

Form veya Panel üzerindeki bileşenleri toplu olarak seçmek için, CTRL tuşuna basın

ve fare ile sürükleyerek seçin.

 

Nesnelerin iki tür özelliği olabilir:design-time ve run-time.

Tasarım anında değiştirilebilen tüm özellikler çalışma anında da değiştirilebilir.

 

Bileşenleri View->Alignment Palette veya sağ tuş->Alignment veya Edit->Align ile

hizalayabiliriz.

 

Compile menüsünden Syntax Check ile çok hızlı bir şekilde (programı derlemeye göre)

yazmış olduğunuz kodda hata kontrolü yapar.

 

Bileşen paletinde çok fazla sayfanız olduğunda bir bileşene ulaşmak için bunları

kaydırmanız gerekir. Bu durumda sayfaları daha kısa adlarla isimlendirin, böylece

tüm sayfalar ekrana sığar.

 

Delphi projenin tüm kod dosyalarını, son derlemeden bu yana değişip değişmediğini

kontrol eder ve sadece değişen dosyaları derler. Projedeki tüm dosyaları değişikliğe

uğrayıp uğramadığına bakmadan derlemek için Project->Build All komutunu verin.

 

Project->Information ile yapmış olduğunuz en son derleme hakkında bazı bilgileri

görebilirsiniz.

 

Delphi'de hemen hemen her bileşende SpeedMenu ismi verilen menüler vardır.

Bu menüyü görmek için bileşene sağ tıklayın. Bazı işlemleri çok kolay bir şekilde

yapabilirsiniz. Bence buna alışın ve her bileşenin SpeedMenu'sünü kontrol edin.

Mesela QuickReport gibi bir bileşen ile çalışırken SpeedMenu çok işinize yarayacaktır.

 

Bir form üzerindeki birden fazla bileşeni seçmek için Shift tuşunu kullanabilirsiniz.

Seçmek istediğiniz bileşenlerden birine tıklayın, sonra Shift tuşuna basarak seçmek

istediğiniz diğer bileşenlere tıklayın. Shift tuşuna basarken seçili bir bileşene

tıklarsanız seçim iptal edilir. Bu arada Object Inspector seçtiğiniz bileşenlerin

ortak özelliklerini gösterecek şekilde değişir. Bu seçme işlemini fare ile de yapabilirsiniz.

Fareyi tıklayın ve fareyi sürükleyerek seçmek istediğiniz bileşenleri içine alın ve bırakın.

Bu işlem bazen çok faydalı olur. Mesela bir form üzerindeki tüm Edit kontrollerinin

rengini değiştirmek gibi. Hepsiyle tek tek uğraşmazsınız.

 

Bir bileşeni seçtikten sonra Ctrl tuşuna basarak yerini ayarlayabilirsiniz.

Ctrl tuşuna basarak sağ oka basarsanız bileşen sağa doğru kayar. Aynı şekilde

Ctrl tuşu basılı iken sol ok tuşuna basarsanız sola, üst ok tuşuna basarsanız üste

ve alt ok tuşuna basarsanız alta doğru kayar.

Böylece bileşenlerin form üzerindeki yerini ince ayarlarla yapabilirsiniz.

 

Shift + Ctrl + Ok tuşlarına basarsanız bileşen grid aralıkları boyunca ilerler.

Grid form üzerinde görünen noktalardır.

 

Koda yorum veya açıklama eklemek için //, { }, (* *) kullanabilirsiniz.

// tek satır için kullanılır.

{ } ve (* *) arasına yazdığınız her şey yorum olarak kabul edilir.

 

Bileşenlerin form üzerindeki yerini yanlışlıkla değiştirilmesini engellemek için

Edit menüsü altından Lock Controls komutunu kullanabilirsiniz. Bu form tasarımını

bitirdiğiniz zaman örneğin bir bileşeni çift tıklayıp kod yazmak isterken yerini

değiştirmenizi önleyecektir.

 

İki dosyayı karşılaştırmak için View menüsünden New Edit Windows komutunu verin.

Yeni bir editör penceresi açılacaktır.

 

Proje içindeki tüm dosyalarda arama yapmak için Search menüsü altından Find in Files

komutunu kullanabilirsiniz.

 

Menü çubuğuna direk olarak bir komut eklemeyin. Kullanıcılar buna pek alışık değildir.

Ancak herhangi bir nedenle bir komutu menü çubuğuna koymak istiyorsanız bu durumda

kullanılan standart ünlem işaretini de komut sonuna ekleyin. Mesela Çıkış! gibi.

 

Bir bileşeni seçtikten sonra klavyeden ESC tuşuna basarsanız,

seçili bileşenin ebeveyni (parent) olan bileşen seçilir. Bunu üzerine panel vb.

bileşenler olduğu için seçemediğiniz formları seçmek için kullanabilirsiniz.

Formun üzerindeki panele tıklayın ve ESC tuşuna basın. Form seçilecektir.

 

 

Kodunuzu düzenlerken bir kod parçasını blok halinde sağa kaydırmak için kodu seçin

ve CTRL+SHIFT+I tuşlarına basın. Sola kaydırmak için CTRL+SHIFT+U tuşlarına basın.

 

 

Bir procedure ve foksiyonu tanımladıktan sonra gövdesini oluşturmak için CTRL+SHIFT+C tuşlarına basın.

Klavyede olmayan bazı özel karaktereri programınızda kullanmak isteyebilirsiniz.

Mesela © gibi. Bu karakteri yazmak için klavyeden ALT tuşuna basarak 0169'u tuşlayın.

Yalnız 0169'u harflerin üstünde olan rakamlardan değil, klavyenin sağ tarafında yer alan

rakamlardan yazmalısınız. Diğer karakterlerin karşılıklarını öğrenmek için

Windows'un Character Map programını kullanabilirsiniz.

 

 

Varsayılan Form yazıtipini Değiştirme : Delphi'ye yeni bir form eklediğiniz zaman

formun yazıtipi "MS Sans Serif" olur. Eğer siz Tahoma fontunu kullanıyorsanız,

her seferinde değiştirmeniz gerekir. Bu zaman kaybını önlemek için,

varsayılan yazıtipini değiştirebilir, yeni oluşturduğunuz formlar için istediğiniz

yazıtip özelliklerini belileyebilirsiniz.

Başlat -> Çalıştır komutunu verip, regedit yazıp Tamam butonuna basıp Registry Editör'ü açın.

HKEY_CURRENT_USERSoftwareBorlandDelphi6.0 anahtarını açın.

Bunun altına FormDesign isimli (arada boşluk yok) bir anahtar açın.

Bu anahtarı seçip, sağ tuşa tıklatın. New -> String Value komutnu verin.

ismini DefaultFont olarak girin.Bu değer'e çift tıklatıp font özelliklerini girebilirsiniz.

Özelliklerin arasına virgül koyun.

Tahoma, 8

Arial,10,Bold,Italic

 

 

Eğer kod içerisinde ' veya & karakterlerini kullanmak isterseniz, bunları ard arda 2 kere yazmalısınız.

  ShowMessage('Mustafa''nın örneği')

Delphi'de varsayılan Proje klasörü : "C:Program FilesBorlandDelphi7Projects" tir.

Bu varsayılan proje klasörünü değiştirmek için;

Delphi'yi çalıştırdığınız kısayolu sağ tıklayın ve Başlama yeri (Start in) bölümünün

karşısına istediğiniz klasörü yazın.

 

Delphi - .....................................

 

WMI ile (o bilgisayar veya remote bilgisayardaki ) Çalışan Uygulamalar Hakkında Bilgi Alma (Process

WbemScripting_TLB unit'ini eklenmesi gerekir:

Bunu Project ->Import Type Library den

<Windows System32>wbemwbemdisp.tlb dosyasını ekleyebilirsiniz.

 

WMI ile yapabilcekelerinizi görmek için Dos promptundan WMIC yazın ve konsoldan

/? ile yardım alın.

Not: 2000 ve XP de yüklü gelir.98 ve ME için Microsoft sitesinden indirilip yüklenmesi gerekir.

 

 

//-------------------------

uses

  ActiveX, WbemScripting_TLB;

 

function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;

  var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external 'activeds.dll';

 

procedure DumpWMI_Process(Process: SWBemObject);

var

  Enum: IEnumVARIANT;

  varArr: OleVariant;

  lNumElements: ULong;

  SProp: ISWbemProperty;

  Prop: OleVariant;

  PropName: string;

  PropType: string;

  PropValue: string;

begin

  Form1.Memo1.Lines.Add('+ WMI Path: ' + Process.Path_.Path);

  Enum := Process.Properties_._NewEnum as IEnumVariant;

  while (Succeeded(ADsEnumerateNext(Enum, 1, VarArr, lNumElements))) and

    (lNumElements > 0) do

  begin

    if Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty, SProp)) and

      Assigned(SProp) then

    begin

      try

        PropName  := SProp.Name;

        Prop := SProp.Get_Value;

        PropType := VarTypeAsText(VarType(Prop));

        PropValue := VarToStr(Prop);

        Form1.Memo1.Lines.Add('  + ' + PropName + '[' + PropType + '] = ' + PropValue);

      except

        on E: Exception do

        begin

          // WriteLn(ErrOutput, PropName, ': ', E.Message);

        end;

      end;

    end;

  end;

end;

 

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Server: string;

  Enum: IEnumVARIANT;

  varArr: OleVariant;

  lNumElements: ULong;

  AName: array[0..255] of Char;

  ASize: DWORD;

begin

  if (ParamCount = 0) then

  begin

    Server := '';

    ASize  := SizeOf(AName) - 1;

    if GetComputerName(@AName, ASize) then Server := AName;

  end

  else

  begin

    Server := ParamStr(1);

  end;

  try

    Memo1.Lines.BeginUpdate;

    Enum := CoSWbemLocator.Create.ConnectServer(Server, 'rootcimv2', '',

      '', '', '', 0, nil).ExecQuery('Select * from Win32_Process', 'WQL',

      wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;

    while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and

      (lNumElements > 0) do

    begin

      DumpWMI_Process(IUnknown(varArr) as SWBemObject);

    end;

  finally

    Memo1.Lines.EndUpdate;

  end;

end;

 

Delphi - .....................................

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol