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:
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
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