Delphi TFraction class

I have created a component that allows you to easily manage fractions in Delphi! here you can see its implementation:

type
 TFraction = class(TComponent)
  strict private
   aNumerator: integer;
   aDenominator: integer;
   FOnReduced: TFracEvent;
   function GCD(a, b: integer): integer;
  public
   constructor Create(AOwner: TComponent; aNumerator: integer; aDenominator: integer); reintroduce;
   function toString: string; reintroduce;
   function toDouble: double;
   procedure Reduce;
   class function Add(fraction1, fraction2: TFraction): TFraction;
   class function Subtract(fraction1, fraction2: TFraction): TFraction;
   class function Multiply(fraction1, fraction2: TFraction): TFraction;
   class function Divide(fraction1, fraction2: TFraction): TFraction;
   class function Negative(const Value: TFraction): TFraction;
   class function GetFraction(value: double): TFraction;
  published
   property Numerator: integer read aNumerator write aNumerator;
   property Denominator: integer read aDenominator write aDenominator;
   property OnReduce: TFracEvent read FOnReduced write FOnReduced;
 end;

Basically that is a component that has the ability to create an in-memory representation of a fraction. Then you can make conversions (double to fraction or vice-versa) or operations among them. Here you can see a video in which I show you how to use it, it’s very easy!

Here there is the component registration part. Ask in a video comment for the complete source code! I have created two separated files (design time and runtime) so that you can add whatever you want to my component. Have fun!

unit uFractionRegister;

interface

uses
 Classes,
 uFraction;

procedure Register;

implementation

procedure Register;
begin
 RegisterComponents('AlbertoComp.', [TFraction]);
end;

end.

22 risposte a “Delphi TFraction class”

  1. Just wish to say your article is as surprising. The clarity
    in your put up is simply cool and i can assume you’re a professional
    on this subject. Well with your permission let me to snatch
    your RSS feed to stay up to date with approaching post.
    Thanks one million and please carry on the gratifying work.

  2. Hi! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog post or vice-versa? My website covers a lot of the same subjects as yours and I feel we could greatly benefit from each other. If you happen to be interested feel free to shoot me an email. I look forward to hearing from you! Terrific blog by the way!

  3. Undeniably believe that which you said. Your favorite reason appeared to be on the internet the simplest thing to be aware of. I say to you, I definitely get annoyed while people think about worries that they plainly don’t know about. You managed to hit the nail upon the top as well as defined out the whole thing without having side effect , people can take a signal. Will probably be back to get more. Thanks

  4. I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all website owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  5. Hello just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the problem resolved soon. Kudos

  6. Does your website have a contact page? I’m having trouble locating it but, I’d like to shoot you an e-mail. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.

  7. I’m compiling my latest list. I’m sorry there hasn’t been any recent updates.

    I’ve had some problems building the list along the
    way. I’ll talk more about that at a later date.

  8. I’m getting a new computer but don’t want to lose my Firefox bookmarks. Is there an easy way to save a record of all the URLs in my Bookmarks and then quickly upload them to Firefox on my new computer?.

  9. Thank you a lot for providing individuals with an exceptionally special opportunity to read in detail from this site. It is always very pleasurable plus packed with fun for me personally and my office fellow workers to visit your web site at least 3 times every week to study the latest things you have. Not to mention, I’m also certainly happy concerning the sensational thoughts you give. Selected 1 points in this article are without a doubt the most effective I’ve had.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.