Programlama yapalım ve Öğrenelim. - Delphi Eğitim181
  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: ...Get the free, total size of a disk disk volume ?...

{

  * Place a Button1 and DriveComboBox1 on your form.

  * The function "SetCurrentDir" well be true if the disk in drive

  * The procedure "GetDiskFreeSpaceEx" returns the free and total disk size

}

 

uses

  SysUtils;

 

implementation

 

function GetDiskSize(drive: Char; var free_size, total_size: Int64): Boolean;

var

  RootPath: array[0..4] of Char;

  RootPtr: PChar;

  current_dir: string;

begin

  RootPath[0] := Drive;

  RootPath[1] := ':';

  RootPath[2] := '';

  RootPath[3] := #0;

  RootPtr := RootPath;

  current_dir := GetCurrentDir;

  if SetCurrentDir(drive + ':') then

  begin

    GetDiskFreeSpaceEx(RootPtr, Free_size, Total_size, nil);

    // this to turn back to original dir

    SetCurrentDir(current_dir);

    Result := True;

  end

  else

  begin

    Result := False;

    Free_size  := -1;

    Total_size := -1;

  end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

  free_size, total_size: Int64;

begin

  if GetDiskSize(DriveComboBox1.Drive, free_size, total_size) then

    ShowMessage('free space =' +

      IntToStr(free_size) + #13 + 'total size=' +

      IntToStr(total_size))

  else

    ShowMessage('No disk in drive!');

end;

 

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

 

neoturk: ...Get the free, total size of a disk disk volume ?...

{

  * Place a Button1 and DriveComboBox1 on your form.

  * The function "SetCurrentDir" well be true if the disk in drive

  * The procedure "GetDiskFreeSpaceEx" returns the free and total disk size

}

 

uses

  SysUtils;

 

implementation

 

function GetDiskSize(drive: Char; var free_size, total_size: Int64): Boolean;

var

  RootPath: array[0..4] of Char;

  RootPtr: PChar;

  current_dir: string;

begin

  RootPath[0] := Drive;

  RootPath[1] := ':';

  RootPath[2] := '';

  RootPath[3] := #0;

  RootPtr := RootPath;

  current_dir := GetCurrentDir;

  if SetCurrentDir(drive + ':') then

  begin

    GetDiskFreeSpaceEx(RootPtr, Free_size, Total_size, nil);

    // this to turn back to original dir

    SetCurrentDir(current_dir);

    Result := True;

  end

  else

  begin

    Result := False;

    Free_size  := -1;

    Total_size := -1;

  end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

  free_size, total_size: Int64;

begin

  if GetDiskSize(DriveComboBox1.Drive, free_size, total_size) then

    ShowMessage('free space =' +

      IntToStr(free_size) + #13 + 'total size=' +

      IntToStr(total_size))

  else

    ShowMessage('No disk in drive!');

end;

 

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

 

neoturk: ...Concatenate and compress files into one destination file ?...

uses

  Zlib;

 

procedure CompressFiles(Files : TStrings; const Filename : String);

var

  infile, outfile, tmpFile : TFileStream;

  compr : TCompressionStream;

  i,l : Integer;

  s : String;

 

begin

  if Files.Count > 0 then

  begin

    outFile := TFileStream.Create(Filename,fmCreate);

    try

      { the number of files }

      l := Files.Count;

      outfile.Write(l,SizeOf(l));

      for i := 0 to Files.Count-1 do

      begin

        infile := TFileStream.Create(Files[i],fmOpenRead);

        try

          { the original filename }

          s := ExtractFilename(Files[i]);

          l := Length(s);

          outfile.Write(l,SizeOf(l));

          outfile.Write(s[1],l);

          { the original filesize }

          l := infile.Size;

          outfile.Write(l,SizeOf(l));

          { compress and store the file temporary}

          tmpFile := TFileStream.Create('tmp',fmCreate);

          compr := TCompressionStream.Create(clMax,tmpfile);

          try

            compr.CopyFrom(infile,l);

          finally

            compr.Free;

            tmpFile.Free;

          end;

          { append the compressed file to the destination file }

          tmpFile := TFileStream.Create('tmp',fmOpenRead);

          try

            outfile.CopyFrom(tmpFile,0);

          finally

            tmpFile.Free;

          end;

        finally

          infile.Free;

        end;

      end;

    finally

      outfile.Free;

    end;

    DeleteFile('tmp');

  end;

end;

 

procedure DecompressFiles(const Filename, DestDirectory : String);

var

  dest,s : String;

  decompr : TDecompressionStream;

  infile, outfile : TFilestream;

  i,l,c : Integer;

begin

  // IncludeTrailingPathDelimiter (D6/D7 only)

  dest := IncludeTrailingPathDelimiter(DestDirectory);

 

  infile := TFileStream.Create(Filename,fmOpenRead);

  try

    { number of files }

    infile.Read(c,SizeOf(c));

    for i := 1 to c do

    begin

      { read filename }

      infile.Read(l,SizeOf(l));

      SetLength(s,l);

      infile.Read(s[1],l);

      { read filesize }

      infile.Read(l,SizeOf(l));

      { decompress the files and store it }

      s := dest+s; //include the path

      outfile := TFileStream.Create(s,fmCreate);

      decompr := TDecompressionStream.Create(infile);

      try

        outfile.CopyFrom(decompr,l);

      finally

        outfile.Free;

        decompr.Free;

      end;

    end;

  finally

    infile.Free;

  end;

end;

 

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

 

neoturk: ...Concatenate and compress files into one destination file ?...

uses

  Zlib;

 

procedure CompressFiles(Files : TStrings; const Filename : String);

var

  infile, outfile, tmpFile : TFileStream;

  compr : TCompressionStream;

  i,l : Integer;

  s : String;

 

begin

  if Files.Count > 0 then

  begin

    outFile := TFileStream.Create(Filename,fmCreate);

    try

      { the number of files }

      l := Files.Count;

      outfile.Write(l,SizeOf(l));

      for i := 0 to Files.Count-1 do

      begin

        infile := TFileStream.Create(Files[i],fmOpenRead);

        try

          { the original filename }

          s := ExtractFilename(Files[i]);

          l := Length(s);

          outfile.Write(l,SizeOf(l));

          outfile.Write(s[1],l);

          { the original filesize }

          l := infile.Size;

          outfile.Write(l,SizeOf(l));

          { compress and store the file temporary}

          tmpFile := TFileStream.Create('tmp',fmCreate);

          compr := TCompressionStream.Create(clMax,tmpfile);

          try

            compr.CopyFrom(infile,l);

          finally

            compr.Free;

            tmpFile.Free;

          end;

          { append the compressed file to the destination file }

          tmpFile := TFileStream.Create('tmp',fmOpenRead);

          try

            outfile.CopyFrom(tmpFile,0);

          finally

            tmpFile.Free;

          end;

        finally

          infile.Free;

        end;

      end;

    finally

      outfile.Free;

    end;

    DeleteFile('tmp');

  end;

end;

 

procedure DecompressFiles(const Filename, DestDirectory : String);

var

  dest,s : String;

  decompr : TDecompressionStream;

  infile, outfile : TFilestream;

  i,l,c : Integer;

begin

  // IncludeTrailingPathDelimiter (D6/D7 only)

  dest := IncludeTrailingPathDelimiter(DestDirectory);

 

  infile := TFileStream.Create(Filename,fmOpenRead);

  try

    { number of files }

    infile.Read(c,SizeOf(c));

    for i := 1 to c do

    begin

      { read filename }

      infile.Read(l,SizeOf(l));

      SetLength(s,l);

      infile.Read(s[1],l);

      { read filesize }

      infile.Read(l,SizeOf(l));

      { decompress the files and store it }

      s := dest+s; //include the path

      outfile := TFileStream.Create(s,fmCreate);

      decompr := TDecompressionStream.Create(infile);

      try

        outfile.CopyFrom(decompr,l);

      finally

        outfile.Free;

        decompr.Free;

      end;

    end;

  finally

    infile.Free;

  end;

end;

 

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

 

