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

📄 189.htm

📁 水木清华的BBS文章
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="8.htm">上一层</a>][<a href="190.htm">下一篇</a>]
<hr><p align="left"><small>发信人: I007 (阿健), 信区: Visual <br>

标  题: The Delphi Component Writing FAQ <br>

发信站: BBS 水木清华站 (Sat Nov 29 08:29:26 1997) <br>

  <br>

非常值得一看: <br>

  <br>

The Delphi Component Writing FAQ <br>

  <br>

Edited By:      John M. Miano   miano@worldnet.att.net <br>

Version:        9 <br>

Last Updated:   21-Jul-1997 <br>

  <br>

Changes: <br>

  <br>

I finally caught up on all the suggestions everyone has sent me in the <br>

past few months. <br>

  <br>

The original version of this document is now at <br>

  <br>

http://home.att.net/~miano <br>

  <br>

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

Table of Contents <br>



  <br>

Section 1 - Introduction <br>

1.1. What is the purpose of this document? <br>

  <br>

Section 2 - IDE <br>

2.1. How can I locate problems that result when my component is used in the IDE? <br>

  <br>

2.2. How do I view assembly langugage the Delphi Generates? <br>

2.3. I can create my control at run time but it crashes at design time.  What is <br>

 wrong? <br>

2.4. How can I create a component that cannot be dropped on a form? <br>

2.5. What is an easy way to backtrack through source code? <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>

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

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

  <br>

  <br>

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

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

 design mode? <br>

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

style scroll bar? <br>

  <br>

Section 4 - Bound Controls <br>

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

4.2. How can I tell the number of the record I am on in a data set? <br>

  <br>

Section 5 - VCL <br>

5.1. How can I step through the VCL source while debugging? <br>

5.2. My component references other components.  How can I tell if a component my <br>

 component references had been deleted? <br>

5.3. What are component messages? <br>

5.4. My control has focus but it is not getting keystroke messages.  What's happ <br>

ening? <br>

  <br>

Section 6 - Other Sources of Information <br>

6.1. Are there any books one how to write Delphi components? <br>

6.2. Are there any good web sites with information on how to write components? <br>

  <br>

Section 7 - Persistent Objects <br>

7.1. How can I save a complex object containing child objects to the .DFM file. <br>

7.2. How can I tell if my constructor is being called for an object being loaded <br>

 from a stream? <br>

7.3. How can I tell if my component's properties are being saved correctly to th <br>

re being saved correctly to th <br>

e form file? <br>

  <br>

Section 8. Tools for Delphi <br>

8.1. Is there YACC and LEX for Delphi? <br>

8.2. How can I write code to display JPEG files? <br>

  <br>

Section 9. Basic Programming Techniques <br>

9.1. How do I create a dynamic array of objects? <br>

9.2. Where is Wincrt in Delphi 2.0? <br>

9.3. What should the base class be for my component? <br>

9.4. What is the difference between the Free and Destroy methods ? <br>

  <br>

Section 10. Advanced Programming Techniques <br>

10.1. Is there a Delphi equivalent to C++'s I/O stream classes? <br>

10.2. How can I get the text equivalent for an enumerated type? <br>

  <br>

Section 11. Component Virtual Methods <br>

11.1. How can I find out when my component has had its window handle created? <br>

11.2. How can I tell when all the components on my form have been loaded? <br>

11.3. Where is the best place to draw my control? <br>

  <br>

Section 12. Windows API Functions <br>

Section 12. Windows API Functions <br>

12.1. I am trying to scroll the contents of my control but I get an ugly flicker <br>

 effect.  How can I eliminate this? <br>

12.2. How can I restart windows? <br>

12.3. How can I batch updates to when changing the appearance of my control? <br>

  <br>

Section 13. Control Borders <br>

13.1. How come my control does not have a 3D border even when I have CTL3D set t <br>

o True? <br>

13.2 How do I implement a BorderStyle property? <br>

  <br>

Section 14. Control Styles <br>

14.1. How do I stop my control from flickering when it gets repainted? <br>

  <br>

Section 15. Windows Messages <br>

15.1. How come my control does not get keystroke messages for the arrow keys? <br>

15.2. Is there an equivalent of Visual Basic's "DoEvents" statement? <br>

  <br>

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

Section 1 - Introductions <br>

  <br>

1.1. What is the purpose of this document? <br>

  <br>

  <br>

The purpose of this document is to answer common or undocumented questions relat <br>

