自认为的超难问题(200分)

  • 主题发起人 主题发起人 vickymade
  • 开始时间 开始时间
V

vickymade

Unregistered / Unconfirmed
GUEST, unregistred user!
最近小弟下载了一个LPTCtrl的控件,可能是D3或D4的。<br>小弟在D7下编译,发现有一个函数编译不过去。如下:<br>procedure TlptCtrl.FindLptAddr;<br>begin<br>&nbsp; FPortAddrArr[1] := mem[$0040:$08] + mem[$0040:$09]*256;<br>&nbsp; if FPortAddrArr[1] &gt; 0 then FLptAvail[1] := true;<br>&nbsp; FPortAddrArr[2] := mem[$0040:$0A] + mem[$0040:$0B]*256;<br>&nbsp; if FPortAddrArr[2] &gt; 0 then FLptAvail[2] := true;<br>&nbsp; FPortAddrArr[3] := mem[$0040:$0C] + mem[$0040:$0D]*256;<br>&nbsp; if FPortAddrArr[3] &gt; 0 then FLptAvail[3] := true;<br>end;<br><br>这个函数编译不过去的地方就在于使用了MEM这个函数,可小弟查遍了Delphi参考手册也没有找到这个函数,在Source找了半天也还是没有找到,请各位高人相助。
 
<br>连个关注的人都没有啊?也帮个门儿顶顶啊。其实我的问题就是想要得到能够在2K下不通过驱动程序来控制并口的代码。谁给偶一个代码,便已过去了,偶就把200分给他。
 
