Delphi to write custom interfaces and use

Delphi to write your own letter to feel very sophisticated people, including their own.

Delphi write their own controls is not difficult, the difficulty lies in the development of complex controls. (In fact, the programming will be a lot of things are not hard, so I'm afraid I think the future is difficult to write their own controls, specially in this recording process to write their own controls, by the way also wrote using the interface)

The first step: control code:

Here is a Unit content control:

Unit pgdbedit; 

interface 

uses 
  the SysUtils, the Classes, Controls, StdCtrls, CnEdit; 

const 
  IID_pgDBConInterface = ' {} 88CEA70D-0506-4CC0-ABB0-4BDBFA0DDBCE ' ; 


type 
  TdbType = (dbText, dbInteger, dbFloat, dbBit, dbtime, dbBlob); / / text type 

  IpgDBConInterface = interface (IInterface) // defines the operation control database interface 
    [IID_pgDBConInterface]
     // Stdcall Drawing mode indicating argument function from right to left 
    function GetCanUpdate: Boolean;
     Procedure SetCanUpdate (value: Boolean);
     Property DB_canUpdate: Boolean read GetCanUpdate write SetCanUpdate; //是否更新数据。
  end;
  TpgDbEdit = class(TEdit, IpgDBConInterface)
  private
    { Private declarations }
    FCanUpdate: Boolean;
    function GetCanUpdate: Boolean;
    procedure SetCanUpdate(value: Boolean);
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
    property DB_canUpdate: Boolean read GetCanUpdate write SetCanUpdate; //是否更新数据。

implementation

function tpgdbedit.GetCanUpdate: Boolean;
begin
  Result:=FCanUpdate;
end;

procedure tpgdbedit.SetCanUpdate(value: Boolean);
begin
  FCanUpdate:=value;
end;
end.

Note: There is no RegisterComponents because the plan to create two packages, one package, and package design at runtime.

 

Step 2: Create a registration unit:

Here is the source of this unit:

Unit pgControlsRegister; 

interface 
uses 
  the Classes; 

Procedure the Register;
 { * control component editor, the property editor registration process } 

Implementation 

uses 
  pgdbedit; 

Procedure the Register;
 the begin 
  RegisterComponents ( ' pgControls ' , [TpgDbEdit]);
 End ; 

End .

Step 3: Create the package runtime:

(File -> New -> Other -> Package)

Creating out above the midpoint Package Add button to add the first step into the unit, and then point above the Options button, select the Runtime only in the Usage Options. Click OK to close out the Options, and then compile Compile, the system will prompt need to add additional packages, point to confirm on the line, the system will automatically add the necessary package. In this way, the package is running on the creation finished.

 

Step Four: Create a package design time:

(File -> New -> Other -> Package)

Creating out above the midpoint Package Add button to add the second step of the unit in, and then point above the Options button, select Designtime only in the Usage Options. Click OK to close out the Options, and then compile Compile, the system will prompt need to add additional packages, point to confirm on the line, the system will automatically add the necessary package. In this way, the package design is created when finished.

 

Concepts of these two packages, you can go to:

http://www.cnpack.org/showdetail.php?id=510&lang=zh-cn

Look to reports, I always read the introduction to know, only to get this. Here, we also designed the installation package on the line. Pack and leave running.

Guess you like

Origin www.cnblogs.com/jijm123/p/12364909.html