Programlama yapalım ve Öğrenelim. - Delphi Eğitim175
  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

neoturk: ...Enumerate drives on a computer ?...

{

  Adds all fixed drives into Combobox1.

  To enumerate another type of drive,

  i.e all CD-ROMs just change the DRIVE_FIXED constant to DRIVE_CDROM.

 

  Fügt all fixen Laufwerke in Combobox1 ein.

  Um z.B alle CD-Rom Laufwerke zu ermitteln,

  einfach DRIVE_CDROM anstatt die Konstante DRIVE_FIXED nehmen.

}

 

procedure List_Drives;

const

  DRIVE_UNKNOWN = 0;

  DRIVE_NO_ROOT_DIR = 1;

  DRIVE_REMOVABLE = 2;

  DRIVE_FIXED = 3;

  DRIVE_REMOTE = 4;

  DRIVE_CDROM = 5;

  DRIVE_RAMDISK = 6;

var

  r: LongWord;

  Drives: array[0..128] of char;

  pDrive: PChar;

begin

  r := GetLogicalDriveStrings(SizeOf(Drives), Drives);

  if r = 0 then Exit;

  if r > SizeOf(Drives) then

    raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));

  pDrive := Drives;

  while pDrive^ <> #0 do

  begin

    if GetDriveType(pDrive) = DRIVE_FIXED then

      Form1.ComboBox1.Items.Add(pDrive);

    Inc(pDrive, 4);

  end;

end;

 

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

 

neoturk: ...Enumerate drives on a computer ?...

{

  Adds all fixed drives into Combobox1.

  To enumerate another type of drive,

  i.e all CD-ROMs just change the DRIVE_FIXED constant to DRIVE_CDROM.

 

  Fügt all fixen Laufwerke in Combobox1 ein.

  Um z.B alle CD-Rom Laufwerke zu ermitteln,

  einfach DRIVE_CDROM anstatt die Konstante DRIVE_FIXED nehmen.

}

 

procedure List_Drives;

const

  DRIVE_UNKNOWN = 0;

  DRIVE_NO_ROOT_DIR = 1;

  DRIVE_REMOVABLE = 2;

  DRIVE_FIXED = 3;

  DRIVE_REMOTE = 4;

  DRIVE_CDROM = 5;

  DRIVE_RAMDISK = 6;

var

  r: LongWord;

  Drives: array[0..128] of char;

  pDrive: PChar;

begin

  r := GetLogicalDriveStrings(SizeOf(Drives), Drives);

  if r = 0 then Exit;

  if r > SizeOf(Drives) then

    raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));

  pDrive := Drives;

  while pDrive^ <> #0 do

  begin

    if GetDriveType(pDrive) = DRIVE_FIXED then

      Form1.ComboBox1.Items.Add(pDrive);

    Inc(pDrive, 4);

  end;

end;

 

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

 

neoturk: ...Register a menu entry to a file ?...

uses

  Registry;

 

procedure AddFileMenue(FilePrefix, Menue, Command: string);

var

  reg: TRegistry;

  typ: string;

begin

  reg := TRegistry.Create;

  with reg do

  begin

    RootKey := HKEY_CLASSES_ROOT;

    OpenKey('.' + FilePrefix, True);

    typ := ReadString('');

    if typ = '' then

    begin

      typ := Fileprefix + 'file';

      WriteString('', typ);

    end;

    CloseKey;

    OpenKey(typ + 'shell' + Menue + 'command', True);

    WriteString('', command + ' "%1"');

    CloseKey;

    Free;

  end;

end;

 

procedure DeleteFileMenue(Fileprefix, Menue: string);

var

  reg: TRegistry;

  typ: string;

begin

  reg := TRegistry.Create;

  with reg do

  begin

    RootKey := HKEY_CLASSES_ROOT;

    OpenKey('.' + Fileprefix, True);

    typ := ReadString('');

    CloseKey;

    OpenKey(typ + 'shell', True);

    DeleteKey(Menue);

    CloseKey;

    Free;

  end;

end;

 

 

{ Example / Beispiel:}

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  { Register the Menuepoint: }

 

  AddFileMenue('rtf', 'Edit with Notepad', 'C:Windowssystemnotepad.exe');

 

  {

    If you now click with the right mousebutton on a *.rtf-file then

    you can see a Menuepoint: "Edit with Notepad".

    When Click on that point Notepad opens the file.

 

    Wenn man nun mit der rechten Maustaste im Explorer auf eine *.rtf-Datei Clickt,

    dann erscheint dort der Menuepunkt "Edit with Notepad".

    Beim Clicken darauf, öffnet Notepad diese Datei.

  }

end;

 

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  {

   Unregister the Menuepoint / Undo your changes in the Registry:

   Löscht den Menuepunkt wieder aus der Registry:

  }

 

  DeleteFileMenue('rtf', 'Edit with Notepad');

end;

 

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

 

neoturk: ...Register a menu entry to a file ?...

uses

  Registry;

 

procedure AddFileMenue(FilePrefix, Menue, Command: string);

var

  reg: TRegistry;

  typ: string;

begin

  reg := TRegistry.Create;

  with reg do

  begin

    RootKey := HKEY_CLASSES_ROOT;

    OpenKey('.' + FilePrefix, True);

    typ := ReadString('');

    if typ = '' then

    begin

      typ := Fileprefix + 'file';

      WriteString('', typ);

    end;

    CloseKey;

    OpenKey(typ + 'shell' + Menue + 'command', True);

    WriteString('', command + ' "%1"');

    CloseKey;

    Free;

  end;

end;

 

procedure DeleteFileMenue(Fileprefix, Menue: string);

var

  reg: TRegistry;

  typ: string;

begin

  reg := TRegistry.Create;

  with reg do

  begin

    RootKey := HKEY_CLASSES_ROOT;

    OpenKey('.' + Fileprefix, True);

    typ := ReadString('');

    CloseKey;

    OpenKey(typ + 'shell', True);

    DeleteKey(Menue);

    CloseKey;

    Free;

  end;

end;

 

 

{ Example / Beispiel:}

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  { Register the Menuepoint: }

 

  AddFileMenue('rtf', 'Edit with Notepad', 'C:Windowssystemnotepad.exe');

 

  {

    If you now click with the right mousebutton on a *.rtf-file then

    you can see a Menuepoint: "Edit with Notepad".

    When Click on that point Notepad opens the file.

 

    Wenn man nun mit der rechten Maustaste im Explorer auf eine *.rtf-Datei Clickt,

    dann erscheint dort der Menuepunkt "Edit with Notepad".

    Beim Clicken darauf, öffnet Notepad diese Datei.

  }

end;

 

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  {

   Unregister the Menuepoint / Undo your changes in the Registry:

   Löscht den Menuepunkt wieder aus der Registry:

  }

 

  DeleteFileMenue('rtf', 'Edit with Notepad');

end;

 

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

 

neoturk: ...How to accept dropped files from the explorer ?...

{

  This way you can drag and drop files to a specific control in a Delphi form.

  Just create a project and add a ListBox component to Form1.}

 

{ 1. First, a procedure to handle the message but without handling it. }

 

interface

 

procedure WMDROPFILES(var Msg: TMessage);

 

implementation

 

procedure TForm1.WMDROPFILES(var Msg: TWMDropFiles);

var

  pcFileName: PChar;

  i, iSize, iFileCount: integer;

begin

  pcFileName := ''; // to avoid compiler warning message

  iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);

  for i := 0 to iFileCount - 1 do

  begin

    iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;

    pcFileName := StrAlloc(iSize);

    DragQueryFile(Msg.wParam, i, pcFileName, iSize);

    if FileExists(pcFileName) then

      AddFile(pcFileName); // method to add each file

    StrDispose(pcFileName);

  end;

  DragFinish(Msg.wParam);

end;

 

 

{

  2. Second, a WindowProc method to replace ListBox1 WindowProc default method

  and a variable to store ListBox1 WindowProc default method.

}

 

interface

 

procedure LBWindowProc(var Message: TMessage);

 

implementation

 

var

  OldLBWindowProc: TWndMethod;

 

procedure TForm1.LBWindowProc(var Message: TMessage);

begin

  if Message.Msg = WM_DROPFILES then

    WMDROPFILES(Message); // handle WM_DROPFILES message

  OldLBWindowProc(Message);

  // call default ListBox1 WindowProc method to handle all other messages

end;

 

{3. In Form1 OnCreate event, initialize all.}

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  OldLBWindowProc := ListBox1.WindowProc; // store defualt WindowProc

  ListBox1.WindowProc := LBWindowProc; // replace default WindowProc

  DragAcceptFiles(ListBox1.Handle, True); // now ListBox1 accept dropped files

end;

 

 

{4. In Form1 OnDestroy event, uninitialize all. Not necesary but a good practice.}

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  ListBox1.WindowProc := OldLBWindowProc;

  DragAcceptFiles(ListBox1.Handle, False);

