Home Component Writing

Creating Custom DBText Components

edited December 2002 in Component Writing
Is it possible to create and register a new ppDBText component descendant
with special features, such as automatic "Proper"ing of a DBText field?

If so, where do I start to create such components? Is there an example?

I find myself repeatedly having to use label components and reformatting
database text at run-time. My most common reformats are:

Removing extraneous characters: '_','-', etc.
Propering: Converting JOHNNIE becomes Johnnie
Lookups: Integer 3 becomes "White"
Forcing uppercase: oFF becomes OFF
Forcing lowercase: 10X12 becomes 10x12
Expanding Booleans: TRUE becomes "Yes"
Expanding single characters (like lookup): N becomes "No"
Reformatting phone numbers: 713-555-1212 becomes (713) 555-1212

If something like this already exists and is reasonably priced I'd buy it
today. If I write them myself I'll give them away to anyone that want them.

Thanks,

-Johnnie

Comments

  • edited December 2002
    I've looked at the RCL Checkbox package project but don't know where to
    start on doing my own much more simple component.

    I just want to take the text that would be printed by ppDBText and modify it
    right before printing. The component has to be registered so I can drop it
    on a report at design time.

    -Johnnie
  • edited December 2002
    One way would be to make a component that inherits from the TppDBText
    component
    (ppCtrls.pas) and simply override the GetTheText function to make it do
    what you want to.

    Example of registration for ReportBuilder components:

    procedure Register;
    begin
    RegisterNoIcon([TTWGrid]);
    end;
    initialization
    ppRegisterComponent(TTWGrid, 'TWComps', 100, 0, 'TWGrid',
    HInstance);
    finalization
    ppUnRegisterComponent(TTWGrid);
    end.

    Hope this help.

    --
    Daniel Lemire
  • edited December 2002
    Here is a full example of what Daniel is talking about:

    http://www.digital-metaphors.com/tips/CustomDBTextComponent.zip


    Cheers,

    Jim Bennett
    Digital Metaphors

  • edited December 2002
    Thanks - I'm going to download it right now.

    Until I get the components done is there an easy way to modify the text
    before printing in the existing DBText components during one of the events?
    I was just going to select a group of DBText components and assign the same
    event handler, but I don't know which event/parameters to use and my tests
    haven't worked right.

    -Johnnie

  • edited December 2002
    It looks like I'll be able to do this really quick thanks to this example.

    But I'm still curious about doing it in code using an event in case that
    comes up for another case.

    -Johnnie
  • edited December 2002
    The example was spot-on and one hour later I have most of my components
    working.

    Thanks!
  • edited December 2002
    If you want to do it in the standard object event you could use the OnGetText
    event of the TppLabel or TppDBText. Just modify the Text parameter that's
    passed in the event.

    Example:

    procedure TForm1.ppDBText1GetText(Sender: TObject; var Text: String);
    begin
    Text := LowerCase(Text);
    end;


    Cheers
    --
    Daniel Lemire
    Programmeur,
    Conception Design Ware Inc.
    Tél.: 819-868-8853
    Fax : 819-868-8855
This discussion has been closed.