neoturk: ...Change-read the document properties for a specified word document ?...

{ 1. Change MS Word properties via OLE }

 

uses

  ComObj;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  wdPropertyTitle = $00000001;

  wdPropertySubject = $00000002;

  wdPropertyAuthor = $00000003;

  wdPropertyKeywords = $00000004;

  wdPropertyComments = $00000005;

  wdPropertyTemplate = $00000006;

  wdPropertyLastAuthor = $00000007;

  wdPropertyRevision = $00000008;

  wdPropertyAppName = $00000009;

  wdPropertyTimeLastPrinted = $0000000A;

  wdPropertyTimeCreated = $0000000B;

  wdPropertyTimeLastSaved = $0000000C;

  wdPropertyVBATotalEdit = $0000000D;

  wdPropertyPages = $0000000E;

  wdPropertyWords = $0000000F;

  wdPropertyCharacters = $00000010;

  wdPropertySecurity = $00000011;

  wdPropertyCategory = $00000012;

  wdPropertyFormat = $00000013;

  wdPropertyManager = $00000014;

  wdPropertyCompany = $00000015;

  wdPropertyBytes = $00000016;

  wdPropertyLines = $00000017;

  wdPropertyParas = $00000018;

  wdPropertySlides = $00000019;

  wdPropertyNotes = $0000001A;

  wdPropertyHiddenSlides = $0000001B;

  wdPropertyMMClips = $0000001C;

  wdPropertyHyperlinkBase = $0000001D;

  wdPropertyCharsWSpaces = $0000001E;

const

  AWordDoc = 'C:Test.doc';

  wdSaveChanges = $FFFFFFFF;

var

  WordApp: OLEVariant;

  SaveChanges: OleVariant;

begin

  try

    WordApp := CreateOleObject('Word.Application');

  except

    // Error....

    Exit;

  end;

  try

    WordApp.Visible := False;

    WordApp.Documents.Open(AWordDoc);

    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertyTitle].Value := 'Your Title...';

    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertySubject].Value := 'Your Subject...';

    // ...

    // ...

  finally

    SaveChanges := wdSaveChanges;

    WordApp.Quit(SaveChanges, EmptyParam, EmptyParam);

  end;

end;

 

 

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

 

 

{

  2. Read MS Word properties via Structured Storage.

  by Serhiy Perevoznyk

}

uses

  ComObj, ActiveX;

 

const

  FmtID_SummaryInformation: TGUID =

    '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';

 

function FileTimeToDateTimeStr(F: TFileTime): string;

var

  LocalFileTime: TFileTime;

  SystemTime: TSystemTime;

  DateTime: TDateTime;

begin

  if Comp(F) = 0 then Result := '-'

  else

  begin

    FileTimeToLocalFileTime(F, LocalFileTime);

    FileTimeToSystemTime(LocalFileTime, SystemTime);

    with SystemTime do

      DateTime := EncodeDate(wYear, wMonth, wDay) +

        EncodeTime(wHour, wMinute, wSecond, wMilliseconds);

    Result := DateTimeToStr(DateTime);

  end;

end;

 

function GetDocInfo(const FileName: WideString): string;

var

  I: Integer;

  PropSetStg: IPropertySetStorage;

  PropSpec: array[2..19] of TPropSpec;

  PropStg: IPropertyStorage;

  PropVariant: array[2..19] of TPropVariant;

  Rslt: HResult;

  S: string;

  Stg: IStorage;

