INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Inheriting forms and overriding properties

Inheriting forms and overriding properties

(OP)
I have come across an awkward issue and resolved it, and wanted to document the trouble. What I have is 4 different forms which I embed into different tabs inside the main form. I intend to add more than just 4 forms/tabs, and was seeking ways of adding/removing pages. After the 4 separate forms were already designed, I created another new form "TBaseForm" which I in turn converted the 4 forms to inherit from "TBaseForm" instead of the standard "TForm". Here's the base form:

CODE

unit uBaseForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TFormBusyEvent = procedure(Sender: TObject; const Busy: Bool) of object;
  TFormProgress = procedure(Sender: TObject; const Position, Max: Integer) of object;

  TBaseForm = class(TForm)
  private
    FBusy: Bool;
    FOnBusy: TFormBusyEvent;
    FMax: Integer;
    FPosition: Integer;
    FOnProgress: TFormProgress;
    procedure SetBusy(const Value: Bool);
    procedure DoProgress(const Position, Max: Integer);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Busy: Bool read FBusy write SetBusy;
    property Position: Integer read FPosition;
    property Max: Integer read FMax;
    property OnBusy: TFormBusyEvent read FOnBusy write FOnBusy;
    property OnProgress: TFormProgress read FOnProgress write FOnProgress;
  end;

var
  BaseForm: TBaseForm;

implementation

{$R *.dfm}

{ TBaseForm }

constructor TBaseForm.Create(AOwner: TComponent);
begin
  inherited;
  Busy:= True;
  try
    FPosition:= 0;
    FMax:= 0;
  finally
    Busy:= False;
  end;
end;

destructor TBaseForm.Destroy;
begin
  inherited;
end;

procedure TBaseForm.SetBusy(const Value: Bool);
begin
  FBusy := Value;
  if Value then begin
    Screen.Cursor:= crHourglass;
  end else begin
    Screen.Cursor:= crDefault;
  end;
end;

procedure DoProgress(const Position, Max: Integer);
begin
  FPosition:= Position;
  FMax:= Max;
  if assigned(FOnProgress) then
    FOnProgress(Self, FPosition, FMax);
end;

end. 

The issue I was facing was when one of these inherited forms was created in runtime, I was getting "Property not found" errors.

The solution was that I was using the property name "Position", which is already used by the original "TForm". So I changed references from "Position" and "FPosition" to "Progress" and "FProgress". Everything works fine now.

So in the end, the problem was just using a property which was already reserved by its ancestor, and not properly overriding it.

JD Solutions

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close