Programlama yapalım ve Öğrenelim. - Delphi Eğitim186
  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: ...Ensure that a path name ends with a delimiter '' ?...

{

For People (as I am) who can't manage with all of this function names and

forget some "jewels".

You should sometimes "rename" such procedures if it helps you to remember.

}

 

{

Die Unit Sysutils verbirgt einige Funktionen, die oft in Vergessenheit

geraten.

Kapselt die Funktion aus "Sysutils" in einer Funktion mit einem

"ansprechenden" Namen.

}

 

 

{ IncludeTrailingBackslash }

 

// Adds '' to the end of a string if it is not already there.

// Die Funktion gibt einen Pfadnamen mit dem abschließenden Zeichen '' zurück.

 

function CheckPfadEnd(const P: string): string;

begin

Result := IncludeTrailingBackslash(P);

end;

 

 

{ ExcludeTrailingBackslash }

 

// Removes one '' from the end of a string if it is there.

// Die Funktion gibt einen Pfadnamen ohne das abschließende Zeichen zurück.

 

 

MyDir := ExcludeTrailingBackslash('c:Windows');

// ---> MyDir = c:Windows

 

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

 

neoturk: ...Ensure that a path name ends with a delimiter '' ?...

{

For People (as I am) who can't manage with all of this function names and

forget some "jewels".

You should sometimes "rename" such procedures if it helps you to remember.

}

 

{

Die Unit Sysutils verbirgt einige Funktionen, die oft in Vergessenheit

geraten.

Kapselt die Funktion aus "Sysutils" in einer Funktion mit einem

"ansprechenden" Namen.

}

 

 

{ IncludeTrailingBackslash }

 

// Adds '' to the end of a string if it is not already there.

// Die Funktion gibt einen Pfadnamen mit dem abschließenden Zeichen '' zurück.

 

function CheckPfadEnd(const P: string): string;

begin

Result := IncludeTrailingBackslash(P);

end;

 

 

{ ExcludeTrailingBackslash }

 

// Removes one '' from the end of a string if it is there.

// Die Funktion gibt einen Pfadnamen ohne das abschließende Zeichen zurück.

 

 

MyDir := ExcludeTrailingBackslash('c:Windows');

// ---> MyDir = c:Windows

 

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

 

neoturk: ...Replace text in a text file ?...

procedure FileReplaceString(const FileName, searchstring, replacestring: string);

var

  fs: TFileStream;

  S: string;

begin

  fs := TFileStream.Create(FileName, fmOpenread or fmShareDenyNone);

  try

    SetLength(S, fs.Size);

    fs.ReadBuffer(S[1], fs.Size);

  finally

    fs.Free;

  end;

  S  := StringReplace(S, SearchString, replaceString, [rfReplaceAll, rfIgnoreCase]);

  fs := TFileStream.Create(FileName, fmCreate);

  try

    fs.WriteBuffer(S[1], Length(S));

  finally

    fs.Free;

  end;

end;

 

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

 

neoturk: ...Replace text in a text file ?...

procedure FileReplaceString(const FileName, searchstring, replacestring: string);

var

  fs: TFileStream;

  S: string;

begin

  fs := TFileStream.Create(FileName, fmOpenread or fmShareDenyNone);

  try

    SetLength(S, fs.Size);

    fs.ReadBuffer(S[1], fs.Size);

  finally

    fs.Free;

  end;

  S  := StringReplace(S, SearchString, replaceString, [rfReplaceAll, rfIgnoreCase]);

  fs := TFileStream.Create(FileName, fmCreate);

  try

    fs.WriteBuffer(S[1], Length(S));

  finally

    fs.Free;

  end;

end;

 

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

 

neoturk: ...Retrieve version information for a specified file ?...

uses

  ShellApi;

 

type

  TFileVersionInfo = record

    FileType,

    CompanyName,

    FileDescription,

    FileVersion,

    InternalName,

    LegalCopyRight,

    LegalTradeMarks,

    OriginalFileName,

    ProductName,

    ProductVersion,

    Comments,

    SpecialBuildStr,

    PrivateBuildStr,

    FileFunction: string;

    DebugBuild,

    PreRelease,

    SpecialBuild,

    PrivateBuild,

    Patched,

    InfoInferred: Boolean;

  end;

 

function FileVersionInfo(const sAppNamePath: TFileName): TFileVersionInfo;

var

  rSHFI: TSHFileInfo;

  iRet: Integer;

  VerSize: Integer;

  VerBuf: PChar;

  VerBufValue: Pointer;

  VerHandle: Cardinal;

  VerBufLen: Cardinal;

  VerKey: string;

  FixedFileInfo: PVSFixedFileInfo;

 

  // dwFileType, dwFileSubtype

  function GetFileSubType(FixedFileInfo: PVSFixedFileInfo): string;

  begin

    case FixedFileInfo.dwFileType of

 

      VFT_UNKNOWN: Result    := 'Unknown';

      VFT_APP: Result        := 'Application';

      VFT_DLL: Result        := 'DLL';

      VFT_STATIC_LIB: Result := 'Static-link Library';

 

      VFT_DRV:

        case

          FixedFileInfo.dwFileSubtype of

          VFT2_UNKNOWN: Result         := 'Unknown Driver';

          VFT2_DRV_COMM: Result        := 'Communications Driver';

          VFT2_DRV_PRINTER: Result     := 'Printer Driver';

          VFT2_DRV_KEYBOARD: Result    := 'Keyboard Driver';

          VFT2_DRV_LANGUAGE: Result    := 'Language Driver';

          VFT2_DRV_DISPLAY: Result     := 'Display Driver';

          VFT2_DRV_MOUSE: Result       := 'Mouse Driver';

          VFT2_DRV_NETWORK: Result     := 'Network Driver';

          VFT2_DRV_SYSTEM: Result      := 'System Driver';

          VFT2_DRV_INSTALLABLE: Result := 'InstallableDriver';

          VFT2_DRV_SOUND: Result       := 'Sound Driver';

        end;

      VFT_FONT:

        case FixedFileInfo.dwFileSubtype of

          VFT2_UNKNOWN: Result       := 'Unknown Font';

          VFT2_FONT_RASTER: Result   := 'Raster Font';

          VFT2_FONT_VECTOR: Result   := 'Vector Font';

          VFT2_FONT_TRUETYPE: Result := 'Truetype Font';

          else;

        end;

      VFT_VXD: Result := 'Virtual Defice Identifier = ' +

          IntToHex(FixedFileInfo.dwFileSubtype, 8);

    end;

  end;

 

 

  function HasdwFileFlags(FixedFileInfo: PVSFixedFileInfo; Flag: Word): Boolean;

  begin

    Result := (FixedFileInfo.dwFileFlagsMask and

      FixedFileInfo.dwFileFlags and

      Flag) = Flag;

  end;

 

  function GetFixedFileInfo: PVSFixedFileInfo;

  begin

    if not VerQueryValue(VerBuf, '', Pointer(Result), VerBufLen) then

      Result := nil

  end;

 

  function GetInfo(const aKey: string): string;

  begin

    Result := '';

    VerKey := Format('StringFileInfo%.4x%.4x%s',

      [LoWord(Integer(VerBufValue^)),

      HiWord(Integer(VerBufValue^)), aKey]);

    if VerQueryValue(VerBuf, PChar(VerKey), VerBufValue, VerBufLen) then

      Result := StrPas(VerBufValue);

  end;

 

  function QueryValue(const aValue: string): string;

  begin

    Result := '';

    // obtain version information about the specified file

    if GetFileVersionInfo(PChar(sAppNamePath), VerHandle, VerSize, VerBuf) and

      // return selected version information

      VerQueryValue(VerBuf, 'VarFileInfoTranslation', VerBufValue, VerBufLen) then

      Result := GetInfo(aValue);

  end;

begin

  // Initialize the Result

  with Result do

  begin

    FileType         := '';

    CompanyName      := '';

    FileDescription  := '';

    FileVersion      := '';

    InternalName     := '';

    LegalCopyRight   := '';

    LegalTradeMarks  := '';

    OriginalFileName := '';

    ProductName      := '';

    ProductVersion   := '';

    Comments         := '';

    SpecialBuildStr  := '';

    PrivateBuildStr  := '';

    FileFunction     := '';

    DebugBuild       := False;

    Patched          := False;

    PreRelease       := False;

    SpecialBuild     := False;

    PrivateBuild     := False;

    InfoInferred     := False;

  end;

 

  // Get the file type

  if SHGetFileInfo(PChar(sAppNamePath), 0, rSHFI, SizeOf(rSHFI),

    SHGFI_TYPENAME) <> 0 then

  begin

    Result.FileType := rSHFI.szTypeName;

  end;

 

  iRet := SHGetFileInfo(PChar(sAppNamePath), 0, rSHFI, SizeOf(rSHFI), SHGFI_EXETYPE);

  if iRet <> 0 then

  begin

    // determine whether the OS can obtain version information

    VerSize := GetFileVersionInfoSize(PChar(sAppNamePath), VerHandle);

    if VerSize > 0 then

    begin

      VerBuf := AllocMem(VerSize);

      try

        with Result do

        begin

          CompanyName      := QueryValue('CompanyName');

          FileDescription  := QueryValue('FileDescription');

          FileVersion      := QueryValue('FileVersion');

          InternalName     := QueryValue('InternalName');

          LegalCopyRight   := QueryValue('LegalCopyRight');

          LegalTradeMarks  := QueryValue('LegalTradeMarks');

          OriginalFileName := QueryValue('OriginalFileName');

          ProductName      := QueryValue('ProductName');

          ProductVersion   := QueryValue('ProductVersion');

          Comments         := QueryValue('Comments');

          SpecialBuildStr  := QueryValue('SpecialBuild');

          PrivateBuildStr  := QueryValue('PrivateBuild');

          // Fill the VS_FIXEDFILEINFO structure

          FixedFileInfo := GetFixedFileInfo;

          DebugBuild    := HasdwFileFlags(FixedFileInfo, VS_FF_DEBUG);

          PreRelease    := HasdwFileFlags(FixedFileInfo, VS_FF_PRERELEASE);

          PrivateBuild  := HasdwFileFlags(FixedFileInfo, VS_FF_PRIVATEBUILD);

          SpecialBuild  := HasdwFileFlags(FixedFileInfo, VS_FF_SPECIALBUILD);

          Patched       := HasdwFileFlags(FixedFileInfo, VS_FF_PATCHED);

          InfoInferred  := HasdwFileFlags(FixedFileInfo, VS_FF_INFOINFERRED);

          FileFunction  := GetFileSubType(FixedFileInfo);

        end;

      finally

        FreeMem(VerBuf, VerSize);

      end

    end;

  end

end;

 

// Test it:

 

procedure TForm1.Button1Click(Sender: TObject);

var

  FvI: TFileVersionInfo;

const

  Tabulator: array[0..0] of Integer = (70);

  BoolValues: array[Boolean] of string = ('No', 'Yes');

begin

  FvI := FileVersionInfo('C:FileName.exe');

  ListBox1.TabWidth := 1;

  SendMessage(ListBox1.Handle, LB_SETTABSTOPS, 1, Longint(@Tabulator));

  with FvI, ListBox1.Items do

  begin

    Add('FileType:'#9 + FileType);

    Add('CompanyName:'#9 + CompanyName);

    Add('FileDescription:'#9 + FileDescription); // siehe Eigenschaftsdialog des Explorers

    Add('FileVersion:'#9 + FileVersion);

    Add('InternalName:'#9 + InternalName);

    Add('LegalCopyRight:'#9 + LegalCopyRight);

    Add('LegalTradeMarks:'#9 + LegalTradeMarks);

    Add('OriginalFileName:'#9 + OriginalFileName);

    Add('ProductName:'#9 + ProductName);

    Add('ProductVersion:'#9 + ProductVersion);

    Add('SpecialBuildStr:'#9 + SpecialBuildStr);

    Add('PrivateBuildStr:'#9 + PrivateBuildStr);

    Add('FileFunction:'#9 + FileFunction);

    Add('DebugBuild:'#9 + BoolValues[DebugBuild]);

    Add('PreRelease:'#9 + BoolValues[PreRelease]);

    Add('PrivateBuild:'#9 + BoolValues[PrivateBuild]);

    Add('SpecialBuild:'#9 + BoolValues[SpecialBuild]);

  end;

end;

 

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

 

neoturk: ...Retrieve version information for a specified file ?...

uses

  ShellApi;

 

type

  TFileVersionInfo = record

    FileType,

    CompanyName,

    FileDescription,

    FileVersion,

    InternalName,

    LegalCopyRight,

    LegalTradeMarks,

    OriginalFileName,

    ProductName,

    ProductVersion,

    Comments,

    SpecialBuildStr,

    PrivateBuildStr,

    FileFunction: string;

    DebugBuild,

    PreRelease,

    SpecialBuild,

    PrivateBuild,

    Patched,

    InfoInferred: Boolean;

  end;

 

function FileVersionInfo(const sAppNamePath: TFileName): TFileVersionInfo;

var

  rSHFI: TSHFileInfo;

  iRet: Integer;

  VerSize: Integer;

  VerBuf: PChar;

  VerBufValue: Pointer;

  VerHandle: Cardinal;

  VerBufLen: Cardinal;

  VerKey: string;

  FixedFileInfo: PVSFixedFileInfo;

 

  // dwFileType, dwFileSubtype

  function GetFileSubType(FixedFileInfo: PVSFixedFileInfo): string;

  begin

    case FixedFileInfo.dwFileType of

 

      VFT_UNKNOWN: Result    := 'Unknown';

      VFT_APP: Result        := 'Application';

      VFT_DLL: Result        := 'DLL';

      VFT_STATIC_LIB: Result := 'Static-link Library';

 

      VFT_DRV:

        case

          FixedFileInfo.dwFileSubtype of

          VFT2_UNKNOWN: Result         := 'Unknown Driver';

          VFT2_DRV_COMM: Result        := 'Communications Driver';

          VFT2_DRV_PRINTER: Result     := 'Printer Driver';

          VFT2_DRV_KEYBOARD: Result    := 'Keyboard Driver';

          VFT2_DRV_LANGUAGE: Result    := 'Language Driver';

          VFT2_DRV_DISPLAY: Result     := 'Display Driver';

          VFT2_DRV_MOUSE: Result       := 'Mouse Driver';

          VFT2_DRV_NETWORK: Result     := 'Network Driver';

          VFT2_DRV_SYSTEM: Result      := 'System Driver';

          VFT2_DRV_INSTALLABLE: Result := 'InstallableDriver';

          VFT2_DRV_SOUND: Result       := 'Sound Driver';

        end;

      VFT_FONT:

        case FixedFileInfo.dwFileSubtype of

          VFT2_UNKNOWN: Result       := 'Unknown Font';

          VFT2_FONT_RASTER: Result   := 'Raster Font';

          VFT2_FONT_VECTOR: Result   := 'Vector Font';

          VFT2_FONT_TRUETYPE: Result := 'Truetype Font';

          else;

        end;

      VFT_VXD: Result := 'Virtual Defice Identifier = ' +

          IntToHex(FixedFileInfo.dwFileSubtype, 8);

    end;

  end;

 

 

  function HasdwFileFlags(FixedFileInfo: PVSFixedFileInfo; Flag: Word): Boolean;

  begin

    Result := (FixedFileInfo.dwFileFlagsMask and

      FixedFileInfo.dwFileFlags and

      Flag) = Flag;

  end;

 

  function GetFixedFileInfo: PVSFixedFileInfo;

  begin

    if not VerQueryValue(VerBuf, '', Pointer(Result), VerBufLen) then

      Result := nil

  end;

 

  function GetInfo(const aKey: string): string;

  begin

    Result := '';

    VerKey := Format('StringFileInfo%.4x%.4x%s',

      [LoWord(Integer(VerBufValue^)),

      HiWord(Integer(VerBufValue^)), aKey]);

    if VerQueryValue(VerBuf, PChar(VerKey), VerBufValue, VerBufLen) then

      Result := StrPas(VerBufValue);

  end;

 

  function QueryValue(const aValue: string): string;

  begin

    Result := '';

    // obtain version information about the specified file

    if GetFileVersionInfo(PChar(sAppNamePath), VerHandle, VerSize, VerBuf) and

      // return selected version information

      VerQueryValue(VerBuf, 'VarFileInfoTranslation', VerBufValue, VerBufLen) then

      Result := GetInfo(aValue);

  end;

begin

  // Initialize the Result

  with Result do

  begin

    FileType         := '';

    CompanyName      := '';

    FileDescription  := '';

    FileVersion      := '';

    InternalName     := '';

    LegalCopyRight   := '';

    LegalTradeMarks  := '';

    OriginalFileName := '';

    ProductName      := '';

    ProductVersion   := '';

    Comments         := '';

    SpecialBuildStr  := '';

    PrivateBuildStr  := '';

    FileFunction     := '';

    DebugBuild       := False;

    Patched          := False;

    PreRelease       := False;

    SpecialBuild     := False;

    PrivateBuild     := False;

    InfoInferred     := False;

  end;

 

  // Get the file type

  if SHGetFileInfo(PChar(sAppNamePath), 0, rSHFI, SizeOf(rSHFI),

    SHGFI_TYPENAME) <> 0 then

  begin

    Result.FileType := rSHFI.szTypeName;

  end;

 

  iRet := SHGetFileInfo(PChar(sAppNamePath), 0, rSHFI, SizeOf(rSHFI), SHGFI_EXETYPE);

  if iRet <> 0 then

  begin

    // determine whether the OS can obtain version information

    VerSize := GetFileVersionInfoSize(PChar(sAppNamePath), VerHandle);

    if VerSize > 0 then

    begin

      VerBuf := AllocMem(VerSize);

      try

        with Result do

        begin

          CompanyName      := QueryValue('CompanyName');

          FileDescription  := QueryValue('FileDescription');

          FileVersion      := QueryValue('FileVersion');

          InternalName     := QueryValue('InternalName');

          LegalCopyRight   := QueryValue('LegalCopyRight');

          LegalTradeMarks  := QueryValue('LegalTradeMarks');

          OriginalFileName := QueryValue('OriginalFileName');

          ProductName      := QueryValue('ProductName');

          ProductVersion   := QueryValue('ProductVersion');

          Comments         := QueryValue('Comments');

          SpecialBuildStr  := QueryValue('SpecialBuild');

          PrivateBuildStr  := QueryValue('PrivateBuild');

          // Fill the VS_FIXEDFILEINFO structure

          FixedFileInfo := GetFixedFileInfo;

          DebugBuild    := HasdwFileFlags(FixedFileInfo, VS_FF_DEBUG);

          PreRelease    := HasdwFileFlags(FixedFileInfo, VS_FF_PRERELEASE);

          PrivateBuild  := HasdwFileFlags(FixedFileInfo, VS_FF_PRIVATEBUILD);

          SpecialBuild  := HasdwFileFlags(FixedFileInfo, VS_FF_SPECIALBUILD);

          Patched       := HasdwFileFlags(FixedFileInfo, VS_FF_PATCHED);

          InfoInferred  := HasdwFileFlags(FixedFileInfo, VS_FF_INFOINFERRED);

          FileFunction  := GetFileSubType(FixedFileInfo);

        end;

      finally

        FreeMem(VerBuf, VerSize);

      end

    end;

  end

end;

 

// Test it:

 

procedure TForm1.Button1Click(Sender: TObject);

var

  FvI: TFileVersionInfo;

const

  Tabulator: array[0..0] of Integer = (70);

  BoolValues: array[Boolean] of string = ('No', 'Yes');

begin

  FvI := FileVersionInfo('C:FileName.exe');

  ListBox1.TabWidth := 1;

  SendMessage(ListBox1.Handle, LB_SETTABSTOPS, 1, Longint(@Tabulator));

  with FvI, ListBox1.Items do

  begin

    Add('FileType:'#9 + FileType);

    Add('CompanyName:'#9 + CompanyName);

    Add('FileDescription:'#9 + FileDescription); // siehe Eigenschaftsdialog des Explorers

    Add('FileVersion:'#9 + FileVersion);

    Add('InternalName:'#9 + InternalName);

    Add('LegalCopyRight:'#9 + LegalCopyRight);

    Add('LegalTradeMarks:'#9 + LegalTradeMarks);

    Add('OriginalFileName:'#9 + OriginalFileName);

    Add('ProductName:'#9 + ProductName);

    Add('ProductVersion:'#9 + ProductVersion);

    Add('SpecialBuildStr:'#9 + SpecialBuildStr);

    Add('PrivateBuildStr:'#9 + PrivateBuildStr);

    Add('FileFunction:'#9 + FileFunction);

    Add('DebugBuild:'#9 + BoolValues[DebugBuild]);

    Add('PreRelease:'#9 + BoolValues[PreRelease]);

    Add('PrivateBuild:'#9 + BoolValues[PrivateBuild]);

    Add('SpecialBuild:'#9 + BoolValues[SpecialBuild]);

  end;

end;

 

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

 

neoturk: ...Search a directory tree for a specified file ?...

uses

  ImageHlp;

 

function SearchForFile(const ARootPath: string;

                       const AFileName: string;

                       var APathFound: string): Boolean;

var

  Found: array[0..500] of Char;

begin

  FillChar(Found, SizeOf(Found), #00);

  Result := (SearchTreeForFile(PChar(ARootPath), PChar(AFileName), Found) = True);

  APathFound := ExtractFilePath(Found);

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  APathFound: string;

begin

  if SearchForFile('C:WINDOWS', 'winhlp32.exe', APathFound) then

    ShowMessage('winhlp32.exe found in: ' + APathFound);

end;

 

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

 

neoturk: ...Search a directory tree for a specified file ?...

uses

  ImageHlp;

 

function SearchForFile(const ARootPath: string;

                       const AFileName: string;

                       var APathFound: string): Boolean;

var

  Found: array[0..500] of Char;

begin

  FillChar(Found, SizeOf(Found), #00);

  Result := (SearchTreeForFile(PChar(ARootPath), PChar(AFileName), Found) = True);

  APathFound := ExtractFilePath(Found);

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  APathFound: string;

begin

  if SearchForFile('C:WINDOWS', 'winhlp32.exe', APathFound) then

    ShowMessage('winhlp32.exe found in: ' + APathFound);

end;

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