⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 189.htm

📁 水木清华的BBS文章
💻 HTM
📖 第 1 页 / 共 5 页
字号:
When viewing the source for the VCL units, it's definitely a good idea to <br>

become comfortable with bookmarks in the editor.  That is,  Ctrl+Shift+N, <br>

when N is a number 0-9, to set a bookmark.  Jump to a bookmark using Ctrl+N. <br>

  <br>

2.6. How can I add to the popup menu that is displayed when the right mouse butt <br>

on is clicked on my component? <br>

  <br>

You do this by creating a Component Editor.  One would think that a component ed <br>

itor would be something that is called from the popup menu but it actually contr <br>

ols what appears in the menu or rather the items that your component can add to <br>

the menu. <br>

  <br>

The steps to follow are: <br>

  <br>

1. Create a class that derives from TComponentEditor <br>

2. In your class override the method GetVerbCount, GetVerb, and ExecuteVerb. <br>

3. In your component's Register procedure add a call to RegisterComponentEditor <br>

that associates your component editor with your <br>

  <br>

  <br>

  <br>

 <br>

  <br>

  <br>



  <br>

When viewing the source for the VCL units, it's definitely a good idea to <br>

become comfortable with bookmarks in the editor.  That is,  Ctrl+Shift+N, <br>

when N is a number 0-9, to set a bookmark.  Jump to a bookmark using Ctrl+N. <br>

  <br>

2.6. How can I add to the popup menu that is displayed when the right mouse butt <br>

on is clicked on my component? <br>

  <br>

You do this by creating a Component Editor.  One would think that a component ed <br>

itor would be something that is called from the popup menu but it actually contr <br>

ols what appears in the menu or rather the items that your component can add to <br>

the menu. <br>

  <br>

The steps to follow are: <br>

  <br>

1. Create a class that derives from TComponentEditor <br>

2. In your class override the method GetVerbCount, GetVerb, and ExecuteVerb. <br>

3. In your component's Register procedure add a call to RegisterComponentEditor <br>

that associates your component editor with your <br>

  <br>

  <br>

  <br>

From Ray Konopka <br>

  <br>

When viewing the source for the VCL units, it's definitely a good idea to <br>

become comfortable with bookmarks in the editor.  That is,  Ctrl+Shift+N, <br>

when N is a number 0-9, to set a bookmark.  Jump to a bookmark using Ctrl+N. <br>

  <br>

2.6. How can I add to the popup menu that is displayed when the right mouse butt <br>

on is clicked on my component? <br>

  <br>

You do this by creating a Component Editor.  One would think that a component ed <br>

itor would be something that is called from the popup menu but it actually contr <br>

ols what appears in the menu or rather the items that your component can add to <br>

the menu. <br>

  <br>

The steps to follow are: <br>

  <br>

1. Create a class that derives from TComponentEditor <br>

2. In your class override the method GetVerbCount, GetVerb, and ExecuteVerb. <br>

3. In your component's Register procedure add a call to RegisterComponentEditor <br>

that associates your component editor with your component. <br>

  <br>

This topic is described well in the book "Developing Delphi Components". <br>

  <br>

  <br>

2.7. How come I get I/O 103 in design mode? <br>

  <br>

You probably have WriteLn statements in your code. <br>

  <br>

2.8. Why are my property values not getting saved when I use a component editor? <br>

  <br>

  <br>

I have found that when using a component editor that a component's properties wi <br>

ll not be saved. The property appears to be correct in design mode but when you <br>

run or save the property is set to a different value. <br>

  <br>

It appears that a property editor needs to call <br>

  <br>

 Designer.Modified <br>

  <br>

to let Delphi know that you have changed a property value. <br>

  <br>

------------------------------------------------------------------------ <br>

Section 3 - Using other components within a component <br>

  <br>

3.1. How can I add a scroll bar component to my component and have it work at in <br>

 design mode? <br>

 design mode? <br>

  <br>