end;

 

 

{5. To complete source code, the AddFile method.}

 

interface

 

procedure AddFile(sFileName: string);

 

implementation

 

procedure TForm1.AddFile(sFileName: string);

begin

  ListBox1.Items.Add(sFilename);

end;

 

{6. Do not forget to add ShellAPI unit to the uses clause. }

 

Complete code

 

 

unit Unit1;

 

interface

 

uses

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

  StdCtrls;

 

type

  TForm1 = class(TForm)

    ListBox1: TListBox;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

  private

    { Private declarations }

    procedure WMDROPFILES(var Msg: TMessage);

    procedure LBWindowProc(var Message: TMessage);

    procedure AddFile(sFileName: string);

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

uses

  ShellAPI;

 

var

  OldLBWindowProc: TWndMethod;

 

procedure TForm1.AddFile(sFileName: string);

begin

  ListBox1.Items.Add(sFilename);

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  OldLBWindowProc := ListBox1.WindowProc; // store defualt WindowProc

  ListBox1.WindowProc := LBWindowProc; // replace default WindowProc

  DragAcceptFiles(ListBox1.Handle, True); // now ListBox1 accept dropped files

end;

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  ListBox1.WindowProc := OldLBWindowProc;

  DragAcceptFiles(ListBox1.Handle, False);

end;

 

procedure TForm1.LBWindowProc(var Message: TMessage);

begin

  if Message.Msg = WM_DROPFILES then

    WMDROPFILES(Message); // handle WM_DROPFILES message

  OldLBWindowProc(Message);

  // call default ListBox1 WindowProc method to handle all other messages

end;

 

procedure TForm1.WMDROPFILES(var Msg: TMessage);

var

  pcFileName: PChar;

  i, iSize, iFileCount: integer;

begin

  pcFileName := ''; // to avoid compiler warning message

  iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);

  for i := 0 to iFileCount - 1 do

  begin

    iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;

    pcFileName := StrAlloc(iSize);

    DragQueryFile(Msg.wParam, i, pcFileName, iSize);

    if FileExists(pcFileName) then

      AddFile(pcFileName); // method to add each file

    StrDispose(pcFileName);

  end;

  DragFinish(Msg.wParam);

end;

 

end.

 

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

 

neoturk: ...How to accept dropped files from the explorer ?...

{

  This way you can drag and drop files to a specific control in a Delphi form.

  Just create a project and add a ListBox component to Form1.}

 

{ 1. First, a procedure to handle the message but without handling it. }

 

interface

 

procedure WMDROPFILES(var Msg: TMessage);

 

implementation

 

procedure TForm1.WMDROPFILES(var Msg: TWMDropFiles);

var

  pcFileName: PChar;

  i, iSize, iFileCount: integer;

begin

  pcFileName := ''; // to avoid compiler warning message

  iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);

  for i := 0 to iFileCount - 1 do

  begin

    iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;

    pcFileName := StrAlloc(iSize);

    DragQueryFile(Msg.wParam, i, pcFileName, iSize);

    if FileExists(pcFileName) then

      AddFile(pcFileName); // method to add each file

    StrDispose(pcFileName);

  end;

  DragFinish(Msg.wParam);

end;

 

 

{

  2. Second, a WindowProc method to replace ListBox1 WindowProc default method

  and a variable to store ListBox1 WindowProc default method.

}

 

interface

 

procedure LBWindowProc(var Message: TMessage);

 

implementation

 

var

  OldLBWindowProc: TWndMethod;

 

procedure TForm1.LBWindowProc(var Message: TMessage);

begin

  if Message.Msg = WM_DROPFILES then

    WMDROPFILES(Message); // handle WM_DROPFILES message

  OldLBWindowProc(Message);

  // call default ListBox1 WindowProc method to handle all other messages

end;

 

{3. In Form1 OnCreate event, initialize all.}

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  OldLBWindowProc := ListBox1.WindowProc; // store defualt WindowProc

  ListBox1.WindowProc := LBWindowProc; // replace default WindowProc

  DragAcceptFiles(ListBox1.Handle, True); // now ListBox1 accept dropped files

end;

 

 

{4. In Form1 OnDestroy event, uninitialize all. Not necesary but a good practice.}

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  ListBox1.WindowProc := OldLBWindowProc;

  DragAcceptFiles(ListBox1.Handle, False);

end;

 

 

{5. To complete source code, the AddFile method.}

 

interface

 

procedure AddFile(sFileName: string);

 

