这个家伙糟厉害 函数 这样写!有谁见过这样写的吗?

function GetPartFilter(AID: string): string;  //单元头部分还定义了
var
  querytemp: TOceanQuery;
  s: string;
  lOwnerids: TStringList;
  procedure GetOwnerids(AID: string);  //压根 都不用定义 都可以???
  var lQuery: TOceanQuery;
  begin
    lQuery := TOceanQuery.Create(nil);
    try
      lQuery.Close;
      lQuery.SQL.Text := 'select ID from PartInfo where Ownerid=' + QuotedStr(AID) + ' and ID<>' + QuotedStr(AID) + ' and ImageIndex=0';
      lQuery.Open;
      while not lQuery.Eof do
      begin
        lOwnerids.Add(lQuery.FieldByName('ID').AsString);
        GetOwnerids(lQuery.FieldByName('ID').AsString);
        lQuery.Next;
      end;
    finally
      lQuery.Free;
    end;
  end;
var I: Integer;
begin
  Result := '';
  querytemp := TOceanQuery.Create(nil);
  lOwnerids := TStringList.Create;
  try
    querytemp.Close;
    querytemp.SQL.Text := 'select ID,ImageIndex from partinfo where ID=''' + AID + '''';
    querytemp.Open;
    if querytemp.IsEmpty then Exit;
    if querytemp.FieldByName('ImageIndex').AsInteger <> 0 then
    begin
      Result := 'ID=' + QuotedStr(AID);
      Exit;
    end;
    lOwnerids.Add(querytemp.FieldByName('ID').AsString);
    GetOwnerids(querytemp.FieldByName('ID').AsString);
    for I := 0 to lOwnerids.Count - 1 do
    begin
      if Result = '' then
        Result := 'Ownerid in (' + QuotedStr(lOwnerids[I])
      else
        Result := Result + ',' + QuotedStr(lOwnerids[I]);
    end;
    if Result <> '' then
      Result := Result + ')';
  finally
    querytemp.Free;
    lOwnerids.Free;
  end;
end;

导航