You need to define your own scroll bar class that intercepts the CM_DESIGNHITTES <br>

T message. <br>

  <br>

TMyScrollBar = class (TScrollBar) <br>

      Procedure CMDesignHitTest (var Message : TCMDesignHitTest) ; Message CM_DE <br>

SIGNHITTEST ; <br>

    End ; <br>

  <br>

Procedure TMyScrollBar.CMDesignHitTest (var Message : TCMDesignHitTest) ; <br>

  Begin <br>

  Message.Result := 1 ; <br>

  End ; <br>

  <br>

When your component creates one of these scroll bars it needs to use <br>

  <br>

TMyScrollBar.Create (Nil) <br>

  <br>

rather than <br>

  <br>

TMyScrollBar.Create (Self) <br>

  <br>

  <br>

otherwise the scroll bar will display sizing handles when it is click.   This me <br>

ans you need to be sure to explicitly free the scroll bar in your component's de <br>

structor. <br>

  <br>

3.2 How do I create a Windows '95-style scroll bar? <br>

  <br>

You need to set the page size for the scroll bar.   The following code sequence <br>

illustrates this: <br>

  <br>

Procedure SetPageSize (ScrollBar : TScrollBar ; PageSize : Integer) ; <br>

  Var <br>

    ScrollInfo : TScrollInfo ; <br>

  Begin <br>

  ScrollInfo.cbSize := Sizeof (ScrollInfo) ; <br>

  ScrollInfo.fMask := SIF_PAGE ; <br>

  ScrollInfo.nPage := PageSize ; <br>

  SetScrollInfo (ScrollBar.Handle, SB_CTL, ScrollInfo, True) ; <br>

  End ; <br>

  <br>

To retrieve the page size use: <br>

  <br>

Function GetpageSize (ScrollBar : TScrollBar) ; <br>



  Var <br>

    ScrollInfo : TScrollInfo ; <br>

  Begin <br>

  If HandleAllocated Then <br>

    Begin <br>

    ScrollInfo.cbSize := Sizeof (ScrollInfo) ; <br>

    ScrollInfo.fMask := SIF_PAGE ; <br>

    GetScrollInfo (ScrollBar.Handle, SB_CTL, ScrollInfo) ; <br>

    Result := ScrollInfo.nPage ; <br>

    End ; <br>

  <br>

------------------------------------------------------------------------ <br>

Section 4 - Bound Controls <br>

  <br>

4.1. Where is the documentation for the TDataLink class? <br>

  <br>

The C++Builder documentation contains a description of the TDataLink class. It i <br>

s not in any Delphi documentation so far. For those of you who do not have C++Bu <br>

ilder here is the description that has been in this document for a long time: <br>

  <br>

Properties: <br>

=========== <br>

=========== <br>

  <br>

Property:       Active : Boolean (Read Only) <br>

---------------------------------------- <br>

  <br>

Returns true when the data link is connected to an active datasource. <br>

The ActiveChanged method is called to give notification when the state changes. <br>

  <br>

Property:       ActiveRecord: (Read/Write) <br>

-------------------------------------- <br>

  <br>

This sets or returns the current record within the TDatalink's buffer window.  V <br>

alid values are <br>

0..BufferCount - 1.  There appear to be no range checks so assigning values outs <br>

ide this range produces unpredictable results. <br>

  <br>

Property:       BufferCount: (Read/Write) <br>

------------------------------------- <br>

  <br>

The TDataLink maintains a window of records into the dataset  This property is t <br>

he size of this window and determines the maximum number of row that can be view <br>

 simultaneously.  For most controls you would use a BufferCount of one.  For con <br>

trols such as a data grid this value is the number of visible rows. <br>



  <br>

Property:       DataSet: TDataSet (Read) <br>

------------------------------------ <br>

  <br>

The dataset the TDataLink is attached to.  This is a shortcut to DataSource.Data <br>