begin

  Result := '';

  try

    OleCheck(StgOpenStorage(PWideChar(FileName), nil, STGM_READ or

      STGM_SHARE_DENY_WRITE,

      nil, 0, Stg));

    PropSetStg := Stg as IPropertySetStorage;

    OleCheck(PropSetStg.Open(FmtID_SummaryInformation,

      STGM_READ or STGM_SHARE_EXCLUSIVE, PropStg));

    for I := 2 to 19 do

    begin

      PropSpec[I].ulKind := PRSPEC_PROPID;

      PropSpec[I].PropID := I;

    end;

    Rslt := PropStg.ReadMultiple(18, @PropSpec, @PropVariant);

    OleCheck(Rslt);

    if Rslt <> S_FALSE then for I := 2 to 19 do

      begin

        S := '';

        if PropVariant[I].vt = VT_LPSTR then

          if Assigned(PropVariant[I].pszVal) then

            S := PropVariant[I].pszVal;

        case I of

          2:  S  := Format('Title: %s', [S]);

          3:  S  := Format('Subject: %s', [S]);

          4:  S  := Format('Author: %s', [S]);

          5:  S  := Format('Keywords: %s', [S]);

          6:  S  := Format('Comments: %s', [S]);

          7:  S  := Format('Template: %s', [S]);

          8:  S  := Format('Last saved by: %s', [S]);

          9:  S  := Format('Revision number: %s', [S]);

          10: S := Format('Total editing time: %g sec',

              [Comp(PropVariant[I].filetime) / 1.0E9]);

          11: S := Format('Last printed: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          12: S := Format('Create time/date: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          13: S := Format('Last saved time/date: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          14: S := Format('Number of pages: %d', [PropVariant[I].lVal]);

          15: S := Format('Number of words: %d', [PropVariant[I].lVal]);

          16: S := Format('Number of characters: %d',

              [PropVariant[I].lVal]);

          17:; // thumbnail

          18: S := Format('Name of creating application: %s', [S]);

          19: S := Format('Security: %.8x', [PropVariant[I].lVal]);

        end;

        if S <> '' then Result := Result + S + #13;

      end;

  finally

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if Opendialog1.Execute then

    ShowMessage(GetDocInfo(opendialog1.FileName));

end;

 

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

 

neoturk: ...Change-read the document properties for a specified word document ?...

{ 1. Change MS Word properties via OLE }

 

uses

  ComObj;

 

procedure TForm1.Button1Click(Sender: TObject);

const

  wdPropertyTitle = $00000001;

  wdPropertySubject = $00000002;

  wdPropertyAuthor = $00000003;

  wdPropertyKeywords = $00000004;

  wdPropertyComments = $00000005;

  wdPropertyTemplate = $00000006;

  wdPropertyLastAuthor = $00000007;

  wdPropertyRevision = $00000008;

  wdPropertyAppName = $00000009;

  wdPropertyTimeLastPrinted = $0000000A;

  wdPropertyTimeCreated = $0000000B;

  wdPropertyTimeLastSaved = $0000000C;

  wdPropertyVBATotalEdit = $0000000D;

  wdPropertyPages = $0000000E;

  wdPropertyWords = $0000000F;

  wdPropertyCharacters = $00000010;

  wdPropertySecurity = $00000011;

  wdPropertyCategory = $00000012;

  wdPropertyFormat = $00000013;

  wdPropertyManager = $00000014;

  wdPropertyCompany = $00000015;

  wdPropertyBytes = $00000016;

  wdPropertyLines = $00000017;

  wdPropertyParas = $00000018;

  wdPropertySlides = $00000019;

  wdPropertyNotes = $0000001A;

  wdPropertyHiddenSlides = $0000001B;

  wdPropertyMMClips = $0000001C;

  wdPropertyHyperlinkBase = $0000001D;

  wdPropertyCharsWSpaces = $0000001E;

const

  AWordDoc = 'C:Test.doc';

  wdSaveChanges = $FFFFFFFF;

var

  WordApp: OLEVariant;

  SaveChanges: OleVariant;

begin

  try

    WordApp := CreateOleObject('Word.Application');

  except

    // Error....

    Exit;

  end;

  try

    WordApp.Visible := False;

    WordApp.Documents.Open(AWordDoc);

    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertyTitle].Value := 'Your Title...';

    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertySubject].Value := 'Your Subject...';

    // ...

    // ...

  finally

    SaveChanges := wdSaveChanges;

    WordApp.Quit(SaveChanges, EmptyParam, EmptyParam);

  end;

end;

 

 

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

 

 

{

  2. Read MS Word properties via Structured Storage.

  by Serhiy Perevoznyk

}

uses

  ComObj, ActiveX;

 

const

  FmtID_SummaryInformation: TGUID =

    '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';

 

