我想创建一个
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | interface uses Generics.Collections; type TObjectBase = class public procedure SomeBaseFunction; end; TObjectBaseList<T: TObjectBase> = class(TObjectList< T >) public procedure SomeOtherBaseFunction; end; TIndexedObject = class(TObjectBase) protected FIndex: Integer; public property Index: Integer read FIndex write FIndex; end; TIndexedObjectList<T: TIndexedObject> = class(TObjectBaseList< T >) private function GetNextAutoIndex: Integer; public function Add(AObject: T): Integer; function ItemByIndex(AIndex: Integer): T; procedure Insert(AIndex: Integer; AObject: T); end; TCatalogueItem = class(TIndexedObject) private FID: integer; public property ID: integer read FId write FId; end; TCatalogueItemList = class(TIndexedObjectList<TCatalogueItem>) public function GetRowById(AId: Integer): Integer; end; implementation uses Math; { TObjectBase } procedure TObjectBase.SomeBaseFunction; begin end; { TObjectBaseList< T > } procedure TObjectBaseList< T >.SomeOtherBaseFunction; begin end; { TIndexedObjectList } function TIndexedObjectList< T >.Add(AObject: T): Integer; begin AObject.Index := GetNextAutoIndex; Result := inherited Add(AObject); end; procedure TIndexedObjectList< T >.Insert(AIndex: Integer; AObject: T); begin AObject.Index := GetNextAutoIndex; inherited Insert(AIndex, AObject); end; function TIndexedObjectList< T >.ItemByIndex(AIndex: Integer): T; var I: Integer; begin Result := Default(T); while (Count > 0) and (I < Count) and (Result = Default(T)) do if Items[I].Index = AIndex then Result := Items[I] else Inc(I); end; function TIndexedObjectList< T >.GetNextAutoIndex: Integer; var I: Integer; begin Result := 0; for I := 0 to Count - 1 do Result := Max(Result, Items[I].Index); Inc(Result); end; { TCatalogueItemList } function TCatalogueItemList.GetRowById(AId: Integer): Integer; var I: Integer; begin Result := -1; for I := 0 to Pred(Self.Count) do if Self.Items[I].Id = AId then begin Result := I; Break; end; end; end. /////// ERROR HAPPENS HERE ////// ???? why is beyond me |
似乎有以下声明:
导致以下编译器错误:
[DCC Error] edGenerics.pas(106): E2010 Incompatible types:
'TCatalogueItem' and 'TIndexedObject'
但是编译器在编译单元的末尾(第 106 行)显示错误,而不是在声明本身上,这对我来说没有任何意义...
基本上我的想法是我有一个从 TObjectList 下降的通用列表,我可以根据需要扩展新功能。对此的任何帮助都会很棒!!!
我应该使用 Delphi 2010 添加。
谢谢。
您的错误在于类型转换,编译器错误是可以的(但它无法在我的 Delphi XE3 中找到正确的文件)。
您的 ItemByIndex 方法已声明:
但是你有这行:
这对于父类
您可能知道,
2 3 | begin Result := TIndexedObject(nil); //did you see the problem now? |
要将结果初始化为 nil 值,可以调用 Default() 伪函数,如下所示:
在 Delphi XE 或更高版本中,该解决方案也是通用的。不是将结果类型转换为固定的
应用泛型类型转换
2 3 | //or Result := T(SomeOtherValue); |
但是,在这种特定情况下,不需要对
它会编译,并希望能像你期望的那样工作。
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll
在我的系统中,我已经定义了STI。Dog继承自Animal,在animals表中有一个type列,其值为"Dog"。现在我想让SpecialDog继承自dog,只是为了在某些特殊情况下稍微修改一下行为。数据还是一样。我需要通过SpecialDog运行的所有查询,以返回数据库中类型为Dog的值。我的问题是因为我有一个type列,rails将WHERE"animals"."type"IN('SpecialDog')附加到我的查询中,所以我不能获取原始的Dog条目。所以我想要的是以某种方式覆盖rails在通过SpecialDog访问数据库时使用的值,使其表现得像Dog。有没有办法覆盖用于类型
我在一个我想在formtasticGem中覆盖的方法中找到了这个。该方法如下所示:defto_htmlinput_wrappingdohidden_field_html是什么意思?在第三行做什么?我知道它对数组有什么作用,但在这里我不知道。 最佳答案 你可以这样读:hidden_field_htmllabel_with_nested_checkbox是连接到hidden_field_html末尾的参数-为了“清晰”,他们将其分成两行 关于ruby-on-rails-没有参数的`
我已经看到了一些其他的问题,尝试了他们的建议,但没有一个对我有用。我已经使用Rails大约一年了,刚刚开始一个新的Rails项目,突然遇到了问题。我卸载并尝试重新安装所有Ruby和Rails。Ruby很好,但Rails不行。当我输入railss时,我得到了can'tfindgemrailties。我当前的Ruby版本是ruby2.2.2p95(2015-04-13修订版50295)[x86_64-darwin15],尽管我一直在尝试通过rbenv设置ruby2.3.0。如果我尝试rails-v查看我正在运行的版本,我会得到同样的错误。我使用的是MacOSXElCapitan版本10
考虑一下:现在这些情况:#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2#output:http://domain.com/?foo=1&bar=2我需要用其他字符串输出URL。我如何保证&符号不会被转义?由于我无法控制的原因,我无法发送&。求助!把我的头发拉到这里:\编辑:为了澄清,我实际上有一个像这样的数组:@images=[{:id=>"fooid",:url=>"http://
我正在处理http://prepwork.appacademy.io/mini-curriculum/array/中概述的数组问题我正在尝试创建函数my_transpose,它接受一个矩阵并返回其转置。我对写入二维数组感到很困惑!这是一个代码片段,突出了我的困惑。rows=[[0,1,2],[3,4,5],[6,7,8]]columns=Array.new(3,Array.new(3))putscolumns.to_s#Outputisa3x3arrayfilledwithnilcolumns[0][0]=0putscolumns.to_s#Outputis[[0,nil,nil],[
考虑这个,它工作正常::>.to_proc.curry(2)[9][8]#=>true,because9>8然而,即使>是一个二元运算符,如果没有指定的元数,上面的代码将无法工作::>.to_proc.curry[9][8]#=>ArgumentError:wrongnumberofarguments(0for1)为什么两者不等价?注意:我特别想用提供的一个参数创建中间柯里化(Currying)函数,然后然后调用然后用第二个参数调用它。 最佳答案 curry必须知道传入的过程的数量,对吧?:-1来自arity的负值令人困惑,但基本上
所以我只是对此感到好奇:DataMapper为其模型使用混合classPostincludeDataMapper::Resource虽然active-record使用继承classPost有谁知道为什么DataMapper选择这样做(或者为什么AR选择不这样做)? 最佳答案 它允许您从另一个不是DM类的类继承。它还允许动态地将DM功能添加到类中。这是我正在处理的模块中的类方法:defdatamapper_classklass=self.dupklass.send(:include,DataMapper::Resource)klass