implementation

 

procedure TForm1.AddFile(sFileName: string);

begin

  ListBox1.Items.Add(sFilename);

end;

 

{6. Do not forget to add ShellAPI unit to the uses clause. }

 

Complete code

 

 

unit Unit1;

 

interface

 

uses

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

  StdCtrls;

 

type

  TForm1 = class(TForm)

    ListBox1: TListBox;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

  private

    { Private declarations }

    procedure WMDROPFILES(var Msg: TMessage);

    procedure LBWindowProc(var Message: TMessage);

    procedure AddFile(sFileName: string);

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

uses

  ShellAPI;

 

var

  OldLBWindowProc: TWndMethod;

 

procedure TForm1.AddFile(sFileName: string);

begin

  ListBox1.Items.Add(sFilename);

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  OldLBWindowProc := ListBox1.WindowProc; // store defualt WindowProc

  ListBox1.WindowProc := LBWindowProc; // replace default WindowProc

  DragAcceptFiles(ListBox1.Handle, True); // now ListBox1 accept dropped files

end;

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  ListBox1.WindowProc := OldLBWindowProc;

  DragAcceptFiles(ListBox1.Handle, False);

end;

 

procedure TForm1.LBWindowProc(var Message: TMessage);

begin

  if Message.Msg = WM_DROPFILES then

    WMDROPFILES(Message); // handle WM_DROPFILES message

  OldLBWindowProc(Message);

  // call default ListBox1 WindowProc method to handle all other messages

end;

 

procedure TForm1.WMDROPFILES(var Msg: TMessage);

var

  pcFileName: PChar;

  i, iSize, iFileCount: integer;

begin

  pcFileName := ''; // to avoid compiler warning message

  iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);

  for i := 0 to iFileCount - 1 do

  begin

    iSize := DragQueryFile(Msg.wParam, i, nil, 0) + 1;

    pcFileName := StrAlloc(iSize);

    DragQueryFile(Msg.wParam, i, pcFileName, iSize);

    if FileExists(pcFileName) then

      AddFile(pcFileName); // method to add each file

    StrDispose(pcFileName);

  end;

  DragFinish(Msg.wParam);

end;

 

end.

 

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

 

neoturk: ...Disable the close [x] button on a form ?...

procedure TFMain.FormCreate(Sender: TObject);

var

  hMenuHandle: Integer;

begin

  hMenuHandle := GetSystemMenu(Handle, False);

  if (hMenuHandle <> 0) then

    DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);

end;

 

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

 

neoturk: ...Disable the close [x] button on a form ?...

procedure TFMain.FormCreate(Sender: TObject);

var

  hMenuHandle: Integer;

begin

  hMenuHandle := GetSystemMenu(Handle, False);

  if (hMenuHandle <> 0) then

    DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);

end;

 

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

 

neoturk: ...Open the windows explorer and show the specified folder ?...

uses

  ShellApi;

 

// strFolder is the folder you want to open

procedure ShowFolder(strFolder: string);

begin

  ShellExecute(Application.Handle,

    PChar('explore'),

    PChar(strFolder),

    nil,

    nil,

    SW_SHOWNORMAL);

end;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  strFolder = 'c:My Documents';

begin

  ShowFolder(strFolder);

end;

 

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

 

neoturk: ...Open the windows explorer and show the specified folder ?...

uses

  ShellApi;

 

// strFolder is the folder you want to open

procedure ShowFolder(strFolder: string);

begin

  ShellExecute(Application.Handle,

    PChar('explore'),

    PChar(strFolder),

    nil,

    nil,

    SW_SHOWNORMAL);

end;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  strFolder = 'c:My Documents';

begin

  ShowFolder(strFolder);

end;

 

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

 

neoturk: ...Run a program or open an associated file ?...

{ Open a file or starts a programm (without parameters) }

 

procedure OpenFile(FileName: string);

var

  c: array[0..800] of Char;

begin

  StrPCopy(c, FileName);

  ShellExecute(Application.Handle, 'open', c, nil, nil, SW_NORMAL);

end;

 

{ Starts a programm with commandline parameters }

 

procedure OpenProgram(prog, params: string);

var

  c, p: array[0..800] of Char;

begin

  StrPCopy(c, prog);

  StrPCopy(p, params);

  ShellExecute(Application.Handle, 'open', c, p, nil, SW_NORMAL);

end;

 

{ Starts a program and wait until its terminated:

  WindowState is of the SW_xxx constants }

 