function FileTimeToDateTimeStr(F: TFileTime): string;

var

  LocalFileTime: TFileTime;

  SystemTime: TSystemTime;

  DateTime: TDateTime;

begin

  if Comp(F) = 0 then Result := '-'

  else

  begin

    FileTimeToLocalFileTime(F, LocalFileTime);

    FileTimeToSystemTime(LocalFileTime, SystemTime);

    with SystemTime do

      DateTime := EncodeDate(wYear, wMonth, wDay) +

        EncodeTime(wHour, wMinute, wSecond, wMilliseconds);

    Result := DateTimeToStr(DateTime);

  end;

end;

 

function GetDocInfo(const FileName: WideString): string;

var

  I: Integer;

  PropSetStg: IPropertySetStorage;

  PropSpec: array[2..19] of TPropSpec;

  PropStg: IPropertyStorage;

  PropVariant: array[2..19] of TPropVariant;

  Rslt: HResult;

  S: string;

  Stg: IStorage;

begin

  Result := '';

  try

    OleCheck(StgOpenStorage(PWideChar(FileName), nil, STGM_READ or

      STGM_SHARE_DENY_WRITE,

      nil, 0, Stg));

    PropSetStg := Stg as IPropertySetStorage;

    OleCheck(PropSetStg.Open(FmtID_SummaryInformation,

      STGM_READ or STGM_SHARE_EXCLUSIVE, PropStg));

    for I := 2 to 19 do

    begin

      PropSpec[I].ulKind := PRSPEC_PROPID;

      PropSpec[I].PropID := I;

    end;

    Rslt := PropStg.ReadMultiple(18, @PropSpec, @PropVariant);

    OleCheck(Rslt);

    if Rslt <> S_FALSE then for I := 2 to 19 do

      begin

        S := '';

        if PropVariant[I].vt = VT_LPSTR then

          if Assigned(PropVariant[I].pszVal) then

            S := PropVariant[I].pszVal;

        case I of

          2:  S  := Format('Title: %s', [S]);

          3:  S  := Format('Subject: %s', [S]);

          4:  S  := Format('Author: %s', [S]);

          5:  S  := Format('Keywords: %s', [S]);

          6:  S  := Format('Comments: %s', [S]);

          7:  S  := Format('Template: %s', [S]);

          8:  S  := Format('Last saved by: %s', [S]);

          9:  S  := Format('Revision number: %s', [S]);

          10: S := Format('Total editing time: %g sec',

              [Comp(PropVariant[I].filetime) / 1.0E9]);

          11: S := Format('Last printed: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          12: S := Format('Create time/date: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          13: S := Format('Last saved time/date: %s',

              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);

          14: S := Format('Number of pages: %d', [PropVariant[I].lVal]);

          15: S := Format('Number of words: %d', [PropVariant[I].lVal]);

          16: S := Format('Number of characters: %d',

              [PropVariant[I].lVal]);

          17:; // thumbnail

          18: S := Format('Name of creating application: %s', [S]);

          19: S := Format('Security: %.8x', [PropVariant[I].lVal]);

        end;

        if S <> '' then Result := Result + S + #13;

      end;

  finally

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if Opendialog1.Execute then

    ShowMessage(GetDocInfo(opendialog1.FileName));

end;

 

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

 

neoturk: ...Install an inf file with delphi ?...

uses

  ShellAPI;

 

function InstallINF(const PathName: string; hParent: HWND): Boolean;

var

  instance: HINST;

begin

  instance := ShellExecute(hParent,

    PChar('open'),

    PChar('rundll32.exe'),

    PChar('setupapi,InstallHinfSection DefaultInstall 132 ' + PathName),

    nil,

    SW_HIDE);

 

  Result := instance > 32;

end; { InstallINF }

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  InstallINF('C:XYZ.inf', 0);

end;

 

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

 

neoturk: ...Install an inf file with delphi ?...

uses

  ShellAPI;

 

function InstallINF(const PathName: string; hParent: HWND): Boolean;

var

  instance: HINST;

begin

  instance := ShellExecute(hParent,

    PChar('open'),

    PChar('rundll32.exe'),

    PChar('setupapi,InstallHinfSection DefaultInstall 132 ' + PathName),

    nil,

    SW_HIDE);

 

  Result := instance > 32;

end; { InstallINF }

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  InstallINF('C:XYZ.inf', 0);

end;

 

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

 

neoturk: ...Show the select directory dialog and sepeify the initial directory ?...

uses

  ShlObj, ActiveX;

 

function SelectDirectoryEx(hOwn: HWND; var Path: string; Caption, Root: string;

  uFlag: DWORD = $25): Boolean;

const

  BIF_NEWDIALOGSTYLE = $0040;

var

  BrowseInfo: TBrowseInfo;

  Buffer: PChar;

  RootItemIDList, ItemIDList: PItemIDList;

  ShellMalloc: IMalloc;

  IDesktopFolder: IShellFolder;

  Dummy: LongWord;

 

  function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam: Cardinal;

    lpData: Cardinal): Integer; stdcall;

  var

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

  begin

    case uMsg of

      BFFM_INITIALIZED:

        SendMessage(Hwnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));

      BFFM_SELCHANGED:

        begin

          SHGetPathFromIDList(PItemIDList(lParam), @PathName);

          SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, Longint(PChar(@PathName)));

        end;

    end;

    Result := 0;

  end;

begin

  Result := False;

  FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);

  if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then

  begin

    Buffer := ShellMalloc.Alloc(MAX_PATH);

    try

      RootItemIDList := nil;

      if Root <> '' then

      begin

        SHGetDesktopFolder(IDesktopFolder);

        IDesktopFolder.ParseDisplayName(hOwn, nil, POleStr(WideString(Root)),

          Dummy, RootItemIDList, Dummy);

      end;

      with BrowseInfo do

      begin

        hwndOwner := hOwn;

        pidlRoot := RootItemIDList;

        pszDisplayName := Buffer;

        lpszTitle := PChar(Caption);

        ulFlags := uFlag;

        lpfn := @BrowseCallbackProc;

        lParam := Integer(PChar(Path));

      end;

      ItemIDList := ShBrowseForFolder(BrowseInfo);

      Result := ItemIDList <> nil;

      if Result then

      begin

        ShGetPathFromIDList(ItemIDList, Buffer);

        ShellMalloc.Free(ItemIDList);

        Path := StrPas(Buffer);

      end;

    finally

      ShellMalloc.Free(Buffer);

    end;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Path: string;

begin

  Path := 'C:Windows';

  if SelectDirectoryEx(Handle, Path, 'Select Directory Sample', 'C:') then

    ShowMessage(Path);

end;

 

 

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

 

{

  Heres an example on how to locate a folder with a specific filer,

  using SHBrowseForFolder and a BrowseCallBack function

  ( by Jack Kallestrup )

}

 

uses ShlObj, ShellApi;

 

function BrowseCallBack ( Hwnd : THandle; uMsg : UINT; lpParam, lpData : LPARAM): integer; stdcall;

var

  Buffer : Array[0..255] of char;

  Buffer2 : Array[0..255] of char;

  TmpStr : String;

begin

  // Initialize buffers

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

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

 

  // Statusline text

  TmpStr := 'Locate folder containing '+StrPas(PChar(lpData));

 

  // Copy statustext to pchar

  StrPCopy(Buffer2,TmpStr);

 

  // Send message to BrowseForDlg that

  // the status text has changed

  SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,Integer(@Buffer2));

 

  // If directory in BrowswForDlg has changed ?

  if uMsg = BFFM_SELCHANGED then begin

    // Get the new folder name

    SHGetPathFromIDList(PItemIDList(lpParam),Buffer);

    // And check for existens of our file.

    {$IFDEF RX_D3}  //RxLib - extentions

    if FileExists(NormalDir(StrPas(Buffer))+StrPas(PChar(lpData)))

       and (StrLen(Buffer) > 0) then

    {$ELSE}

      if Length(StrPas(Buffer)) <> 0 then

       if Buffer[Length(StrPas(Buffer))-1] = '' then

         Buffer[Length(StrPas(Buffer))-1] := #0;

      if FileExists(StrPas(Buffer)+''+StrPas(PChar(lpData))) and

         (StrLen(Buffer) > 0) then

    {$ENDIF}

      // found : Send message to enable OK-button

      SendMessage(hwnd,BFFM_ENABLEOK,1,1)

    else

      // Send message to disable OK-Button

      SendMessage(Hwnd,BFFM_ENABLEOK,0,0);

  end;

  result := 0

end;

 

 

function BrowseforFile(Handle : THandle; Title : String; Filename : String) : String;

var

  BrowseInfo : TBrowseInfo;

  RetBuffer,

  FName,

  ResultBuffer : Array[0..255] of char;

  PIDL : PItemIDList;

begin

  StrPCopy(Fname,FileName);

 

  //Initialize buffers

  FillChar(BrowseInfo,SizeOf(TBrowseInfo),#0);

  Fillchar(RetBuffer,SizeOf(RetBuffer),#0);

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

 

  BrowseInfo.hwndOwner := Handle;

  BrowseInfo.pszDisplayName := @Retbuffer;

  BrowseInfo.lpszTitle := @Title[1];

 

  // we want a status-text

  BrowseInfo.ulFlags := BIF_StatusText;

 

  // Our call-back function cheching for fileexist

  BrowseInfo.lpfn := @BrowseCallBack;

  BrowseInfo.lParam := Integer(@FName);

 

  // Show BrowseForDlg

  PIDL := SHBrowseForFolder(BrowseInfo);

 

  // Return fullpath to file

  if SHGetPathFromIDList(PIDL,ResultBuffer) then

    result := StrPas(ResultBuffer)

  else

    Result := '';

 

  GlobalFreePtr(PIDL);  //Clean up

end;

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

const

  FileName = 'File.xyz';

var

  Answer: Integer;

begin

  if MessageBox(0, 'To locate the file yourself, click ok',

     PChar(Format('File %s not found.',[FileName])),MB_OKCANCEL) = 1 then

       BrowseforFile(Handle, 'locate ' + FileName, FileName);

end;

 

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

 

neoturk: ...Show the select directory dialog and sepeify the initial directory ?...

uses

  ShlObj, ActiveX;

 

function SelectDirectoryEx(hOwn: HWND; var Path: string; Caption, Root: string;

  uFlag: DWORD = $25): Boolean;

const

  BIF_NEWDIALOGSTYLE = $0040;

var

  BrowseInfo: TBrowseInfo;

  Buffer: PChar;

  RootItemIDList, ItemIDList: PItemIDList;

  ShellMalloc: IMalloc;

  IDesktopFolder: IShellFolder;

  Dummy: LongWord;

 

  function BrowseCallbackProc(hwnd: HWND; uMsg: UINT; lParam: Cardinal;

    lpData: Cardinal): Integer; stdcall;

  var

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

  begin

    case uMsg of

      BFFM_INITIALIZED:

        SendMessage(Hwnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));

      BFFM_SELCHANGED:

        begin

          SHGetPathFromIDList(PItemIDList(lParam), @PathName);

          SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, Longint(PChar(@PathName)));

        end;

    end;

    Result := 0;

  end;

begin

  Result := False;

  FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);

  if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then

  begin

    Buffer := ShellMalloc.Alloc(MAX_PATH);

    try

      RootItemIDList := nil;

      if Root <> '' then

      begin

        SHGetDesktopFolder(IDesktopFolder);

        IDesktopFolder.ParseDisplayName(hOwn, nil, POleStr(WideString(Root)),

          Dummy, RootItemIDList, Dummy);

      end;

      with BrowseInfo do

      begin

        hwndOwner := hOwn;

        pidlRoot := RootItemIDList;

        pszDisplayName := Buffer;

        lpszTitle := PChar(Caption);

        ulFlags := uFlag;

        lpfn := @BrowseCallbackProc;

        lParam := Integer(PChar(Path));

      end;

      ItemIDList := ShBrowseForFolder(BrowseInfo);

      Result := ItemIDList <> nil;

      if Result then

      begin

        ShGetPathFromIDList(ItemIDList, Buffer);

        ShellMalloc.Free(ItemIDList);

        Path := StrPas(Buffer);

      end;

    finally

      ShellMalloc.Free(Buffer);

    end;

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Path: string;

begin

  Path := 'C:Windows';

  if SelectDirectoryEx(Handle, Path, 'Select Directory Sample', 'C:') then

    ShowMessage(Path);

end;

 

 

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

 

{

  Heres an example on how to locate a folder with a specific filer,

  using SHBrowseForFolder and a BrowseCallBack function

  ( by Jack Kallestrup )

}

 

uses ShlObj, ShellApi;

 

function BrowseCallBack ( Hwnd : THandle; uMsg : UINT; lpParam, lpData : LPARAM): integer; stdcall;

var

  Buffer : Array[0..255] of char;

  Buffer2 : Array[0..255] of char;

  TmpStr : String;

begin

  // Initialize buffers

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

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

 

  // Statusline text

  TmpStr := 'Locate folder containing '+StrPas(PChar(lpData));

 

  // Copy statustext to pchar

  StrPCopy(Buffer2,TmpStr);

 

  // Send message to BrowseForDlg that

  // the status text has changed

  SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,Integer(@Buffer2));

 

  // If directory in BrowswForDlg has changed ?

  if uMsg = BFFM_SELCHANGED then begin

    // Get the new folder name

    SHGetPathFromIDList(PItemIDList(lpParam),Buffer);

    // And check for existens of our file.

    {$IFDEF RX_D3}  //RxLib - extentions

    if FileExists(NormalDir(StrPas(Buffer))+StrPas(PChar(lpData)))

       and (StrLen(Buffer) > 0) then

    {$ELSE}

      if Length(StrPas(Buffer)) <> 0 then

       if Buffer[Length(StrPas(Buffer))-1] = '' then

         Buffer[Length(StrPas(Buffer))-1] := #0;

      if FileExists(StrPas(Buffer)+''+StrPas(PChar(lpData))) and

         (StrLen(Buffer) > 0) then

    {$ENDIF}

      // found : Send message to enable OK-button

      SendMessage(hwnd,BFFM_ENABLEOK,1,1)

    else

      // Send message to disable OK-Button

      SendMessage(Hwnd,BFFM_ENABLEOK,0,0);

  end;

  result := 0

end;

 

 

function BrowseforFile(Handle : THandle; Title : String; Filename : String) : String;

var

  BrowseInfo : TBrowseInfo;

  RetBuffer,

  FName,

  ResultBuffer : Array[0..255] of char;

  PIDL : PItemIDList;

begin

  StrPCopy(Fname,FileName);

 

  //Initialize buffers

  FillChar(BrowseInfo,SizeOf(TBrowseInfo),#0);

  Fillchar(RetBuffer,SizeOf(RetBuffer),#0);

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

 

  BrowseInfo.hwndOwner := Handle;

  BrowseInfo.pszDisplayName := @Retbuffer;

  BrowseInfo.lpszTitle := @Title[1];

 

  // we want a status-text

  BrowseInfo.ulFlags := BIF_StatusText;

 

  // Our call-back function cheching for fileexist

  BrowseInfo.lpfn := @BrowseCallBack;

  BrowseInfo.lParam := Integer(@FName);

 

  // Show BrowseForDlg

  PIDL := SHBrowseForFolder(BrowseInfo);

 

  // Return fullpath to file

  if SHGetPathFromIDList(PIDL,ResultBuffer) then

    result := StrPas(ResultBuffer)

  else

    Result := '';

 

  GlobalFreePtr(PIDL);  //Clean up

end;

 

// Example:

 

procedure TForm1.Button1Click(Sender: TObject);

const

  FileName = 'File.xyz';

var

  Answer: Integer;

begin

  if MessageBox(0, 'To locate the file yourself, click ok',

     PChar(Format('File %s not found.',[FileName])),MB_OKCANCEL) = 1 then

       BrowseforFile(Handle, 'locate ' + FileName, FileName);

end;

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