ed to writing Delphi components.  After spending a ridiculous amount of time try <br>

ing to decipher the TDataLink component it occured to me that there ought to be <br>

some way of recording and sharing solutions to the problems encountered while wr <br>

iting controls. All information is provided as is.  There are no guarantee as to <br>

 its correctness. <br>

  <br>

If you have any questions you would like to be answered or have any contribution <br>

s you think would be suitable for inclusion please send them to the editor.  Rep <br>

orts of errors or omissions are also welcome. <br>

  <br>

In addition to including more answers and questions I am trying to expand in two <br>

 more areas: <br>

  <br>

1. Tools that are of interest to advanced developers: These might not be directl <br>

y related to component writing but they will have some integration with Delphi. <br>

  <br>

2. References to publications:  Since there is not enough room in an FAQ for ext <br>

ensive examples as I come across examples of how to do things in print I will in <br>

clude them here.  This will not be an academic style bibliography I only indend <br>

to include references to the best or most accessible document or publication. <br>

  <br>

  <br>

If you have an suggestions for any of these they are also welcome.  Keep in mind <br>

 that I cannot include an item if I cannot verify it. <br>

  <br>

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

Section 2 - IDE Problems <br>

  <br>

2.1. How can I locate problems that result when my component is used in the IDE? <br>

  <br>

  <br>

The only solution to locating problems I have found is to: <br>

  <br>

1. In Delphi go to Tools/Options then go to the "Library" page. <br>

Check the "Compile With Debug Info" box. <br>

2. Rebuild the library. <br>

3. Run Delphi from within Turbo Debugger. <br>

4. Use "File/Change Dir" to include the source directories. <br>

  <br>

If you get a GPF you can use view the stack and get some idea where the problem <br>

is occuring. <br>

  <br>

Another suggestion from Roger Hernandez <br>

  <br>

  <br>

One way of tracing what is going on inside a component is the following: <br>

  <br>

{$IFDEF DebugOutput} <br>

  OutputDebugString ('Some debug string goes here.'); <br>

{$ENDIF} <br>

  <br>

I have used this technique to trace problems dealing with component <br>

creation, destruction, and property loading while running in the IDE. <br>

It can also be used to debug problems with component property editors <br>

running in the IDE.  One can also use a more complicated system where a <br>

debug function is called that can optionally take a severity level, and <br>

only print messages over a given level.  What I ended up doing was <br>

encapsulating the debug message functions in a unit. <br>

  <br>

  <br>

2.2. How do I view assembly langugage the Delphi Generates? <br>

  <br>

From Glen Boyd <br>

  <br>

Run the REGEDIT program and go to "HKEY_CURRENT_USER\Software\Borland\Delphi\2.0 <br>

\Debugging" and add a string value called EnableCPU and set its string value to <br>

1.  This adds the CPU window to the view menu.  The CPU window is active at run <br>



time for stepping through and stuff like that. <br>

  <br>

2.3. I can create my control at run time but it crashes at design time.  What is <br>

 wrong? <br>

  <br>

1. Your component must descend from TComponent <br>

  <br>

2. Your constructory and destructor declarations must look like: <br>

  <br>

Constructor Create (AOwner : TComponent) ; Override ; <br>

Destructor Destroy ; Override ; <br>

  <br>

3  All fields that are published must be either ordinal, single, double, extende <br>

d, comp, currency, string, small set, method pointer or a class.  The Delphi com <br>

piler does not produce an error if you use any other type in a published section <br>

. However you will get an GPF if you try to use a control that contains a publis <br>

hed declaration of any other type. <br>

  <br>

The following declarations will cause serious problems if you attempt to use TMy <br>

Component in design mode. <br>

  <br>

Type <br>

Type <br>

  TComplex = Record <br>

        RealPart : Double ; <br>

        ComplexPart : Double ; <br>

        End ; <br>

  <br>

class TMyComponent = Class (TComponent) <br>

  Private <br>

    F1 : TComplex ; <br>

  Published <br>

    Property P1 : TComplex Read F1 Write F1 ; <br>

    End ; <br>

  <br>

2.4. How can I create a component that cannot be dropped on a form? <br>

  <br>

From Ray Lischner <br>

  <br>

If you don't want the user to be able to drop the component on a form  then <br>

use then RegisterNoIcon and RegisterClass procedures. <br>

  <br>

2.5. What is an easy way to backtrack through source code? <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 <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>

 <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>

⌨️ 快捷键说明

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