Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2008 Jul : Can someone else run this code and see if it fails?

www.cryer.info
Managed Newsgroup Archive

Can someone else run this code and see if it fails?

Subject:Can someone else run this code and see if it fails?
Posted by:"Ian Boyd" (ian.borlandnews0..@avatopia.com)
Date:Wed, 23 Jul 2008 16:48:07 -0400

i have assurances that this code should work. i've tried it on 3 computers
here, it fails every time


procedure TForm1.Button4Click(Sender: TObject);
var
    dwSharingMode: DWORD;
    hCreatedFile: THandle;
    hFile: THandle;
begin
    //Sharing mode when we create the file
    dwSharingMode :=
            FILE_SHARE_READ or
            FILE_SHARE_WRITE;

    hFile := CreateFile(
            'c:\tempFile.dat',
            GENERIC_WRITE,
            dwSharingMode,
            nil,
            CREATE_ALWAYS,
            FILE_FLAG_DELETE_ON_CLOSE,
            0);
    Assert(hFile <> INVALID_HANDLE_VALUE,
                SysErrorMessage(GetLastError));
    hFile := 0; //Leave the handle open

    hFile := CreateFile(
            'c:\tempFile.dat',
            GENERIC_READ,
            FILE_SHARE_READ or FILE_SHARE_WRITE,
            nil,
            OPEN_EXISTING,
            0,
            0);
    if hFile <> INVALID_HANDLE_VALUE then
    begin
        CloseHandle(hFile);
        MessageDlg('Sucessfully opened temporary file.',
                    mtInformation, [mbOk], 0)
    end
    else
        MessageDlg('Could not open temporary file: '+
                SysErrorMessage(GetLastError), mtError, [mbOk], 0);
end;

Glossary

File Types

Replies:

www.cryer.info
Managed Newsgroup Archive