Thoughts from Dan Miser RSS 2.0
 Monday, March 07, 2005
I needed to create a custom TField class to handle some special processing recently. It was surprisingly easy to get this working:
1. First, create a descendant TField class and put it in a run-time package.

type
  TDrmBCDField = class(TBCDField)
    //override whatever methods you need here
  end;

2. Next, create a registration unit and place that in a design-time package. This unit has nothing more than this:

unit uDrmBCDFieldReg;

interface

procedure Register;

implementation

uses
  uDrmBCDField,
  DB;

procedure Register;
begin
  RegisterFields([TDrmBCDField, TDrmFMTBCDField]);
end;

end.

After compiling these packages, you can now get the new custom TField type to display when selecting "New Field..." in the Dataset designer. However, this doesn't address places where you don't use persistent fields, and it doesn't address the (IMO) more commonly used "Add Fields..." or "Add All Fields" context menu items. In order to always use your new custom class, you need to add code like this to your run-time package. By doing this, both the Delphi IDE and your code at run-time will pick up the proper field class type. I had to use code like this because Delphi 6 doesn't have assignable const permissions in the DB.pas unit.


var
  FieldClass: ^TFieldClass = nil;
initialization
  FieldClass := @DefaultFieldClasses[ftBCD];
  FieldClass^ := TTIPBCDField;
finalization
  if Assigned(FieldClass) then
    FieldClass^ := TBCDField;
end.

Notes:

  • There is a bug in Delphi 6 that causes occasional AVs when rebuilding packages that use RegisterFields. According to this Google post by Vitaliy Lyanchevskiy, you can use RegisterClasses during design and development to get around this problem.
  • Instead of DefaultFieldClasses, you can override TDataset.GetFieldClass if you want specific field types to be used at a TDataset-level.
Monday, March 07, 2005 4:48:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
Delphi
Tracked by:
http://9nr-information.info/43362073/denver-zoo-lights.html [Pingback]
http://9no-information.info/77843928/city-island-bronx.html [Pingback]
http://9nc-information.info/81048277/speedo-photo.html [Pingback]
http://9nl-information.info/10715190/digital-photo-equipment.html [Pingback]
http://9nv-information.info/62580054/index.html [Pingback]
http://9nw-information.info/92106675/index.html [Pingback]
http://9nt-information.info/52112351/index.html [Pingback]
http://9nc-information.info/98237255/index.html [Pingback]
http://9nx-information.info/21689237/index.html [Pingback]
http://9nk-information.info/86959699/save-a-life-with-5.html [Pingback]
http://9nf-information.info/72555784/index.html [Pingback]
http://9qf-information.info/36442339/dora-esploratrice-it.html [Pingback]
http://9oy-information.info/68153205/index.html [Pingback]
http://9qd-information.info/50075170/index.html [Pingback]
http://9oo-information.info/50897069/index.html [Pingback]
http://9oa-information.info/67900784/index.html [Pingback]
http://9qi-information.info/78775192/volo-tampere-levi.html [Pingback]
http://9ou-information.info/53431660/index.html [Pingback]
http://9qb-information.info/36065837/index.html [Pingback]
http://9rw-information.info/88501827/super-one-home-page.html [Pingback]
http://9rb-information.info/10980022/index.html [Pingback]
http://9rm-information.info/19535591/index.html [Pingback]
http://9rt-information.info/08786676/index.html [Pingback]
http://9rt-information.info/77295635/index.html [Pingback]
http://9rg-information.info/43713474/index.html [Pingback]
http://9rt-information.info/30449125/index.html [Pingback]
http://9rr-information.info/13728624/index.html [Pingback]
http://9uafp-le-informazioni.info/56931036/index.html [Pingback]
http://9uaek-le-informazioni.info/63566627/mobile-arte-povera-provincia-milano.h... [Pingback]
http://9uaef-le-informazioni.info/49482065/index.html [Pingback]
http://9uaef-le-informazioni.info/49482065/download-kaspersky-in-italiano.html [Pingback]
http://9uaec-le-informazioni.info/12514355/index.html [Pingback]
http://9uafg-le-informazioni.info/22342082/mappa-navigatore-gps-audi.html [Pingback]
http://9uaep-le-informazioni.info/86905187/index.html [Pingback]
http://9uafm-le-informazioni.info/46298736/index.html [Pingback]
http://9uahj-le-informazioni.info/35348891/rin-grande-innamorata-sesshomaru.html [Pingback]
http://9uagt-le-informazioni.info/22194258/index.html [Pingback]
http://9uagq-le-informazioni.info/45525747/index.html [Pingback]
http://9uagj-le-informazioni.info/72844153/index.html [Pingback]
http://9uahq-le-informazioni.info/36114978/raffaele-trevisani.html [Pingback]
http://9uagl-le-informazioni.info/77163565/harrison-ford-fanpage.html [Pingback]
http://9uagf-le-informazioni.info/54866499/nds-sat.html [Pingback]
http://9uago-le-informazioni.info/79652166/play-bratz-game.html [Pingback]
http://9uaga-le-informazioni.info/12675675/index.html [Pingback]
http://9uagn-le-informazioni.info/55315204/nave-tft.html [Pingback]
http://9uahi-le-informazioni.info/81371712/custodia-subacquea-pentax.html [Pingback]
Navigation
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 306
This Year: 21
This Month: 0
This Week: 0
Comments: 604
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)