Set. <br>

  <br>

Property:       DataSource: TDataSource (Read/Write) <br>

------------------------------------------------ <br>

  <br>

Sets or returns data source control the TDataLink is attached to. <br>

  <br>

Property:       DataSourceFixed: Boolean (Read/WRite) <br>

------------------------------------------------- <br>

  <br>

This property is used to prevent the data source for the TDataLink from being ch <br>

anged.  If this property is set to Trye then assigning a value to the DataSource <br>

 property will result in an exception. <br>

  <br>

Property:       Editing: Boolean (Read Only) <br>

---------------------------------------- <br>

  <br>

  <br>

Returns true if the datalink is in edit mode. <br>

  <br>

Property:       ReadOnly: Boolean (read/Write) <br>

------------------------------------------ <br>

  <br>

This property determines if the TDataLink is read only.  It does not appear to a <br>

ffect the attached datalink <br>

or dataset.  If this property is set to True the datalink will not go into edit <br>

mode. <br>

  <br>

Property:       RecordCount: Integer (Read) <br>

--------------------------------------- <br>

  <br>

The property returns the approximate number of records in the attached dataset. <br>

  <br>

Methods: <br>

======== <br>

  <br>

function Edit: Boolean; <br>

----------------------- <br>

  <br>

Puts the TDatalink's attached dataset into edit mode. <br>



  <br>

Return Value: <br>

        True => Success <br>

        False => Failure <br>

  <br>

procedure UpdateRecord; <br>

----------------------- <br>

  <br>

It appears that this is a function that is intended to be called by other parts <br>

of the data base interface and should not be called directly.  All it does is se <br>

t a flag and call UpdateData (described below). <br>

  <br>

  <br>

Virtual Methods <br>

=============== <br>

  <br>

The mechanism for having the TDataLink object communicate with a component is to <br>

 override these procedures. <br>

  <br>

procedure ActiveChanged <br>

------------------------ <br>

This procedure is called whenever the datasource the TDataLink is attached to be <br>

enever the datasource the TDataLink is attached to be <br>

comes active or inactive.  Use the Active property to determine whether or not t <br>

he link is active. <br>

  <br>

procedure CheckBrowseMode <br>

------------------------- <br>

This method appears to get called before any changes take place to the database. <br>

  <br>

  <br>

procedure DataSetChanged; <br>

------------------------- <br>

This procedure gets called when the following events occur: <br>

  <br>

   o Moving to the start of the dataset <br>

   o Moving to the end of the dataset <br>

   o Inserting or Appending to the dataset <br>

   o Deleting a record from the dataset <br>

   o Canceling the editing of a record <br>

   o Updating a record <br>

  <br>

The non-overridden action for this procedure is to call <br>

  <br>

        RecordChanged (Nil) <br>

        RecordChanged (Nil) <br>

  <br>

procedure DataSetScrolled(Distance: Integer) <br>

-------------------------------------------- <br>

This procedure is called whenever the current record in the dataset changes.  Th <br>

e Distance parameter tells how far the buffer window into the dataset was scroll <br>

ed (This seems to always be in the range -1, 0, 1). <br>

  <br>

Use the ActiveRecord to determine which record within the buffer window is the c <br>

urrent one. <br>

  <br>

It is not possible to force a scroll of the buffer window. <br>

  <br>

procedure FocusControl(Field: TFieldRef) <br>

---------------------------------------- <br>

This appears to get called as a result of Field.FocusControl. <br>

  <br>

procedure EditingChanged <br>

------------------------- <br>

This procedure is called when the editing state of the TDataLink changes.  Use t <br>

he Editing property to determine if the TDataLink is in edit mode or not. <br>

  <br>

procedure LayoutChanged <br>



----------------------- <br>

This procedure is called when the layout of the attached dataset changes (e.g. c <br>

olumn added). <br>

  <br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -