求组件源代码,只为学习用,最重要的是自定义事件的处理!

Jinglihui 2003-08-13 03:28:23
分不是问题!
...全文
38 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
MEFULEU 2003-08-15
  • 打赏
  • 举报
回复
unit PrinterStatus;

interface

uses
Windows, Messages, WinProcs, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;


// TPrinterstatus
// Komponente zum Abfragen des aktuellen Druckerportstatus
// Programmiert 2000 von K. Otto
// funktioniert unter Win 9x, jedoch nicht unter Win NT
// ---------------------------------
// Status: Freeware incl. Sourcecode
// ---------------------------------
// Diese Komponente beruht auf einem Beitrag von Robert Vivrette
// f黵 "The unofficial Newsletter of Delphi Users"
// http://www.undu.com/articles/990228a.html

type
TPrinterStatus = class(TComponent)
private
{ Private-Deklarationen }
fStatus : Byte;
fLPT : Integer;
Function GetTimeOut : Boolean;
Function GetIOError : Boolean;
Function GetPrinterSelected : Boolean;
Function GetOutOfPaper : Boolean;
Function GetAcknowledgement : Boolean;
Function GetPrinterBusy : Boolean;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
Procedure CheckPrinterStatus; // Liest den Druckerstatus der angegeben LPT-Schnittstelle
Constructor Create(AOwner : TComponent); Override;
Property TimeOut : Boolean Read GetTimeOut;
Property IOError : Boolean Read GetIOError;
Property PrinterSelected : Boolean Read GetPrinterSelected;
Property OutOfPaper : Boolean Read GetOutOfPaper;
Property Acknowledgement : Boolean Read GetAcknowledgement;
Property Busy : Boolean Read GetPrinterBusy;
published
{ Published-Deklarationen }
Property LPT : Integer Read fLPT Write fLPT;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Eigene', [TPrinterStatus]);
end;

Function TPrinterStatus.GetTimeOut : Boolean;
Begin
Result:=(fStatus and $01)=$01;
End;

Function TPrinterStatus.GetIOError : Boolean;
Begin
Result:=(fStatus and $08)=$08;
End;

Function TPrinterStatus.GetPrinterSelected : Boolean;
Begin
Result:=(fStatus and $10)=$10;
End;

Function TPrinterStatus.GetOutOfPaper : Boolean;
Begin
Result:=(fStatus and $20)=$20;
End;

Function TPrinterStatus.GetAcknowledgement : Boolean;
Begin
Result:=(fStatus and $40)=$40;
End;

Function TPrinterStatus.GetPrinterBusy : Boolean;
Begin
Result:=not ((fStatus and $80)=$80);
End;

Procedure TPrinterStatus.CheckPrinterStatus;
Var
Status : Byte;
CheckLPT : Word;
Begin
Status:=0;
If (fLPT>=1) and (fLPT<=3) Then
Begin
CheckLPT:=fLPT-1;
asm
mov dx,CheckLPT;
mov al,0;
mov ah,2;
int 17h;
mov &Status, ah;
End;
End;
fStatus:=Status;
End;

Constructor TPrinterStatus.Create(AOwner : TComponent);
Begin
Inherited Create(AOwner);
fLPT:=1;
fStatus:=0;
End;

end.
//////////////////////////////////////////////////////
用法:

if not PrinterStatus1.PrinterReady(0) then //0 = current printerport
ShowMessage(PrinterStatus1.StatusMsg) else {print print print} ;

unit PrinterStatus;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TPrinterStatus = class(TComponent)
private
{ Private declarations }
FPort : Word;
FStatusStr : string;
protected
{ Protected declarations }
public
{ Public declarations }
function PrinterReady(LPT: Word): boolean;
published
{ Published declarations }
property StatusMsg: string read FStatusStr;
end;

procedure Register;

implementation
uses Printers;

procedure Register;
begin
RegisterComponents('Win95', [TPrinterStatus]);
end;

const
PrnReady = $90;
OffLine = $00;
OffLine2 = $10; {NEW LINE}
PaperOut = $20;
PaperOut2 = $30; {NEW LINE}
HookedButOff = $80; {NEW LINE}
NoConnect = $B0; {MODIFIED LINE}

{NOCONNECT = $30 FOR SOME COMPUTERS BY STU}

function TPrinterStatus.PrinterReady(LPT: Word): boolean;
var
ErrorCode, C : BYTE;
code, x : integer;
s : string;

function GetPrinterStatus (LPT: Word): Byte;
{Pass 1 in LPT for LPT1}
begin
asm
mov ah,2
mov dx,LPT
dec dx
int $17
mov @Result,ah
end;
end; {GetPrinterStatus}


begin
result := false; //assume not

FPort := LPT;
if FPort = 0 then begin {if no port specified then try to set port to current
printer port}
{printer name}
s := Printer.Printers[Printer.PrinterIndex];
if Pos('FPort',s) <> 0 then begin
s := Copy(s, Pos('FPort',s) +3, 1);
Val(s,x,code);
if code <> 0 then FPort := 1 else FPort := x;
end else FPort := 1; {default to LPT1}
end;

{valid LPT is 1..4}
if (FPort > 4) or (FPort < 1) then begin
raise ERangeError.CreateFmt(
'LPT%d is not within the valid range of %d..%d',
[FPort, 1, 4]);
exit;
end;


ErrorCode := GetPrinterStatus(FPort);

ErrorCode := ErrorCode and $B0; {NEW LINE}

C := ERRORCODE shl 6; {ALWAYS MEANS NOTHING CONNECTED}

if C > 0 then ERRORCODE := $B0; {ELEMINATES NO LPT3 AND NOTHING CONNECTED}

case ErrorCode of
PrnReady : begin FStatusStr := 'Printer Ready'; result := true;
end;
NoConnect : FStatusStr := 'Printer not connected';
Offline,OffLine2 : FStatusStr := 'Printer off line'; {Modified}
PaperOut,PaperOut2 : FStatusStr := 'Printer out of paper'; {Modified}
HookedButOff : FStatusStr := 'Printer connected but turned off'; {New}
else
FStatusStr := 'Printer error code: ' + IntToStr(ErrorCode);
end;

end;


end.
Siney 2003-08-13
  • 打赏
  • 举报
回复
在我的主页上有一个用bcb6开发的元件库(公开源代码),你可以看看

http://siney.yeah.net
yy2001 2003-08-13
  • 打赏
  • 举报
回复
mark
Jinglihui 2003-08-13
  • 打赏
  • 举报
回复
我要用C++写的组件!最好能有事件关联处理的组件!
我不懂电脑 2003-08-13
  • 打赏
  • 举报
回复
原代码装了bcb后在source目录里有很多
Jinglihui 2003-08-13
  • 打赏
  • 举报
回复
书叫什么名字?
nuaacims 2003-08-13
  • 打赏
  • 举报
回复
你去ChinaBcb上下载Lewolf的书把 上面有详细的讲如何作自定义控件
很详细 有代码

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