File handle 
Author Message
 File handle

Does anyone know how to get the file handle ?  I need to write a FLUSH
procedure for typed files.  Does I have to use File-rec or not ??

Thank you very much !

DP.



Wed, 18 Jun 1902 08:00:00 GMT  
 File handle

Quote:

> Does anyone know how to get the file handle ?  I need to write a FLUSH
> procedure for typed files.  Does I have to use File-rec or not ??

If you're programming under windows you can use the _lopen-Function from
the WinProcs-Unit. See your on line help for informations about the
parameters.

--
Ulli Conrad
Goettingen, Planet Earth

http://www.gwdg.de/~uconrad1



Wed, 18 Jun 1902 08:00:00 GMT  
 File handle

Quote:

> Does anyone know how to get the file handle ?  I need to write a FLUSH
> procedure for typed files.  Does I have to use File-rec or not ??

It depends on how you write it.  If you're working with high-level code,
you can do this:

uses
  dos;

var
  f : file of sometype;

begin
  assign (f,'myfile.dat');
  reset (f);
  {...}
  writeln ('file handle:  ',FileRec(f).handle);
  {...}
  close (f);
end;

If you're working with assembly, it's not necessary, since the handle is
the first field in the file type:

function gethandle (var f : file of something); assembler;

asm
  les   di,[f]
  mov   ax,word ptr es:[di]
end;

Or you can just use that function in your own code to get the file
handle if you're using high-level TP.

Quote:
> Thank you very much !

> DP.

--
Scott Earnest        | We now return you to our regularly |



Wed, 18 Jun 1902 08:00:00 GMT  
 File handle


Quote:
> Does anyone know how to get the file handle ?  I need to write a FLUSH
> procedure for typed files.  Does I have to use File-rec or not ??

> Thank you very much !

> DP.

Make close(f) and reset(f,sizeof(???)); That fast.


Wed, 18 Jun 1902 08:00:00 GMT  
 File handle

Quote:

>Does anyone know how to get the file handle ?  I need to write a FLUSH
>procedure for typed files.  Does I have to use File-rec or not ??

>Thank you very much !

>DP.

If you typecast the file variable as a FileRec, the handle is one of
its fields: FileRec(FileVar).Handle.  The code below will force a
flush of the DOS buffers associated with the file F:

function FlushFile(var F : File) : Boolean;
var
  Temp : word;
  Code : integer;
  Regs : Registers;
begin
  with Regs do begin
    FlushFile := false;
    BX := FileRec(F).Handle;
    Temp := DosVersion;
    if (Lo(Temp) > 3) or (Lo(Temp) = 3) and (Hi(Temp) >= 3) then begin
      AX := $6800;   { commit file }
      MsDos(Regs);
    end
    else begin   { pre DOS 3 }
      AX := $4500;   { duplicate file handle }
      MsDos(Regs);
      { Do nothing if no handle available or old handle is invalid }
      if ((Flags and 1) = 0) then begin
        Temp := AX;
        AX := $3E00; { close temporary handle }
        BX := Temp;
        MsDos(Regs);
      end;
    end;
    if ((Flags and 1) = 0) then FlushFile := true;
  end;
end;

You must, of course, flush any buffers in your Pascal program with a
Write statement before flushing the DOS buffers.  FlushFile will not
force SMARTDRV or similar disk caching programs to flush to disk. This
may not be a problem, since SMARTDRV generally flushes within a few
seconds.

                            Bruce Mickle



Wed, 18 Jun 1902 08:00:00 GMT  
 File handle

Quote:
> Does anyone know how to get the file handle ?  I need to write a FLUSH
> procedure for typed files.  Does I have to use File-rec or not ??

> Thank you very much !

> DP.

        Well, it looks like nobody will answer this one. Let's see...

        If I did understand your question... you want to clear the file buffer of
a file which is not a text file? If that's the case, it is a good idea to
use file handles.
        For using file handles you'll have to use the DOS Interrupts. I regret I
can never guess somebody's coding level!   What I'm talking about is a bit
complex to explain here. I suggest you to try using Interrupts, there are a
lot about that on the Internet. Do it by yourself, if you have problems do
not hesitate on reaching me.

                                                Jaguar/NE



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Losing File Handles - But I am not using Files

2. Creating executable file + file handling "objects"

3. BDE Error: # of Max File handles exceeded

4. HELP: File handling and encryption problems!

5. XOR encryption program file handling

6. XOR encryption program file handling

7. Table.Close does not close file handle?

8. HELP: File handling and encryption problems!

9. File handling

10. File handling.

11. need help on file handling

12. record file handling problem

 

 
Powered by phpBB® Forum Software