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

  • Home
  • SEARCH
  • 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 8819105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:16:15+00:00 2026-06-14T05:16:15+00:00

Take a look the following code : uses TypInfo, Dialogs, Classes, Generics.Collections, ADODB, DB,

  • 0

Take a look the following code :

uses
  TypInfo, Dialogs, Classes, Generics.Collections, ADODB, DB, SysUtils;

type
  TTable_1 = (ID, FName, LName, FatherName);

type
  TBaseTable<TableType> = class(TADOQuery)
  public
    constructor Create(AOwner: TComponent); Override;
    procedure Select(DS: TDataSource);
  end;

implementation

{ TBaseTable<TableType> }

constructor TBaseTable<TableType>.Create(AOwner: TComponent);
begin
  inherited;
  Self.Connection := DataModule3.ADOConnection1;
  Self.Connection.Connected := True;
end;

procedure TBaseTable<TableType>.Select(DS: TDataSource);
var
  Query: string;
  EnumIndex: Byte;
begin
  EnumIndex := 0;
  Query := 'SELECT ';
  while (GetEnumName(TypeInfo(TableType), EnumIndex) <> UnitName) do
  begin
    Query := Query + GetEnumName(TypeInfo(TableType), EnumIndex) + ',';
    Inc(EnumIndex);
  end;
  Query := Copy(Query, 0, Length(Query) - 1);
  Query := Query + ' FROM Table_1';
  Close;
  SQL.Text := Query;
  Open;
  DS.DataSet := Self;
end;

I use it like :

var
  Test: TBaseTable<TTable_1>;
begin
  Test := TBaseTable<TTable_1>.Create(Self);
  Test.Select(DataSource1);
end;

As you can see, I write the name of the table in the query as static string ( ‘Table_1’ ), I want to get the enum name and pass it to select statement as table name to make code more usable.

Another question is how to get the passed enum size to get the field names, as you can see currently I compare the current enum name with Unit name, it’s bad idea, anyone can help me?

At least I want to develop a class, write an Enum for each table in my database and pass it to my class and my class’s methods use it to Select, Insert, Edit and etc.

I want to write a micro ORM for my personal use.

Thanks.

  • 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-14T05:16:17+00:00Added an answer on June 14, 2026 at 5:16 am

    You can use the new System.RTTI unit:

    function TBaseTable<TableType>.Select: string;
    var
      EnumIndex: Byte;
      Context: TRttiContext;
      TableTypeRtti: TRttiEnumerationType;
    begin
      Context := TRttiContext.Create;
      try
        TableTypeRtti := Context.GetType(TypeInfo(TableType)) as TRttiEnumerationType;
        Result := 'SELECT ';
        for EnumIndex := TableTypeRtti.MinValue to TableTypeRtti.MaxValue do begin
          Result := Result + GetEnumName(TypeInfo(TableType), EnumIndex) + ',';
        end;
        Result := Copy(Result, 0, Length(Result) - 1);
        Result := Result + ' FROM ' + TableTypeRtti.Name;
      finally
        Context.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look that the following code snippet: A a = null try {
Please take a look at the following autocomplete code. $(document).ready(function(){ $(#the_input).autocomplete(/autocomplete.php, { //some options
Please take a look at following code: #include <stdio.h> #include <iostream> using namespace std;
take a look at the following code I attempted to write inside a constructor:
take a look in following code: <?php $a = 20; $a= NULL; //or unset($a)
Can you please take a look at following code and let me know why
Take a look at the following code static size_t reader(void *ptr, size_t size, size_t
take a look at the following code var a = new View(); a =
Take a look at the following code: Number.prototype.isIn = function () { for (var
Take a look at the following code: var o; (function (p) { p =

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.