COM's theory
In an example
COM's interface is the core of COM. All COM interfaces are derived through iUnknown, which informs customers that those interfaces are valid, that is, they have been defined. The general way to define is as follows:
ISIMPLEINTERFACE = Interface (IUNKNOWN)
Function GetName: String
Procedure setName (v_name: string)
END;
If you join this one in the above interface:
ISIMPLEINTERFACE = Interface (IUNKNOWN)
V_name: String;
Function GetName: String
Procedure setName (v_name: string)
END;
This is not allowed because we say that the interface method is like a placeholder. It is necessary to implement class leadership. V_Name: String This sentence is just a data member will never have any meaning, if you want to define Can only be defined in the implementation class.
Now give an example of COM, there is no practical use, but at least the problem:
Unit unit1;
Interface
Uses
Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, stdctrls;
Type
TFORM1 = Class (TFORM)
Label1: TLABEL;
EDIT1: TEDIT;
Button1: tbutton;
Button2: tbutton;
Procedure formcreate (Sender: TOBJECT);
Procedure Button1Click (Sender: TOBJECT);
Procedure Button2Click (Sender: TOBJECT);
Procedure formclose (Sender: Tobject; VAR Action: Tclosection);
Private
{Private Declarations}
public
{Public declarations}
END;
ISIMPLEINTERFACE = Interface (IUNKNOWN)
Procedure setValue (v_value: integer);
Function GetValue: Integer;
END;
TSIMPLEIMPLE = Class (TinterFaceDObject, ISIMPLEINTERFACE)
Public
Value: integer;
Procedure setValue (v_value: integer);
Function GetValue: Integer;
END;
VAR
FORM1: TFORM1;
v_obj: tsimpleimple;
IMPLEMentation
{$ R * .dfm}
{TsimpleImple}
Function TSIMPLE.GETVALUE: Integer;
Begin
Result: = Value;
END;
Procedure TsimpleIMple.SetValue (v_value: integer);
Begin
Value: = v_value;
END;
Procedure TFORM1.FormCreate (Sender: TOBJECT);
Begin
v_obj: = TsimpleImple.create;
END;
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
Begin
v_obj.setValue (strtoint (edit1.text)); edit1.clear;
END;
Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT);
Begin
Edit1.Text: = INTTOSTR (v_obj.getvalue);
END;
Procedure TFORM1.FORMCLOSE (Sender: TpoBject; VAR Action: Tclosection);
Begin
v_obj.free;
END;
End.
Blue words define an interface, almost defined in the form of IsImpleInterface, but I want to emphasize that the interface definition is to implement the access of the OLE mode, and implement the class Definition is an implementation of interface functions. Both are different from functional and implementation.
(to be continued…)