Programlama yapalım ve Öğrenelim. - Delphi Eğitim171
  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: ...Check if a path exists ?...

uses FileCtrl;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if DirectoryExists('c:windows') then

    ShowMessage('Path exists!');

end;

 

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

 

neoturk: ...Show the select directory dialog ?...

uses Filectrl;

 

{....}

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Dir: String;

begin

  SelectDirectory('Select a directory', '', Dir);

  ShowMessage(Dir);

end;

 

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

 

neoturk: ...Show the select directory dialog ?...

uses Filectrl;

 

{....}

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Dir: String;

begin

  SelectDirectory('Select a directory', '', Dir);

  ShowMessage(Dir);

end;

 

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

 

neoturk: ...Convert long filenames in short filenames ?...

uses

  Windows, SysUtils;

 

function GetShortName(sLongName: string): string;

var

  sShortName:    string;

  nShortNameLen: Integer;

begin

  SetLength(sShortName, MAX_PATH);

  nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH - 1);

  if (0 = nShortNameLen) then

  begin

    // handle errors...

  end;

  SetLength(sShortName, nShortNameLen);

  Result := sShortName;

end;

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  Caption := GetShortName('C:Program FilesDelphi6Libtest.cnt');

  // --> C:PROGRA~1Delphi6Libtest.cnt

end;

 

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

 

neoturk: ...Convert long filenames in short filenames ?...

uses

  Windows, SysUtils;

 

function GetShortName(sLongName: string): string;

var

  sShortName:    string;

  nShortNameLen: Integer;

begin

  SetLength(sShortName, MAX_PATH);

  nShortNameLen := GetShortPathName(PChar(sLongName), PChar(sShortName), MAX_PATH - 1);

  if (0 = nShortNameLen) then

  begin

    // handle errors...

  end;

  SetLength(sShortName, nShortNameLen);

  Result := sShortName;

end;

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  Caption := GetShortName('C:Program FilesDelphi6Libtest.cnt');

  // --> C:PROGRA~1Delphi6Libtest.cnt

end;

 

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

 

neoturk: ...Get the free disk space ?...

procedure TForm1.Button1Click(Sender: TObject);

var

  freeSpace, totalSpace: Double;

  s: Char;

begin

  // Drive letter

  // Laufwerksbuchstabe

  s := 'D';

 

  freeSpace  := DiskFree(Ord(s) - 64);

  totalSpace := DiskSize(Ord(s) - 64);

 

  label1.Caption := Format('Free Space: %12.0n', [freeSpace]);

  Label2.Caption := Format('Total Space: %12.0n', [totalSpace]);

  Label3.Caption := IntToStr(Round((totalSpace - freeSpace) / totalSpace * 100)) +

    ' Percent used.';

end;

 

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

 

neoturk: ...Get the free disk space ?...

procedure TForm1.Button1Click(Sender: TObject);

var

  freeSpace, totalSpace: Double;

  s: Char;

begin

  // Drive letter

  // Laufwerksbuchstabe

  s := 'D';

 

  freeSpace  := DiskFree(Ord(s) - 64);

  totalSpace := DiskSize(Ord(s) - 64);

 

  label1.Caption := Format('Free Space: %12.0n', [freeSpace]);

  Label2.Caption := Format('Total Space: %12.0n', [totalSpace]);

  Label3.Caption := IntToStr(Round((totalSpace - freeSpace) / totalSpace * 100)) +

    ' Percent used.';

end;

 

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

 

neoturk: ...Get the pathes of the windows special folders ?...

uses

  ActiveX, ShlObj;

 

procedure TForm1.Button1Click(Sender: TObject);

// Replace CSIDL_HISTORY with the constants below

var

  Allocator: IMalloc;

  SpecialDir: PItemIdList;

  FBuf: array[0..MAX_PATH] of Char;

  PerDir: string;

begin

  if SHGetMalloc(Allocator) = NOERROR then

  begin

    SHGetSpecialFolderLocation(Form1.Handle, CSIDL_HISTORY, SpecialDir);

    SHGetPathFromIDList(SpecialDir, @FBuf[0]);

    Allocator.Free(SpecialDir);

    ShowMessage(string(FBuf));

  end;

end;

 

// With Windows Me/2000, the SHGetSpecialFolderLocation function

// is superseded by ShGetFolderLocation.

 

 

// function to get the desktop folder location:

 

function GetDeskTopPath : string;

var

  shellMalloc: IMalloc;

  ppidl: PItemIdList;

  PerDir: string;

begin

  ppidl := nil;

  try

    if SHGetMalloc(shellMalloc) = NOERROR then

    begin

      SHGetSpecialFolderLocation(Form1.Handle, CSIDL_DESKTOP, ppidl);

      SetLength(Result, MAX_PATH);

      if not SHGetPathFromIDList(ppidl, PChar(Result)) then

        raise exception.create('SHGetPathFromIDList failed : invalid pidl');

      SetLength(Result, lStrLen(PChar(Result)));

    end;

  finally

   if ppidl <> nil then

         shellMalloc.free(ppidl);

  end;

end;

 

{

  Constants:

 

  CSIDL_DESKTOP

  CSIDL_INTERNET

  CSIDL_PROGRAMS

  CSIDL_CONTROLS

  CSIDL_PRINTERS

  CSIDL_PERSONAL

  CSIDL_FAVORITES

  CSIDL_STARTUP

  CSIDL_RECENT

  CSIDL_SENDTO

  CSIDL_BITBUCKET

  CSIDL_STARTMENU

  CSIDL_DESKTOPDIRECTORY

  CSIDL_DRIVES

  CSIDL_NETWORK

  CSIDL_NETHOOD

  CSIDL_FONTS

  CSIDL_TEMPLATES

  CSIDL_COMMON_STARTMENU

  CSIDL_COMMON_PROGRAMS

  CSIDL_COMMON_STARTUP

  CSIDL_COMMON_DESKTOPDIRECTORY

  CSIDL_APPDATA

  CSIDL_PRINTHOOD

  CSIDL_ALTSTARTUP

  CSIDL_COMMON_ALTSTARTUP

  CSIDL_COMMON_FAVORITES

  CSIDL_INTERNET_CACHE

  CSIDL_COOKIES

  CSIDL_HISTORY

}

 

 

{***********************************************************}

{ Read paths from registry. by LENIN INC }

 

uses

  Windows, SysUtils, Registry;

 

type

  TSystemPath = (Desktop, StartMenu,

    Programs, Startup, Personal, AppData,

    Fonts, SendTo, Recent, Favorites, Cache,

    Cookies, History, NetHood, PrintHood,

    Templates, LocADat, WindRoot, WindSys,

    TempPath, RootDir, ProgFiles, ComFiles,

    ConfigPath, DevicePath, MediaPath, WallPaper);

 

function GetSystemPath(SystemPath: TSystemPath): string;

var

  ph: PChar;

begin

  with TRegistry.Create do

    try

      RootKey := HKEY_CURRENT_USER;

      OpenKey('SoftwareMicrosoftWindowsCurrentVersion' +

        'ExplorerShell Folders', True);

      case SystemPath of

        Desktop: Result   := ReadString('Desktop');

        StartMenu: Result := ReadString('Start Menu');

        Programs: Result  := ReadString('Programs');

        Startup: Result   := ReadString('Startup');

        Personal: Result  := ReadString('Personal');

        AppData: Result   := ReadString('AppData');

        Fonts: Result     := ReadString('Fonts');

        SendTo: Result    := ReadString('SendTo');

        Recent: Result    := ReadString('Recent');

        Favorites: Result := ReadString('Favorites');

        Cache: Result     := ReadString('Cache');

        Cookies: Result   := ReadString('Cookies');

        History: Result   := ReadString('History');

        NetHood: Result   := ReadString('NetHood');

        PrintHood: Result := ReadString('PrintHood');

        Templates: Result := ReadString('Templates');

        LocADat: Result   := ReadString('Local AppData');

        WindRoot:

          begin

            GetMem(ph, 255);

            GetWindowsDirectory(ph, 254);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        WindSys:

          begin

            GetMem(ph, 255);

            GetSystemDirectory(ph, 254);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        TempPath:

          begin

            GetMem(ph, 255);

            GetTempPath(254, ph);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        RootDir:

          begin

            GetMem(ph, 255);

            GetSystemDirectory(ph, 254);

            Result := (Copy(Strpas(ph), 1, 2));

            Freemem(ph);

          end;

      end;

      RootKey := HKEY_LOCAL_MACHINE;

      OpenKey('SOFTWAREMicrosoftWindowsCurrentVersion', True);

      case SystemPath of

        ProgFiles: Result := ReadString('ProgramFilesDir');

        ComFiles: Result := ReadString('CommonFilesDir');

        ConfigPath: Result := ReadString('ConfigPath');

        DevicePath: Result := ReadString('DevicePath');

        MediaPath: Result := ReadString('MediaPath');

        WallPaper: Result := ReadString('WallPaperDir');

      end;

    finally

      CloseKey;

      Free;

    end;

  if (Result <> '') and (Result[Length(Result)] <> '') then

    Result := Result + '';

end;

 

//Use

procedure TForm1.Button1Click(Sender: TObject);

begin

  label1.Caption := GetSystemPath(DevicePath);

end;

 

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

 

neoturk: ...Get the pathes of the windows special folders ?...

uses

  ActiveX, ShlObj;

 

procedure TForm1.Button1Click(Sender: TObject);

// Replace CSIDL_HISTORY with the constants below

var

  Allocator: IMalloc;

  SpecialDir: PItemIdList;

  FBuf: array[0..MAX_PATH] of Char;

  PerDir: string;

begin

  if SHGetMalloc(Allocator) = NOERROR then

  begin

    SHGetSpecialFolderLocation(Form1.Handle, CSIDL_HISTORY, SpecialDir);

    SHGetPathFromIDList(SpecialDir, @FBuf[0]);

    Allocator.Free(SpecialDir);

    ShowMessage(string(FBuf));

  end;

end;

 

// With Windows Me/2000, the SHGetSpecialFolderLocation function

// is superseded by ShGetFolderLocation.

 

 

// function to get the desktop folder location:

 

function GetDeskTopPath : string;

var

  shellMalloc: IMalloc;

  ppidl: PItemIdList;

  PerDir: string;

begin

  ppidl := nil;

  try

    if SHGetMalloc(shellMalloc) = NOERROR then

    begin

      SHGetSpecialFolderLocation(Form1.Handle, CSIDL_DESKTOP, ppidl);

      SetLength(Result, MAX_PATH);

      if not SHGetPathFromIDList(ppidl, PChar(Result)) then

        raise exception.create('SHGetPathFromIDList failed : invalid pidl');

      SetLength(Result, lStrLen(PChar(Result)));

    end;

  finally

   if ppidl <> nil then

         shellMalloc.free(ppidl);

  end;

end;

 

{

  Constants:

 

  CSIDL_DESKTOP

  CSIDL_INTERNET

  CSIDL_PROGRAMS

  CSIDL_CONTROLS

  CSIDL_PRINTERS

  CSIDL_PERSONAL

  CSIDL_FAVORITES

  CSIDL_STARTUP

  CSIDL_RECENT

  CSIDL_SENDTO

  CSIDL_BITBUCKET

  CSIDL_STARTMENU

  CSIDL_DESKTOPDIRECTORY

  CSIDL_DRIVES

  CSIDL_NETWORK

  CSIDL_NETHOOD

  CSIDL_FONTS

  CSIDL_TEMPLATES

  CSIDL_COMMON_STARTMENU

  CSIDL_COMMON_PROGRAMS

  CSIDL_COMMON_STARTUP

  CSIDL_COMMON_DESKTOPDIRECTORY

  CSIDL_APPDATA

  CSIDL_PRINTHOOD

  CSIDL_ALTSTARTUP

  CSIDL_COMMON_ALTSTARTUP

  CSIDL_COMMON_FAVORITES

  CSIDL_INTERNET_CACHE

  CSIDL_COOKIES

  CSIDL_HISTORY

}

 

 

{***********************************************************}

{ Read paths from registry. by LENIN INC }

 

uses

  Windows, SysUtils, Registry;

 

type

  TSystemPath = (Desktop, StartMenu,

    Programs, Startup, Personal, AppData,

    Fonts, SendTo, Recent, Favorites, Cache,

    Cookies, History, NetHood, PrintHood,

    Templates, LocADat, WindRoot, WindSys,

    TempPath, RootDir, ProgFiles, ComFiles,

    ConfigPath, DevicePath, MediaPath, WallPaper);

 

function GetSystemPath(SystemPath: TSystemPath): string;

var

  ph: PChar;

