📄 server_tlb.pas
字号:
unit Server_TLB;
// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //
// PASTLWTR : $Revision: 1.79 $
// File generated on 8/15/99 1:03:09 AM from Type Library described below.
// ************************************************************************ //
// Type Lib: C:\work\d5dg\code\Ch23\AutoEvents\Server.tlb (1)
// IID\LCID: {2EA1DDA0-5CBD-11D2-9261-00104B700B61}\0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (c:\windows\SYSTEM\StdOle2.Tlb)
// (2) v4.0 StdVCL, (C:\Program Files\Borland\CBuilder4\Bin\stdvcl40.tlb)
// ************************************************************************ //
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
ServerMajorVersion = 1;
ServerMinorVersion = 0;
LIBID_Server: TGUID = '{2EA1DDA0-5CBD-11D2-9261-00104B700B61}';
IID_IServerWithEvents: TGUID = '{2EA1DDA1-5CBD-11D2-9261-00104B700B61}';
DIID_IServerWithEventsEvents: TGUID = '{2EA1DDA3-5CBD-11D2-9261-00104B700B61}';
CLASS_ServerWithEvents: TGUID = '{2EA1DDA5-5CBD-11D2-9261-00104B700B61}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IServerWithEvents = interface;
IServerWithEventsDisp = dispinterface;
IServerWithEventsEvents = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
ServerWithEvents = IServerWithEvents;
// *********************************************************************//
// Interface: IServerWithEvents
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {2EA1DDA1-5CBD-11D2-9261-00104B700B61}
// *********************************************************************//
IServerWithEvents = interface(IDispatch)
['{2EA1DDA1-5CBD-11D2-9261-00104B700B61}']
procedure Clear; safecall;
procedure AddText(const NewText: WideString); safecall;
end;
// *********************************************************************//
// DispIntf: IServerWithEventsDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {2EA1DDA1-5CBD-11D2-9261-00104B700B61}
// *********************************************************************//
IServerWithEventsDisp = dispinterface
['{2EA1DDA1-5CBD-11D2-9261-00104B700B61}']
procedure Clear; dispid 3;
procedure AddText(const NewText: WideString); dispid 4;
end;
// *********************************************************************//
// DispIntf: IServerWithEventsEvents
// Flags: (4096) Dispatchable
// GUID: {2EA1DDA3-5CBD-11D2-9261-00104B700B61}
// *********************************************************************//
IServerWithEventsEvents = dispinterface
['{2EA1DDA3-5CBD-11D2-9261-00104B700B61}']
procedure OnTextChanged(const NewText: WideString); dispid 1;
procedure OnClear; dispid 2;
end;
// *********************************************************************//
// The Class CoServerWithEvents provides a Create and CreateRemote method to
// create instances of the default interface IServerWithEvents exposed by
// the CoClass ServerWithEvents. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoServerWithEvents = class
class function Create: IServerWithEvents;
class function CreateRemote(const MachineName: string): IServerWithEvents;
end;
TServerWithEventsOnTextChanged = procedure(Sender: TObject; var NewText: OleVariant) of object;
// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TServerWithEvents
// Help String : ServerWithEvents Object
// Default Interface: IServerWithEvents
// Def. Intf. DISP? : No
// Event Interface: IServerWithEventsEvents
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TServerWithEventsProperties= class;
{$ENDIF}
TServerWithEvents = class(TOleServer)
private
FOnTextChanged: TServerWithEventsOnTextChanged;
FOnClear: TNotifyEvent;
FIntf: IServerWithEvents;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TServerWithEventsProperties;
function GetServerProperties: TServerWithEventsProperties;
{$ENDIF}
function GetDefaultInterface: IServerWithEvents;
protected
procedure InitServerData; override;
procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: IServerWithEvents);
procedure Disconnect; override;
procedure Clear;
procedure AddText(const NewText: WideString);
property DefaultInterface: IServerWithEvents read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TServerWithEventsProperties read GetServerProperties;
{$ENDIF}
property OnTextChanged: TServerWithEventsOnTextChanged read FOnTextChanged write FOnTextChanged;
property OnClear: TNotifyEvent read FOnClear write FOnClear;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TServerWithEvents
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TServerWithEventsProperties = class(TPersistent)
private
FServer: TServerWithEvents;
function GetDefaultInterface: IServerWithEvents;
constructor Create(AServer: TServerWithEvents);
protected
public
property DefaultInterface: IServerWithEvents read GetDefaultInterface;
published
end;
{$ENDIF}
procedure Register;
implementation
uses ComObj;
class function CoServerWithEvents.Create: IServerWithEvents;
begin
Result := CreateComObject(CLASS_ServerWithEvents) as IServerWithEvents;
end;
class function CoServerWithEvents.CreateRemote(const MachineName: string): IServerWithEvents;
begin
Result := CreateRemoteComObject(MachineName, CLASS_ServerWithEvents) as IServerWithEvents;
end;
procedure TServerWithEvents.InitServerData;
const
CServerData: TServerData = (
ClassID: '{2EA1DDA5-5CBD-11D2-9261-00104B700B61}';
IntfIID: '{2EA1DDA1-5CBD-11D2-9261-00104B700B61}';
EventIID: '{2EA1DDA3-5CBD-11D2-9261-00104B700B61}';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;
procedure TServerWithEvents.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
ConnectEvents(punk);
Fintf:= punk as IServerWithEvents;
end;
end;
procedure TServerWithEvents.ConnectTo(svrIntf: IServerWithEvents);
begin
Disconnect;
FIntf := svrIntf;
ConnectEvents(FIntf);
end;
procedure TServerWithEvents.DisConnect;
begin
if Fintf <> nil then
begin
DisconnectEvents(FIntf);
FIntf := nil;
end;
end;
function TServerWithEvents.GetDefaultInterface: IServerWithEvents;
begin
if FIntf = nil then
Connect;
Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to Server. You must call ''Connect'' or ''ConnectTo'' before this operation');
Result := FIntf;
end;
constructor TServerWithEvents.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TServerWithEventsProperties.Create(Self);
{$ENDIF}
end;
destructor TServerWithEvents.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TServerWithEvents.GetServerProperties: TServerWithEventsProperties;
begin
Result := FProps;
end;
{$ENDIF}
procedure TServerWithEvents.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
begin
case DispID of
-1: Exit; // DISPID_UNKNOWN
1: if Assigned(FOnTextChanged) then
FOnTextChanged(Self, Params[0] (*const WideString*));
2: if Assigned(FOnClear) then
FOnClear(Self);
end; {case DispID}
end;
procedure TServerWithEvents.Clear;
begin
DefaultInterface.Clear;
end;
procedure TServerWithEvents.AddText(const NewText: WideString);
begin
DefaultInterface.AddText(NewText);
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TServerWithEventsProperties.Create(AServer: TServerWithEvents);
begin
inherited Create;
FServer := AServer;
end;
function TServerWithEventsProperties.GetDefaultInterface: IServerWithEvents;
begin
Result := FServer.DefaultInterface;
end;
{$ENDIF}
procedure Register;
begin
RegisterComponents('Servers',[TServerWithEvents]);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -