home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Editor.ial / Code / Code.txt
Encoding:
Text File  |  1998-03-30  |  2.1 KB  |  77 lines

  1. Listing One
  2. procedure TMainForm.OpenDoc (const DocName: String);
  3. begin
  4.     ShellExecute (Handle, 'open', PChar (DocName), Nil, Nil, sw_Show);
  5. end;
  6.  
  7.  
  8. Listing Two
  9. function TBrowserMain.GetFileAssociation (const InstallPath: String): String;
  10. var
  11.     Key: hKey;
  12.     bytes: LongInt;
  13.     szBuff: array [0..255] of Char;
  14. begin
  15.     { Get the Level 1 file registration keyname }
  16.     Result := ''; bytes := sizeof (szBuff);
  17.     if RegOpenKey (hKey_Classes_Root, StrPCopy (szBuff, ExtractFileExt _
  18.       (InstallPath)), Key) = 0 then try
  19.         if RegQueryValue (Key, Nil, szBuff, bytes) <> 0 then bytes := 0;
  20.     finally
  21.         RegCloseKey (Key);
  22.     end;
  23.  
  24.     { Get the Level 2 file registration info }
  25.     if bytes > 0 then begin
  26.         bytes := sizeof (szBuff);
  27.         if RegOpenKey (hKey_Classes_Root, StrPCopy (szBuff, _
  28.           StrPas (szBuff) + '\shell\open\command'), Key) = 0 then try
  29.             if RegQueryValue (Key, Nil, szBuff, bytes) <> 0 then bytes := 0;
  30.         finally
  31.             RegCloseKey (Key);
  32.         end;
  33.  
  34.         if bytes > 0 then Result := StrPas (szBuff);
  35.     end;
  36. end;
  37.  
  38. Listing Three
  39.  
  40. procedure CopyFile (const SrcFile, DstFile: String);
  41. const
  42.     ChunkSize = $2000;
  43. var
  44.     buff: PChar;
  45.     fsSrc, fsDst: TFileStream;
  46.     srcDate, bytesRead, bytesWritten: LongInt;
  47. begin
  48.     fsSrc := TFileStream.Create (SrcFile, fmShareDenyWrite);
  49.     try
  50.     srcDate := FileGetDate (fsSrc.Handle);
  51.     fsDst := TFileStream.Create (DstFile, fmCreate);
  52.     try
  53.         GetMem (buff, ChunkSize);
  54.         try
  55.             while True do
  56.             begin
  57.                     bytesRead := fsSrc.Read (buff^, ChunkSize);
  58.                        bytesWritten := fsDst.Write (buff^, bytesRead);
  59.                 if bytesWritten < bytesRead then
  60.                     raise Exception.Create (Format _
  61.                 ('CopyFile failed writing %s. Disk full?', [DstFile]));
  62.                 if (bytesRead < ChunkSize) or (bytesRead <> bytesWritten) then 
  63. break;
  64.             end;
  65.         finally
  66.             FreeMem (buff, ChunkSize);
  67.         end;
  68.     finally
  69.         FileSetDate (fsDst.Handle, srcDate);
  70.         fsDst.Free;
  71.     end;
  72.     finally
  73.         fsSrc.Free;
  74.     end;
  75. end;
  76.  
  77.