function ExecAndWait(const FileName, Params: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

  CmdLine: string;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

  CmdLine := '"' + FileName + '"' + Params;

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    PChar(ExtractFilePath(FileName)),

    SUInfo, ProcInfo);

  { Wait for it to finish. }

  if Result then

    WaitForSingleObject(ProcInfo.hProcess, INFINITE);

end;

 

{ Execute a complete shell command line and waits until terminated. }

 

function ExecCmdLineAndWait(const CmdLine: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    nil {PChar(ExtractFilePath(Filename))},

    SUInfo, ProcInfo);

  { Wait for it to finish. }

  if Result then

    WaitForSingleObject(ProcInfo.hProcess, INFINITE);

end;

 

{ Execute a complete shell command line without waiting. }

 

function OpenCmdLine(const CmdLine: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    nil {PChar(ExtractFilePath(Filename))},

    SUInfo, ProcInfo);

end;

 

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

 

neoturk: ...Run a program or open an associated file ?...

{ Open a file or starts a programm (without parameters) }

 

procedure OpenFile(FileName: string);

var

  c: array[0..800] of Char;

begin

  StrPCopy(c, FileName);

  ShellExecute(Application.Handle, 'open', c, nil, nil, SW_NORMAL);

end;

 

{ Starts a programm with commandline parameters }

 

procedure OpenProgram(prog, params: string);

var

  c, p: array[0..800] of Char;

begin

  StrPCopy(c, prog);

  StrPCopy(p, params);

  ShellExecute(Application.Handle, 'open', c, p, nil, SW_NORMAL);

end;

 

{ Starts a program and wait until its terminated:

  WindowState is of the SW_xxx constants }

 

function ExecAndWait(const FileName, Params: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

  CmdLine: string;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

  CmdLine := '"' + FileName + '"' + Params;

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    PChar(ExtractFilePath(FileName)),

    SUInfo, ProcInfo);

  { Wait for it to finish. }

  if Result then

    WaitForSingleObject(ProcInfo.hProcess, INFINITE);

end;

 

{ Execute a complete shell command line and waits until terminated. }

 

function ExecCmdLineAndWait(const CmdLine: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    nil {PChar(ExtractFilePath(Filename))},

    SUInfo, ProcInfo);

  { Wait for it to finish. }

  if Result then

    WaitForSingleObject(ProcInfo.hProcess, INFINITE);

end;

 

{ Execute a complete shell command line without waiting. }

 

function OpenCmdLine(const CmdLine: string;

  WindowState: Word): Boolean;

var

  SUInfo: TStartupInfo;

  ProcInfo: TProcessInformation;

begin

  { Enclose filename in quotes to take care of

    long filenames with spaces. }

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

  with SUInfo do

  begin

    cb := SizeOf(SUInfo);

    dwFlags := STARTF_USESHOWWINDOW;

    wShowWindow := WindowState;

  end;

  Result := CreateProcess(nil, PChar(CmdLine), nil, nil, False,

    CREATE_NEW_CONSOLE or

    NORMAL_PRIORITY_CLASS, nil,

    nil {PChar(ExtractFilePath(Filename))},

    SUInfo, ProcInfo);

end;

 

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

 

neoturk: ...Use tfilestream ?...

type

 

  TPerson = record

    Name: string[50];

    vorname: string[50];

  end;

 

  TComputer = record

    Name: string[30];

    cpu: string[30];

  end;

 

var

  Form1: TForm1;

 

  Person: TPerson;

  Computer: TComputer;

 

  Stream: TFileStream;

 

implementation

 

{$R *.DFM}

 

//Speichern resp. Erstellen von Datei

//Save or create the file

procedure TForm1.Button1Click(Sender: TObject);

begin

  try

    Stream := TFileStream.Create('c:test.dat', fmOpenReadWrite);

  except

    Stream := TFileStream.Create('c:test.dat', fmCreate);

  end;

 

  //2 Einträge pro Record

  //save 2 records for TPerson and TComputer

  Person.Name    := 'Grossenbacher';

  Person.vorname := 'Simon';

  Stream.WriteBuffer(Person, SizeOf(TPerson));

 

  Person.Name    := 'Stutz';

  Person.vorname := 'Thomas';

  Stream.WriteBuffer(Person, SizeOf(TPerson));

 

  Computer.Name := 'Delphi';

  Computer.cpu  := 'Intel';

  Stream.WriteBuffer(Computer, SizeOf(TComputer));

 

  Computer.Name := 'Win';

  Computer.cpu  := 'AMD';

  Stream.WriteBuffer(Computer, SizeOf(TComputer));

 

  Stream.Free;

