home *** CD-ROM | disk | FTP | other *** search
- Listing One
- procedure TMainForm.OpenDoc (const DocName: String);
- begin
- ShellExecute (Handle, 'open', PChar (DocName), Nil, Nil, sw_Show);
- end;
-
-
- Listing Two
- function TBrowserMain.GetFileAssociation (const InstallPath: String): String;
- var
- Key: hKey;
- bytes: LongInt;
- szBuff: array [0..255] of Char;
- begin
- { Get the Level 1 file registration keyname }
- Result := ''; bytes := sizeof (szBuff);
- if RegOpenKey (hKey_Classes_Root, StrPCopy (szBuff, ExtractFileExt _
- (InstallPath)), Key) = 0 then try
- if RegQueryValue (Key, Nil, szBuff, bytes) <> 0 then bytes := 0;
- finally
- RegCloseKey (Key);
- end;
-
- { Get the Level 2 file registration info }
- if bytes > 0 then begin
- bytes := sizeof (szBuff);
- if RegOpenKey (hKey_Classes_Root, StrPCopy (szBuff, _
- StrPas (szBuff) + '\shell\open\command'), Key) = 0 then try
- if RegQueryValue (Key, Nil, szBuff, bytes) <> 0 then bytes := 0;
- finally
- RegCloseKey (Key);
- end;
-
- if bytes > 0 then Result := StrPas (szBuff);
- end;
- end;
-
- Listing Three
-
- procedure CopyFile (const SrcFile, DstFile: String);
- const
- ChunkSize = $2000;
- var
- buff: PChar;
- fsSrc, fsDst: TFileStream;
- srcDate, bytesRead, bytesWritten: LongInt;
- begin
- fsSrc := TFileStream.Create (SrcFile, fmShareDenyWrite);
- try
- srcDate := FileGetDate (fsSrc.Handle);
- fsDst := TFileStream.Create (DstFile, fmCreate);
- try
- GetMem (buff, ChunkSize);
- try
- while True do
- begin
- bytesRead := fsSrc.Read (buff^, ChunkSize);
- bytesWritten := fsDst.Write (buff^, bytesRead);
- if bytesWritten < bytesRead then
- raise Exception.Create (Format _
- ('CopyFile failed writing %s. Disk full?', [DstFile]));
- if (bytesRead < ChunkSize) or (bytesRead <> bytesWritten) then
- break;
- end;
- finally
- FreeMem (buff, ChunkSize);
- end;
- finally
- FileSetDate (fsDst.Handle, srcDate);
- fsDst.Free;
- end;
- finally
- fsSrc.Free;
- end;
- end;
-
-