?? tnemulvt.pas
字號:
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program: TNEMULVT.PAS
Description: Delphi component combining both TnCnx and EmulVT components.
Hence it does ANSI emulation using TCP/IP telnet protocol.
Author: Fran鏾is PIETTE
EMail: http://users.swing.be/francois.piette francois.piette@swing.be
http://www.rtfm.be/fpiette francois.piette@rtfm.be
francois.piette@pophost.eunet.be
Creation: May, 1996
Version: 2.11
Support: Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1996-2000 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@pophost.eunet.be>
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
4. You must register this software by sending a picture postcard
to the author. Use a nice stamp and mention your name, street
address, EMail address and any comment you like to say.
Updates:
Jul 22, 1997 Revised Connect method to be callable from FormCreate event
Adapted to Delphi 3
Sep 05, 1997 TnCnx made public, Minor change to method visibility
Added OnTermType and OnDataAvailable events.
Sep 23, 1997 V202. Added local echo support (incomplete because we should ask
the remote host not to echo characters. Will implement later)
Added TnEmultVTVersion
Sep 24, 1997 V2.03 Complete local echo support.
Sep 25, 1997 V2.04 Port to C++Builder
Feb 19, 1998 V2.05 Replaced private section by protected.
Added TriggerDataAvailable virtual function.
Dec 21, 1998 V2.06 Added fixes from Steve Endicott.
Mar 01, 1999 V2.07 Added conditional compile for BCB4. Thanks to James
Legg <jlegg@iname.com>.
Mar 14, 1999 V2.08 Added OnKeyDown event to allow key trapping.
Ignore any exception when sending fct keys.
Aug 15, 1999 V2.09 Move KeyPress procedure to public section for BCB4 compat.
Aug 20, 1999 V2.10 Added compile time options. Revised for BCB4.
Sep 25, 1999 V2.11 Corrected GetSelTextBuf so that lines are returned in
corrected order (they where returned in reverse order).
Thanks to Laurent Navarro <r2363c@email.sps.mot.com> for finding
this bug and fixing it.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit TnEmulvt;
{$B-} { Enable partial boolean evaluation }
{$T-} { Untyped pointers }
{$X+} { Enable extended syntax }
{$IFNDEF VER80} { Not for Delphi 1 }
{$H+} { Use long strings }
{$J+} { Allow typed constant to be modified }
{$ENDIF}
{$IFDEF VER110} { C++ Builder V3.0 }
{$ObjExportAll On}
{$ENDIF}
{$IFDEF VER125} { C++ Builder V4.0 }
{$ObjExportAll On}
{$ENDIF}
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, EmulVT, TnCnx, IniFiles, TnOptFrm, WSocket;
const
TnEmultVTVersion = 211;
CopyRight : String = ' TTnEmulVT (c) 1996-2000 F. Piette V2.11 ';
type
TTnEmulVTDataAvailable = procedure (Sender : TObject;
Buffer : PChar;
var Len : Integer) of object;
TTnEmulVT = class(TEmulVT)
public
TnCnx : TTnCnx;
protected
FError : Word;
FIniFilename : String;
FSectionName : String;
FKeyName : String;
FHostName : String;
FPort : String;
FTag : LongInt;
FUpperLock : Boolean;
FLocalEcho : Boolean;
FOnSessionClosed : TNotifyEvent;
FOnSessionConnected : TNotifyEvent;
FOnNamesClick : TNotifyEvent;
FOnSendLoc : TNotifyEvent;
FOnTermType : TNotifyEvent;
FOnLocalEcho : TNotifyEvent;
FOnDataAvailable : TTnEmulVTDataAvailable;
FMouseDown : Boolean;
FMouseCaptured : Boolean;
FMouseTop : Integer;
FMouseLeft : Integer;
FFocusDrawn : Boolean;
FFocusRect : TRect;
procedure TriggerDataAvailable(Buffer: PChar; Len: Integer); virtual;
procedure TnCnxDataAvailable(Sender: TTnCnx; Buffer: PChar; Len : Integer);
procedure TnCnxSessionClosed(Sender: TTnCnx; Erc: Word);
procedure TnCnxSessionConnected(Sender: TTnCnx; Erc: Word);
procedure TnCnxSendLoc(Sender: TObject);
procedure TnCnxTermType(Sender: TObject);
procedure TnCnxLocalEcho(Sender: TObject);
procedure Display(Msg : String);
procedure DoKeyBuffer(Buffer : PChar; Len : Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure SetOnEndOfRecord(Value : TNotifyEvent);
function GetOnEndOfRecord : TNotifyEvent;
procedure SetLocation(Value : String);
function GetLocation : String;
procedure SetHostName(newValue : String);
public
procedure RequestLocalEcho(newValue : Boolean);
function GetLocalEcho : Boolean;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect;
procedure Disconnect;
procedure EditOptions;
procedure RestoreOptions;
function IsConnected : Boolean;
function Send(Data : Pointer; Len : Integer) : integer;
function SendStr(Data : String) : integer;
function GetSelTextBuf(Buffer: PChar; BufSize: Integer): Integer;
procedure KeyPress(var Key: Char); override;
published
property IniFilename : String read FIniFileName write FIniFileName;
property SectionName : String read FSectionName write FSectionName;
property KeyName : String read FKeyName write FKeyName;
property Error : Word read FError write FError;
property HostName : String read FHostName write SetHostName;
property Port : String read FPort write FPort;
property Tag : LongInt read FTag write FTag;
property Location : String read GetLocation write SetLocation;
property UpperLock : Boolean read FUpperLock write FUpperLock;
property LocalEcho : Boolean read FLocalEcho write FLocalEcho;
property OnKeyDown;
property OnSessionClosed : TNotifyEvent read FOnSessionClosed
write FOnSessionClosed;
property OnSessionConnected : TNotifyEvent read FOnSessionConnected
write FOnSessionConnected;
property OnEndOfRecord : TNotifyEvent read GetOnEndOfRecord
write SetOnEndOfRecord;
property OnNamesClick : TNotifyEvent read FOnNamesClick
write FOnNamesClick;
property OnSendLoc : TNotifyEvent read FOnSendLoc
write FOnSendLoc;
property OnTermType : TNotifyEvent read FOnTermType
write FOnTermType;
property OnLocalEcho : TNotifyEvent read FOnLocalEcho
write FOnLocalEcho;
property OnDataAvailable : TTnEmulVTDataAvailable read FOnDataAvailable
write FOnDataAvailable;
end;
procedure Register;
implementation
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure Register;
begin
RegisterComponents('FPiette', [TTnEmulVT]);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure FontToIni(Font : TFont; IniFile : TIniFile; Section : String);
var
nBuf : Integer;
begin
IniFile.WriteString(Section, 'FontName', Font.Name);
IniFile.WriteInteger(Section, 'FontSize', Font.Size);
IniFile.WriteInteger(Section, 'FontPitch', ord(Font.Pitch));
nBuf := 0;
if fsBold in Font.Style then
nBuf := nBuf or 1;
if fsItalic in Font.Style then
nBuf := nBuf or 2;
if fsUnderline in Font.Style then
nBuf := nBuf or 4;
if fsStrikeOut in Font.Style then
nBuf := nBuf or 8;
IniFile.WriteInteger(Section, 'FontStyle', nBuf);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure IniToFont(Font : TFont; IniFile : TIniFile; Section : String);
var
FontName : String;
nBuf : Integer;
begin
FontName := IniFile.ReadString(Section, 'FontName', '*');
if FontName <> '*' then begin
Font.Name := FontName;
Font.Size := IniFile.ReadInteger(Section, 'FontSize', 9);
Font.Pitch := TFontPitch(IniFile.ReadInteger(Section, 'FontPitch', 12));
nBuf := IniFile.ReadInteger(Section, 'FontStyle', 0);
Font.Style := [];
if (nBuf and 1) <> 0 then
Font.Style := Font.Style + [fsBold];
if (nBuf and 2) <> 0 then
Font.Style := Font.Style + [fsItalic];
if (nBuf and 4) <> 0 then
Font.Style := Font.Style + [fsUnderline];
if (nBuf and 8) <> 0 then
Font.Style := Font.Style + [fsStrikeOut];
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor TTnEmulVT.Create(AOwner: TComponent);
var
Rect : TRect;
begin
inherited Create(AOwner);
if TnCnxVersion < 203 then
raise Exception.Create('TTnEmulVT need TTnCnx version 2.03 or higher ' +
'Please download last release from ' +
'http://www.rtfm.be/fpiette/indexuk.htm');
TnCnx := TTnCnx.Create(Self);
TnCnx.OnDataAvailable := TnCnxDataAvailable;
TnCnx.OnSessionClosed := TnCnxSessionClosed;
TnCnx.OnSessionConnected := TnCnxSessionConnected;
TnCnx.OnSendLoc := TnCnxSendLoc;
TnCnx.OnTermType := TnCnxTermType;
TnCnx.OnLocalEcho := TnCnxLocalEcho;
FIniFileName := 'TNEMULVT.INI';
FSectionName := 'Windows';
FKeyName := 'TnEmulVT';
FPort := 'telnet';
Rect.Top := -1;
SelectRect := Rect;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
destructor TTnEmulVT.Destroy;
begin
TnCnx.Free;
inherited Destroy;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.SetHostName(newValue : String);
begin
FHostName := newValue;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TTnEmulVT.GetLocalEcho : Boolean;
begin
Result := TnCnx.LocalEcho;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.RequestLocalEcho(newValue : Boolean);
begin
if newValue then
TnCnx.DontOption(TN_ECHO)
else
TnCnx.DoOption(TN_ECHO);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.SetLocation(Value : String);
begin
TnCnx.Location := Value;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TTnEmulVT.GetLocation : String;
begin
Result := TnCnx.Location;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.Display(Msg : String);
begin
WriteStr(Msg);
Repaint;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.SetOnEndOfRecord(Value : TNotifyEvent);
begin
TnCnx.OnEndOfRecord := Value;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TTnEmulVT.GetOnEndOfRecord : TNotifyEvent;
begin
Result := TnCnx.OnEndOfRecord;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.TnCnxSendLoc(Sender: TObject);
begin
if Assigned(FOnSendLoc) then
FOnSendLoc(Self);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.TnCnxTermType(Sender: TObject);
begin
if Assigned(FOnTermType) then
FOnTermType(Self);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.TnCnxLocalEcho(Sender: TObject);
begin
if Assigned(FOnLocalEcho) then
FOnLocalEcho(Self);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.TriggerDataAvailable(Buffer: PChar; Len: Integer);
begin
if Assigned(FOnDataAvailable) then
FOnDataAvailable(Self, Buffer, Len);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TTnEmulVT.TnCnxDataAvailable(Sender: TTnCnx; Buffer: PChar;
Len: Integer);
var
I : Integer;
begin
TriggerDataAvailable(Buffer, Len);
if Len <= 0 then
Exit;
for I := 0 to Len - 1 do begin
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -