Я пытаюсь вызвать IQuerySolution.Resolve , но в структуре StructuredQuery.dll есть нарушение прав доступа.
Пример кода
program Project3;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
ComObj,
ActiveX,
Windows,
Winapi.StructuredQuery,
Winapi.StructuredQueryCondition;
function GetUserDefaultUILanguage: LANGID; stdcall; external 'kernel32.dll' name 'GetUserDefaultUILanguage';
procedure Main(InputString: UnicodeString);
var
cond: ICondition;
manager: IQueryParserManager;
parser: IQueryParser;
solution: IQuerySolution;
st: SYSTEMTIME;
resolved: ICondition;
hr: HRESULT;
type
PIEnumUnknown = ^IEnumUnknown;
PIEntity = ^IEntity;
begin
manager := CreateComObject(CLSID_IQueryParserManager) as IQueryParserManager;
OleCheck(manager.CreateLoadedParser(PWideChar('SystemIndex'), GetUserDefaultUILanguage, IQueryParser, {var}Pointer(parser)));
parser._AddRef; //since it was passed as a naked pointer
OleCheck(parser.Parse(PWideChar(InputString), PIEnumUnknown(nil)^, {out}solution));
OleCheck(solution.GetQuery({out}cond, PIEntity(nil)^));
{
IQueryCondition::Resolve and IConditionFactory2::ResolveCondition turn any date/time references
(relative, such as "today", and absolute, such as "5/7/2009") into absolute date/time references
(in the UTC time zone), and also simplifies the result in various ways.
}
GetLocalTime({var}st);
hr := solution.Resolve({var}cond, 0, {var}st, {out}resolved); //<--access violation
OleCheck(hr);
end;
begin
try
CoInitialize(nil);
Main('Chester Copperpot');
WriteLn('Press enter to close');
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Ошибка происходит на линии:
solution.Resolve(condition, 0, systemTime, {out}resolved);
Код копируется и транскодируется непосредственно из образца структурированного запроса Microsoft ( доступен на GitHub )
Что я делаю не так?