Virtual Pascal

Classic Object Pascal for free

can not use 'Registers' predefined type of turbo pascal in VP

in the code below, I copied it from taccess.pas of borland's database toolbox, I Can not compile in VP, I get 'Error 3: Unknown identifier 'Registers' ' . Can Anyone suggest something?

you may post answers to marinayelken@gmail.com


code with problem below
_____________________________________________________

function DupHandle(Handle: Word): Word;
var
Regs : Registers;
begin
Regs.AH := $45; {DOS function to duplicate a file handle}
Regs.BX := Handle;
MsDos(Regs);
if Regs.Flags and FCarry=0 then {Check if carry flag is set}
DupHandle := Regs.AX {Return Duplicate file handle}
else
TAStatus := Regs.AX; {Return error code}
end; { DupHandle }

Views: 656

Reply to This

Replies to This Discussion

Hi !

Turbo Pascal's registers type is not supported by VP. In protected mode, you must use the operating system API functions instead of interrupts. What is your OS and what is the purpose of your function ?
win xp,
software will run in protected mode (cmd.exe), not a windows native application
my purpose is duplicating a file handle and closing the file (flushing it), I have an old code of database application of turbo pascal. Borland's toolbox for database applications uses that procedure.
Also register type is not defined in virtual pascal, if I define it as a type, can I use that type for passing the register values to the interrupt call?

Thank you

Erkut ERGİL


The two subroutines are written below


function DupHandle(Handle: Word): Word;
var
Regs : Registers;
begin
Regs.AH := $45; {DOS function to duplicate a file handle}
Regs.BX := Handle;
MsDos(Regs);
if Regs.Flags and FCarry=0 then {Check if carry flag is set}
DupHandle := Regs.AX {Return Duplicate file handle}
else
TAStatus := Regs.AX; {Return error code}
end; { DupHandle }

procedure CloseFileHandle(Handle : Word);
var
Regs : Registers;
begin
Regs.AH := $3E; {Dos function to close a file handle}
Regs.BX := Handle;
MsDos(Regs);
if not (Regs.Flags and FCarry=0) then {Check if carry flag is set}
TAStatus := Regs.AX; {Return error code}
end; { CloseFileHandle }
Well, as interrupts won't work, you could use the following API functions :

- CreateFile to create or open a file :
HANDLE CreateFile(
     LPCTSTR lpFileName, // pointer to name of the file
     DWORD dwDesiredAccess, // access (read-write) mode
     DWORD dwShareMode, // share mode
     LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes
     DWORD dwCreationDistribution, // how to create
     DWORD dwFlagsAndAttributes, // file attributes
     HANDLE hTemplateFile // handle to file with attributes to copy
);


- DuplicateHandle to duplicate the file's handle :
BOOL DuplicateHandle(
     HANDLE hSourceProcessHandle, // handle to process with handle to duplicate
     HANDLE hSourceHandle, // handle to duplicate
     HANDLE hTargetProcessHandle, // handle to process to duplicate to
     LPHANDLE lpTargetHandle, // pointer to duplicate handle
     DWORD dwDesiredAccess, // access for duplicate handle
     BOOL bInheritHandle, // handle inheritance flag
     DWORD dwOptions // optional actions
);


- CloseHandle to close the file :
BOOL CloseHandle(
     HANDLE hObject // handle to object to close
);


If you need help on the Win32 API you can download the following file : ftp://ftp-developpez.com/alcatiz/win32apihlp.zip

Hope this helps ?
I will check them tomorrow. Thanks for your help.

I will inform you about the result tomorrow.

RSS

© 2021   Created by Allan Mertner.   Powered by

Report an Issue  |  Terms of Service