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