Nirav Kaku said:

>       That's exactly what I need to do. That is to add extra
> functionality to the field. But I am not too sure about how to go
> about it.

Not too difficult depending on exactly how much you want this integrated
into the design time environment. Assuming Delphi 5+:

Step 1. Derive from TField (for a new field type with no inherited
behaviour) or from any existing field type (TStringField for example). Add
what ever behaviour you deem sensible.

Step 2. In a your design time registration code use the RegisterFields
function to tell Delphi that the field is available for use.

Step 3. Use the field type by choosing it as the field type in the Field
Properties box in the New field dialog. This is available from the standard
Delphi Fields Editor. Alternatively you can now exit existing fields to use
the new type, and twiddle the DFM to match. Experts may choose global search
and replace utilities to do this, and folks like us who spend too much time
on tools write custom a Field Editor with data dictionary knowledge and a
auto conversion button!

And there you have it, you field is now being used.

Possible complications:

A. There is no UnregisterField, so once you have a design time package that
registers fields it CANNOT be unloaded and reloaded without nasty exceptions
because of dangling pointers. This omission means that if you start doing
this stuff you need to build your design time packages at the command line,
and you cannot use the automatic build mechanism at all. Not sure if D6
fixes this. It certainly means that you spend a lot of time closing,
compiling a package, an reloading Delphi when you are doing component
development/design time interaction programming.

B. If you are using Delphi 4 or older the Fields Editor does not provide
access to registered fields types. You will then need to write your own
Fields Editor replacement.

C. If you want your field type to be the default type for a particular
TFieldType then you need to create a derived version of the TTable
descendant you want thus to work with and override the protected
GetFieldClass method.

That's most of what we have learned over the last 6 years in this area, so
good luck, and have fun with tour new field types. By using these you can
achieve massive code savings, create more centralised data dictionary
mechanisms, and find subtle bugs in Delphi run time library (eg you can't
have Internal Calc fields and Calculated field in the same dataset!).

Cheers, Max.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to