i defined a macro that will help create the sql being constructed in my DAService
i found some old post that said to add the function in the DataAbstractServiceAfterAcquireConnection event, but it seems that that one is being called multiple times (so it seems in debugging) and the Registerproc is adding the same over and over again…(Tlist.add)
so is this the correct approach (
DataAbstractServiceAfterAcquireConnection(
aSender: TObject; const aConnectionName: string;
const aAcquiredConnection: IDAConnection);
begin
var mac:IDAHasMacroProcessor;
if Supports(aAcquiredConnection, IDAHasMacroProcessor, mac) then
mac.GetMacroProcessor.RegisterProc(‘CheckBitwise’, CheckBitwise, 2);
and as a followup, although the correct sql gets constructed at first sight, i want to be able to check a bit of an integer value, but the macro converts the bit value into a string, so it compares an int with a string…
OnAfterAcquireConnection is fired only so it is suitable place.
Note: You are using TROPooledClassFactory so you are using services from pool. also connection may have already registered method in macro processor .
workaround:
register variable and check for if it, like
var mac:IDAHasMacroProcessor;
if Supports(aAcquiredConnection, IDAHasMacroProcessor, mac) then begin
if mac.GetMacroProcessor.IndexOfName('mytest') = -1 then begin
mac.GetMacroProcessor.AddVariable('mytest');
mac.GetMacroProcessor.RegisterProc(‘CheckBitwise’, CheckBitwise, 2);
end;
end;