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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:00:40+00:00 2026-05-25T00:00:40+00:00

I’m working on a project in RAD Studio 2007, using VCL classes in c++.

  • 0

I’m working on a project in RAD Studio 2007, using VCL classes in c++.

TDBLookupControl is part of VCL & has some undesirable behaviour, which is caused by use of an internal variable SearchTickCount

var
   SearchTickCount: Integer = 0; //file scope in DBCtrls.pas

procedure TDBLookupControl.ProcessSearchKey(Key: Char);
var
  TickCount: Integer;
  S: string;
begin
//some code removed for brevity
      TickCount := GetTickCount;
      if TickCount - SearchTickCount > 2000 then SearchText := '';
      SearchTickCount := TickCount;
//some code removed for brevity
end;

However, SearchTickCount has never been PACKAGEd inside the VCL, as in example below.

extern PACKAGE int SearchTickCount;

I’d like to set SearchTickCount to zero (on demand) in my c++ code.
Externing it in my code makes the c++ compile. However, the linker (obviously) cannot find the variable.

namespace Dbctrls
{
  extern int SearchTickCount;
}
// later on, inside a function
Dbctrls::SearchTickCount = 0;

Is there any way/workaround to link to this variable?

EDIT:
Unfortunately, we’re also using some custom controls that derive from TDBLookupControl so I was tring to avoid creating more custom controls.

  • 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-25T00:00:41+00:00Added an answer on May 25, 2026 at 12:00 am
    static int* s_TimerMemoryAddress;
    
    union VTableHelper
    {
        char* pointer;
        char** deref;
        unsigned int adjustment;
    };
    
    #pragma pack(1)
    struct TInstructionHack
    {
        WORD OpCodePrefix;
        int* OpCodeAddresss;
    };
    
    union FuncPtr
    {
        TInstructionHack* Checker;
        char* Increment;
    };
    #pragma pack()
    

    Since TDBLookupControl::ProcessSearchKey is virtual, a pointer to this function
    doesn’t return an actual non static member function pointer address.
    Instead, it returns a vtable address, which points to a thunk
    (a small bit of code that redirects the virtual function to correct derived
    object non static member function). Below code figures out the final (non-virtual)
    address of the member function TDBLookupControl::* ProcessSearchKey based on thunk

    try
    {
        std::auto_ptr<TDBLookupControlHelper> hack(new TDBLookupControlHelper);
        TDBLookupControlHelper* ptrptr = hack.get();
    
        VTableHelper thunk;
        thunk.pointer = reinterpret_cast<char*>(ptrptr);
        thunk.pointer = *thunk.deref;       //get virtual table pointer
        //adjust for specific function pointer (TDBLookupControl::* ProcessSearchKey)
          as specified by thunk
        thunk.adjustment += 0xF4;       
        thunk.pointer = *thunk.deref;
        thunk.adjustment += 0x02;       //adjust for long jump instruction
        thunk.pointer = *thunk.deref;
        //get actual location of TDBLookupControl::ProcessSearchKey
        thunk.pointer = *thunk.deref;
    
        FuncPtr ptr;
        ptr.Increment = thunk.pointer;
    
        //2000 is completely arbitrary, only to prevent an infinite loop
        for(int counter = 0; counter < 2000 && s_TimerMemoryAddress == NULL; ++counter)
        {
             // Looking for SUB EAX, [SearchTickCount]
            if(ptr.Checker->OpCodePrefix == 0x052B)
                s_TimerMemoryAddress = ptr.Checker->OpCodeAddresss;
            else
                ptr.Increment++;
            counter++;
        }
    }
    catch(...) // catch any illegal dereferences of VTableHelper
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace

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.