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 8487031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:07:07+00:00 2026-06-10T21:07:07+00:00

I have a TFrame that I use for searching for entities in a Delphi

  • 0

I have a TFrame that I use for searching for entities in a Delphi 2010 VCL project, in the TFrame I have a button edit, that allows the user to open a specific form to browse for that entity. (All the browse forms inherit from a common base browse form)
Currently I achieve this by inheriting from the base frame, then implement the Browse event that fires off the specific form. The only difference each time is what form (type) is shown on the click event, is there a way I can achieve this with generics.
That way I can reuse the same base frame without having to rewrite the same code for each entity (there are over 100), and at form create of the host form pass the type constraint to open the appropriate form on browse.
I have tried adding a generic type to the frame:

type
  Browser<T: TfrmBrowser, constructor> = class
  class function BrowseForm(Owner: Tcomponent): T;
end;

class function Browser<T>.BrowseForm(Owner: Tcomponent): T;
var
_browseForm: T;
begin
  _browseForm := T.Create; // 1st problem T.Create(Owner); throws a comile error
  Result := _browseForm;
end;

and then in the picker frame I expose Start that can be called from the the host form’s create event:

procedure TPickerFrame.Start<T>(const idProp, nameProp, anIniSection: string; aDto: IDto);
begin
    _browseForm:= Browser<T>.BrowseForm(self);
    _iniSectionName:= anIniSection;
    _idField:= idProp;
    _descriptionField:= nameProp;
    _dto := aDto;
end;

the truth is, I don’t really get generics in Delphi, and none of this is working.
Below are excerpts from the frame:

_browseForm: TfrmBrowser;

procedure TPickerFrame.Browse(var DS: TDataSet; var Txt: string; var mr: TModalResult);
begin
  // How do I achieve this with Generics
  // _browseForm := T.Create(nil); // <-- this line is what needs to know the form type at runtime
  // Everything else from here is the same
  _browseForm.ProductName := Application.Title;
  _browseForm.PageSize := 20;
  _browseForm.DatabaseType := bdbtADO;
  _browseForm.ADOConnection := dmdbWhereHouse.BaseADOConnection;
  _browseForm.INISectionName := _iniSectionName;
  _browseForm.DoSelBrowse(DS, Txt, mr, _descriptionField, _text);
  if mr = mrOk then
    begin
      DoSelect(DS);
    end;
end;

Does anyone have any experience with a similar requirement? Any help would be appreciated.
Thanks

Below is an example of the rack master browser:

type
  TfrmMbfRACK_MASTER = class(TMxfrmBrowseHoster)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    //...
  private
    FWHID: Integer;
    procedure SetWHID(const Value: Integer);
    { Private declarations }
  public
    { Public declarations }
    procedure BuildADO(Sender: TObject; Q: TADOQuery); override;
  end;

implementation

{$R *.DFM}

{ TfrmMbfRACK_MASTER }

procedure TfrmMbfRACK_MASTER.FormCreate(Sender: TObject);
  begin
    inherited;
    fmeMxFrmBrowseHoster1.KeyField := 'RACK_ID';
    // FWHID := -2; // 22/06/04
    FWHID := 0; // 22/06/04
  end;

procedure TfrmMbfRACK_MASTER.BuildADO(Sender: TObject; Q: TADOQuery);
  begin
    Q.Close;
    Q.SQL.Clear;
    Q.SQL.Add(
      'SELECT R.RACK_DESC, R.RACK_BARCODE, W.ERP_WH, WC.CLASS_NAME, W.DESCRIPTION WAREHOUSE, R.RACK_PACKING_ORDER,  ');
    //...
  end;

The base class

type
  TMxfrmBrowseHoster = class(TfrmMxForm)
  protected
    // ...
    procedure FormCreate(Sender: TObject);
    procedure BuildADO(Sender: TObject; ADOQ: TADOQuery); virtual; abstract;
  public

  procedure TMxfrmBrowseHoster.FormCreate(Sender: TObject);
  begin
    TMxFormProductName := Application.Title;
    fmeMxFrmBrowseHoster1.Initialise;
    INISectionName := Name;
    AbortAction := False;
    fmeMxFrmBrowseHoster1.OnSelect := SelectNormaliser;
    fmeMxFrmBrowseHoster1.OnNeedADO := BuildADO;
    fmeMxFrmBrowseHoster1.INISectionName := self.Name;
    fmeMxFrmBrowseHoster1.MultiSelect := dxBarLargeButton10.Down;
    fmeMxFrmBrowseHoster1.AutoSaveGrid := True;
    dxBarEdit1.OnChange := ActPageSizeChangedExecute;
    FormStorage.RestoreFormPlacement;

    ActConfirmDelete.Execute;
  end;
  • 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-06-10T21:07:09+00:00Added an answer on June 10, 2026 at 9:07 pm

    I find your question a little on the vague side and I’m not 100% sure I understand exactly what you are asking. However, I know how to deal with your problem when calling the constructor. Perhaps that’s all you need help with.

    You need to use virtual constructor polymorphism and a bit of casting:

    class function Browser<T>.BrowseForm(Owner: Tcomponent): T;
    var
    _browseForm: T;
    begin
      _browseForm := TfrmBrowser(T).Create(Owner); 
      Result := _browseForm;
    end;
    

    This relies on virtual constructor polymorphism. So you must make sure that each constructor for every class derived from TfrmBrowser is marked with the override directive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a native Delphi TFrame that emulates Roy Tanck's Cumulus Tag Cloud viewer,
I have written a set of Win32 dlls that encapsulate a Delphi Frame (see
We have a platform using VCL TFrame as rendering surface for OpenGL. Using FireMonkey,
I have a TFrame descendent that has on it a sizable panel which is
I have a visual component that I built from a TFrame (but then registered
I'm using Delphi 2007 Pro. I have a runtime package that includes a number
I have a frame in my project ( TFrame 's descendant) and want to
Have done quite a bit of searching for a guide (of any substance) for
I have a TFrame (fraDisplay) with a TTimer (timAnimateDataChange). The timer is used to
i have 2 tframes, and an add button. I am trying to add one

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.