Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 720471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:45:42+00:00 2026-05-14T05:45:42+00:00

I’m to code a TExpandedShape class inherited from TShape. TExpandedShape must act like TShape

  • 0

I’m to code a TExpandedShape class inherited from TShape. TExpandedShape must act like TShape and be able to draw extra shapes: Polygon and Star.
Here is my code

unit ExpandedShape;
interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs,          ExtCtrls, Windows;

type
  TExpandedShapeType = (
            stRectangle, stSquare, stRoundRect, stRoundSquare, stEllipse, stCircle,
            stPolygon,
            stStar
           );
 TExpandedShape = class(TShape)
 private
       FShape: TExpandedShapeType;
       FEdgeCount: integer;
       procedure SetShape(const Value: TExpandedShapeType);
       procedure SetEdgeCount(const Value: integer);
 public
       procedure Paint; override;
 published
       property Shape : TExpandedShapeType read FShape write SetShape;// default   stPolygon;
       property EdgeCount : integer read FEdgeCount write SetEdgeCount default 5;

 end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Course', [TExpandedShape]);
end;

// TExpandedShape 

procedure TExpandedShape.Paint;
begin
  case Shape of
    stStar :    begin {Draw Star}
                end;
    stPolygon : begin {Draw Polygon}                 
                end;
    else  begin 

{It is supposed to draw Circle, Rectangle etc, but it does not}

          inherited; 
          end;
   end;
  end;

procedure TExpandedShape.SetEdgeCount(const Value: integer);
begin
  FEdgeCount := Value;
  Repaint;
end;

procedure TExpandedShape.SetShape(const Value: TExpandedShapeType);
begin
  FShape := Value;
  Repaint;
end;
end.

So, what is wrong?
IMO TShape.Paint checks private value like FShape in case section and then decides what to draw. When inherited Paint method is called in my code it checks FShape value sees default 0 value [stRectangle] in there and draws it.

PS: I did solve it with blackmagic way using Shape1 property instead of Shape one and if Shape1 value is not stPolygon or stStar i do like this: begin Shape := TShapeType(Shape1); inherited end; But this option is not really an option. I need a good short nice-looking one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:45:43+00:00Added an answer on May 14, 2026 at 5:45 am

    add this inherited line before your inherited….

      inherited Shape := TShapeType(Shape);  // ** add this line **  
      inherited;   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.