该控件全部代码如下:<br><br>unit LptCtrl;<br>{--------------------------------------------------------------------<br>IDENTIFICATION<br>Unit Name: &nbsp; &nbsp; &nbsp;LptCtrl<br>Reg No: &nbsp; &nbsp; &nbsp; &nbsp; -<br>Revision: &nbsp; &nbsp; &nbsp; See revision history.<br>File Name: &nbsp; &nbsp; &nbsp;LptCtrl.pas<br>Target: &nbsp; &nbsp; &nbsp; &nbsp; PC w Intel 386+, LPT port, Windows 3.1 or compatible.<br>Compiler: &nbsp; &nbsp; &nbsp; Delphi 1.x. Note! This unit will probably<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not compile with Delphi 2.x.<br>Issued By: &nbsp; &nbsp; &nbsp;(c) Tord Andersson, 1996. (anderssonto@decus.se).<br> Legal disclaimer. The author will take no responsibilty <br> for damages that could be the result of using this<br> component.<br>Reviewed By: &nbsp; &nbsp;-<br>Tested By: &nbsp; &nbsp; &nbsp;-<br><br>DESCRIPTION<br>This unit holds TlptCtrl, a class/component which is intended<br>for reading/writing directly to an LPT port.<br><br>REVISION HISTORY<br>Version &nbsp;Date &nbsp; &nbsp;Change/addition &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Resp<br>0.2 &nbsp; &nbsp; &nbsp;960606 &nbsp;Released to the public domain. &nbsp; Tord Andersson<br><br>====================================================================}<br><br><br>interface<br><br>uses<br>&nbsp; SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,<br>&nbsp; Forms, Dialogs;<br><br>type<br>&nbsp; TLpt = (None, Lpt1, Lpt2, Lpt3);<br>&nbsp; TLptAvail = array [1..3] of boolean; { is port available? }<br>&nbsp; TPortAddrArr = array [1..3] of word;<br>&nbsp; TlptCtrl = class(TComponent)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; FLpt: TLpt;<br>&nbsp; &nbsp; FPortAddrArr: TPortAddrArr; &nbsp; &nbsp; &nbsp; &nbsp; { LPT port addresses }<br>&nbsp; &nbsp; FPortAddr: word; { selected LPT port address }<br>&nbsp; &nbsp; FLptAvail: TLptAvail;<br>&nbsp; &nbsp; FData: byte; &nbsp; &nbsp; &nbsp; &nbsp;{ LPT data out }<br>&nbsp; &nbsp; FDummy: byte; &nbsp; &nbsp; &nbsp; { will only be used to make 'Status' published }<br><br>&nbsp; &nbsp; procedure SetLptPort(Value: Tlpt);<br>&nbsp; &nbsp; { SetPortAddress will usually be automatically handled<br>&nbsp; &nbsp; &nbsp; through SetLptPort. }<br>&nbsp; &nbsp; procedure SetPortAddress(Value: word);<br>&nbsp; &nbsp; procedure SetData(Value: byte);<br>&nbsp; &nbsp; function &nbsp;GetStatus: byte;<br>&nbsp; &nbsp; function &nbsp;GetCtrl: byte;<br>&nbsp; &nbsp; procedure SetCtrl(Value: byte);<br>&nbsp; &nbsp; procedure FindLptAddr;<br><br><br>&nbsp; protected<br>&nbsp; &nbsp; { Protected declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; property LptAvail: TLptAvail read FLptAvail; { what ports are available? }<br><br>&nbsp; published<br>&nbsp; &nbsp; { Published declarations }<br>&nbsp; &nbsp; property LptPort: TLpt read FLpt write SetLptPort default None;<br>&nbsp; &nbsp; property PortAdress: word read FPortAddr write SetPortAddress;<br>&nbsp; &nbsp; property Data: byte read Fdata write SetData default 0;<br>&nbsp; &nbsp; property Status: byte read GetStatus write FDummy;<br>&nbsp; &nbsp; property Ctrl: byte read GetCtrl write SetCtrl;<br>&nbsp; end;<br><br>procedure Register;<br><br>implementation<br><br>{ &nbsp;FindLptAddr - Will find the addresses of LPT port (1-3).<br>&nbsp; &nbsp;Non valid ports will result in address 0.<br>&nbsp; &nbsp;Note FLptPortAddr[] and FLptAvail will be affected. }<br>procedure TlptCtrl.FindLptAddr;<br>begin<br>&nbsp; { Yes, I know, this could have been coded as a loop... }<br>&nbsp; FPortAddrArr[1] := mem[$0040:$08] + mem[$0040:$09]*256;<br>&nbsp; if FPortAddrArr[1] &gt; 0 then FLptAvail[1] := true;<br><br>&nbsp; FPortAddrArr[2] := mem[$0040:$0A] + mem[$0040:$0B]*256;<br>&nbsp; if FPortAddrArr[2] &gt; 0 then FLptAvail[2] := true;<br><br>&nbsp; FPortAddrArr[3] := mem[$0040:$0C] + mem[$0040:$0D]*256;<br>&nbsp; if FPortAddrArr[3] &gt; 0 then FLptAvail[3] := true;<br>end;<br><br>procedure TLptCtrl.SetLptPort(Value: Tlpt); { To set up the choosen port }<br>begin<br>&nbsp; case Value of<br>&nbsp; &nbsp; Lpt1: if FLptAvail[1] then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FPortAddr := FPortAddrArr[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLpt := Lpt1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; Lpt2: if FLptAvail[2] then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FPortAddr := FPortAddrArr[2];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLpt := Lpt2;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; Lpt3: if FLptAvail[3] then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FPortAddr := FPortAddrArr[3];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLpt := Lpt3;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FPortAddr := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLpt := None;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure TlptCtrl.SetPortAddress(Value: word); { for those who hate automation : ) }<br>begin<br>&nbsp; FPortAddr := Value;<br>end;<br><br>procedure TlptCtrl.SetData(Value: byte); { put data on LPT data lines }<br>begin<br>&nbsp; if FLpt &lt;&gt; None then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Port[FPortAddr] := Value;<br>&nbsp; &nbsp; &nbsp; FData := Value;<br>&nbsp; &nbsp; end;<br>end;<br><br>function TlptCtrl.GetStatus: byte; { read data from LPT status lines }<br>begin<br>&nbsp; if FLpt &lt;&gt; None then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := Port[FPortAddr + 1];<br>&nbsp; &nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; Result := 0;<br>end;<br><br>function TlptCtrl.GetCtrl: byte;{ to read what was put on the Ctrl lines }<br>begin<br>if FLpt &lt;&gt; None then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := Port[FPortAddr + 2];<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; Result := 0;<br>end;<br><br>procedure TlptCtrl.SetCtrl(Value: byte); { put data on Ctrl lines }<br>begin<br>&nbsp; if FLpt &lt;&gt; None then<br>&nbsp; begin<br>&nbsp; &nbsp; Port[FPortAddr + 2] := Value;<br>&nbsp; end;<br>end;<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('I/O', [TlptCtrl]);<br>end;<br><br>{ constructor }<br>constructor TLptCtrl.Create(AOwner: TComponent);<br>begin<br>&nbsp; inherited Create(AOwner);<br>&nbsp; FindLptAddr; (* find available LPT ports *)<br>end;<br><br>{ destructor - just as a placeholder if cleanup will be necessary }<br>destructor TLptCtrl.Destroy;<br>begin<br>&nbsp; inherited Destroy;<br>end;<br><br>end.
 
不好意思,帮不了你!<br>帮你定,提前!
 
MEM不是函数,而是一个delphi系统内建的数组变量,它以内存地址为下标来存取指定的地址(实际相当一个指针构造器),由于进入了windows以后,系统不允许存取物理地址,所以在后来的版本中它就可能被取消了(同时好象还有一个指示字abstract后跟一个地址的那种用法),你可以根据你的程序中的功能,用相应的代码变换一下。<br>分析你的上面这段程序,是判断打印机的接口是否可用,你可以用相应的api来进行。
 
这种形式的地址声明不能用于WINDOWS的保护模式下,因为WINDOWS不允许你的应用程序访问程序外的内存区域,如果这种形式指定的地址不在WINDOWS分配给应用程序的内存范围内,将引起落架 General Protection Fault 错误!还有 MemW,MemL 都是不可以用了。<br>你可以用以下的变通用法来改此函数:<br><br>procedure TlptCtrl.FindLptAddr;<br>var aStr: String;<br>&nbsp; &nbsp; aStraddr: Byte Absolute aStr; <br>begin<br>&nbsp; {FPortAddrArr[1] := mem[$0040:$08] + mem[$0040:$09]*256;} //此句是原来的<br>&nbsp; FPortAddrArr[1] := &nbsp;aStraddr + (aStraddr+1) * 256; //改后的语句<br>&nbsp; if FPortAddrArr[1] &gt; 0 then FLptAvail[1] := true;<br>&nbsp; ///......<br>end;<br>
 
我只能帮你提前了!
 
水平太洼了。那位老兄能将这个控件改得在D7下可以用了啊?
 
晕死,我给得你代码,你把那个函数换一下不就行了吗!
 
我有DLL,与我联系.kimlon@163.com
 
&gt;&gt;Compiler: &nbsp; &nbsp; &nbsp; Delphi 1.x. Note! This unit will probably<br>這個是個d1編的東西, 也就是說是十六位的, 估計已經無法在現在版本用了, 因為, 直接用到硬件地址的, 就算按 乖乖兔 的說法做, 我想也是不行的! 找新的相關功能的控件吧!
 
我的信箱:VSoft@163.com
 
后退
顶部