end;

 

//lädt alle daten von TPerson in listbox1 und

//daten von TComputer in Listbox2

 

//load records from TPerson to listbox1 and

//load records from TComputer to listbox2

procedure TForm1.Button2Click(Sender: TObject);

var

  i: Integer;

begin

  try

    // nur lesen öffnen

    //open read only

    Stream := TFileStream.Create('c:test.dat', fmOpenRead);

  except

    ShowMessage('Datei konnte nicht geladen werden.');

    Exit;

  end;

 

  //variable i auf anzahl Einträge setzen

 

  //set variable i to the record count

 

  //Einlesen von TPerson

  //Read records TPerson

  for i := 2 downto 1 do

  begin

    Stream.ReadBuffer(Person, SizeOf(TPerson));

    Listbox1.Items.Add(Person.vorname + ' ' + Person.Name);

  end;

 

  //Einlesen von TComputer

  //Read Records TComputer

  for i := 2 downto 1 do

  begin

    Stream.ReadBuffer(Computer, SizeOf(TComputer));

    Listbox2.Items.Add(Computer.Name + ' ' + Computer.cpu);

  end;

 

  Stream.Free;

end;

 

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

 

neoturk: ...Use tfilestream ?...

type

 

  TPerson = record

    Name: string[50];

    vorname: string[50];

  end;

 

  TComputer = record

    Name: string[30];

    cpu: string[30];

  end;

 

var

  Form1: TForm1;

 

  Person: TPerson;

  Computer: TComputer;

 

  Stream: TFileStream;

 

implementation

 

{$R *.DFM}

 

//Speichern resp. Erstellen von Datei

//Save or create the file

procedure TForm1.Button1Click(Sender: TObject);

begin

  try

    Stream := TFileStream.Create('c:test.dat', fmOpenReadWrite);

  except

    Stream := TFileStream.Create('c:test.dat', fmCreate);

  end;

 

  //2 Einträge pro Record

  //save 2 records for TPerson and TComputer

  Person.Name    := 'Grossenbacher';

  Person.vorname := 'Simon';

  Stream.WriteBuffer(Person, SizeOf(TPerson));

 

  Person.Name    := 'Stutz';

  Person.vorname := 'Thomas';

  Stream.WriteBuffer(Person, SizeOf(TPerson));

 

  Computer.Name := 'Delphi';

  Computer.cpu  := 'Intel';

  Stream.WriteBuffer(Computer, SizeOf(TComputer));

 

  Computer.Name := 'Win';

  Computer.cpu  := 'AMD';

  Stream.WriteBuffer(Computer, SizeOf(TComputer));

 

  Stream.Free;

end;

 

//lädt alle daten von TPerson in listbox1 und

//daten von TComputer in Listbox2

 

//load records from TPerson to listbox1 and

//load records from TComputer to listbox2

procedure TForm1.Button2Click(Sender: TObject);

var

  i: Integer;

begin

  try

    // nur lesen öffnen

    //open read only

    Stream := TFileStream.Create('c:test.dat', fmOpenRead);

  except

    ShowMessage('Datei konnte nicht geladen werden.');

    Exit;

  end;

 

  //variable i auf anzahl Einträge setzen

 

  //set variable i to the record count

 

  //Einlesen von TPerson

  //Read records TPerson

  for i := 2 downto 1 do

  begin

    Stream.ReadBuffer(Person, SizeOf(TPerson));

    Listbox1.Items.Add(Person.vorname + ' ' + Person.Name);

  end;

 

  //Einlesen von TComputer

  //Read Records TComputer

  for i := 2 downto 1 do

  begin

    Stream.ReadBuffer(Computer, SizeOf(TComputer));

    Listbox2.Items.Add(Computer.Name + ' ' + Computer.cpu);

  end;

 

  Stream.Free;

end;

 

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

 

neoturk: ...Get the path to program files ?...

uses

  Registry;

 

function GetProgramFilesDir: string;

var

  reg: TRegistry;

begin

  reg := TRegistry.Create;

  try

    reg.RootKey := HKEY_LOCAL_MACHINE;

    reg.OpenKey('SOFTWAREMicrosoftWindowsCurrentVersion', False);

    Result := reg.ReadString('ProgramFilesDir');

  finally

    reg.Free;

  end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  // Shows something like c:Program files

  // zeigt "c:Programme" (oder ähnlich)

  ShowMessage(GetProgramFilesDir);

end;

 

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