begin

  with TRegistry.Create do

    try

      RootKey := HKEY_CURRENT_USER;

      OpenKey('SoftwareMicrosoftWindowsCurrentVersion' +

        'ExplorerShell Folders', True);

      case SystemPath of

        Desktop: Result   := ReadString('Desktop');

        StartMenu: Result := ReadString('Start Menu');

        Programs: Result  := ReadString('Programs');

        Startup: Result   := ReadString('Startup');

        Personal: Result  := ReadString('Personal');

        AppData: Result   := ReadString('AppData');

        Fonts: Result     := ReadString('Fonts');

        SendTo: Result    := ReadString('SendTo');

        Recent: Result    := ReadString('Recent');

        Favorites: Result := ReadString('Favorites');

        Cache: Result     := ReadString('Cache');

        Cookies: Result   := ReadString('Cookies');

        History: Result   := ReadString('History');

        NetHood: Result   := ReadString('NetHood');

        PrintHood: Result := ReadString('PrintHood');

        Templates: Result := ReadString('Templates');

        LocADat: Result   := ReadString('Local AppData');

        WindRoot:

          begin

            GetMem(ph, 255);

            GetWindowsDirectory(ph, 254);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        WindSys:

          begin

            GetMem(ph, 255);

            GetSystemDirectory(ph, 254);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        TempPath:

          begin

            GetMem(ph, 255);

            GetTempPath(254, ph);

            Result := Strpas(ph);

            Freemem(ph);

          end;

        RootDir:

          begin

            GetMem(ph, 255);

            GetSystemDirectory(ph, 254);

            Result := (Copy(Strpas(ph), 1, 2));

            Freemem(ph);

          end;

      end;

      RootKey := HKEY_LOCAL_MACHINE;

      OpenKey('SOFTWAREMicrosoftWindowsCurrentVersion', True);

      case SystemPath of

        ProgFiles: Result := ReadString('ProgramFilesDir');

        ComFiles: Result := ReadString('CommonFilesDir');

        ConfigPath: Result := ReadString('ConfigPath');

        DevicePath: Result := ReadString('DevicePath');

        MediaPath: Result := ReadString('MediaPath');

        WallPaper: Result := ReadString('WallPaperDir');

      end;

    finally

      CloseKey;

      Free;

    end;

  if (Result <> '') and (Result[Length(Result)] <> '') then

    Result := Result + '';

end;

 

//Use

procedure TForm1.Button1Click(Sender: TObject);

begin

  label1.Caption := GetSystemPath(DevicePath);

end;

 

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

 

neoturk: ...Check if a file-directory exists ?...

uses

 FileCtrl;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if FileExists('c:boot.ini') then

    ShowMessage('File exists! Datei existiert!');

 

  if FileExists('c:windows') then

    ShowMessage('Directory Exists!');

end;

 

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

 

neoturk: ...Check if a file-directory exists ?...

uses

 FileCtrl;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if FileExists('c:boot.ini') then

    ShowMessage('File exists! Datei existiert!');

 

  if FileExists('c:windows') then

    ShowMessage('Directory Exists!');

end;

 

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

 

neoturk: ...Check if a file can be opened ?...

function IsFileInUse(const fName: TFileName): Boolean;

var

  HFileRes: HFILE;

begin

  Result := False;

  HFileRes := CreateFile(PChar(fName),

                         GENERIC_READ or GENERIC_WRITE,

                         0,

                         nil,

                         OPEN_EXISTING,

                         FILE_ATTRIBUTE_NORMAL,

                         0);

  Result := (HFileRes = INVALID_HANDLE_VALUE);

  if not Result then

    CloseHandle(HFileRes);

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if OpenDialog1.Execute then

    if IsFileInUse(Opendialog1.FileName) then

      ShowMessage('File is in use!');

end;

 

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

 

neoturk: ...Check if a file can be opened ?...

function IsFileInUse(const fName: TFileName): Boolean;

var

  HFileRes: HFILE;

begin

  Result := False;

  HFileRes := CreateFile(PChar(fName),

                         GENERIC_READ or GENERIC_WRITE,

                         0,

                         nil,

                         OPEN_EXISTING,

                         FILE_ATTRIBUTE_NORMAL,

                         0);

  Result := (HFileRes = INVALID_HANDLE_VALUE);

  if not Result then

    CloseHandle(HFileRes);

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if OpenDialog1.Execute then

    if IsFileInUse(Opendialog1.FileName) then

      ShowMessage('File is in use!');

end;

 

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

 

neoturk: ...Set a file's date ?...

function SetFileDateTime(FileName: string; NewDateTime: TDateTime): Boolean;

var

  FileHandle: Integer;

  FileTime: TFileTime;

  LFT: TFileTime;

  LST: TSystemTime;

begin

  Result := False;

  try

    DecodeDate(NewDateTime, LST.wYear, LST.wMonth, LST.wDay);

    DecodeTime(NewDateTime, LST.wHour, LST.wMinute, LST.wSecond, LST.wMilliSeconds);

    if SystemTimeToFileTime(LST, LFT) then

    begin

      if LocalFileTimeToFileTime(LFT, FileTime) then

      begin

        FileHandle := FileOpen(FileName, fmOpenReadWrite or

          fmShareExclusive);

        if SetFileTime(FileHandle, nil, nil, @FileTime) then

          Result := True;

      end;

    end;

  finally

    FileClose(FileHandle);

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if OpenDialog1.Execute then

    if SetFileDateTime(OpenDialog1.FileName, now) then

      ShowMessage('Date set to now !');

end;

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