我想在Delphi中使用类似SQL的条件
if VarI in SOMESET then
...
[SOMESET]从任何文本文件中读取。
在任何文本文件中存储少量数字,如ini/txt,并从文件中读取并将其替换为set,以便我们可以使用if条件的in操作符
如果我理解你问的是正确的,简单的答案是肯定的。你的术语可能有点偏离-在Delphi中意味着一些非常具体的东西,但我不认为这是你的意思。此外,我不认为你是在询问加载和保存的细节,所以我没有包括这一点。相反,我认为你是在问如何允许在这种特定情况下定义'in',下面是如何
unit Unit1;
interface
uses
System.SysUtils;
type
TMySet = record
private
function GetEntry(const i: integer): integer;
public
Entries : array of integer;
// procedure LoadFromFile( const pFromFile : TFileName );
class operator in ( const pTest : integer; pMyset : TMyset ) : boolean;
property Entry[ const i : integer ] : integer
read GetEntry; default;
end;
implementation
{ TMySet }
function TMySet.GetEntry(const i: integer): integer;
begin
Result := Entries[ i ]; // allow default exceptions to occur
end;
class operator TMySet.in(const pTest: integer; pMyset: TMyset): boolean;
var
i: Integer;
begin
for i := Low(pMyset.Entries) to High(pMyset.Entries) do
begin
if i = pMyset[ i ] then
begin
Result := TRUE;
exit;
end;
end;
// else
Result := FALSE;
end;
end.
我希望我理解了你的问题,这对你有帮助。