zoukankan      html  css  js  c++  java
  • Dephi泛型

    TArray TEnumerator(抽象) TEnumerable(抽象)
    实际使用:TList TQueue TStack TPair TDictionary ,内部都包含 TValueEnumerator
    碰到对象:TObjectList TObjectQueue TObjectStack TObjectDictionary
    另外haiy:TThreadedQueue

    比如以前Delphi没有integer list,用泛型,我们可以这样声明:

    var
    list: TList<Integer>;
    i:integer;
    begin
    list := TList<Integer>.Create;
    list.Add(1);
    list.Add(2);
    list.Add(3);
    list.Items[2] := 8;

    for I := 0 to List.Count-1 do
    ShowMessage(IntToStr(List.Items[i]));

    list.Free;
    end;

    TDictionary类是一个name,value容器,内部是哈希索引,所以对于数据查找非常高效,如下面的代码:

    var
    Dict: TDictionary<string, string>;
    begin
    Dict := TDictionary<string, string>.Create;
    Dict.Add('key1', 'value1');
    Dict.Add('key2', 'value2');
    if not Dict.ContainsKey('key3') then
    Dict.Add('key3','value3');
    Dict.Free;
    end;


    上面的代码中name和value都是string类型,实际应用中可以用其它的类型比如integer,double之类
    因为Object Pascal没有垃圾收集,所以对应的每种泛型类都有一个对应引用类型实现,比如TObjectList,TObjectDictionary,这些类实现中, 当删除元素时会自动帮你释放对象。
    上面的TList和TDictionary在Generics.Collections单元,有兴趣可以研究一下代码。除了已有的泛型类之外,你可以编写自己的泛型类,感兴趣的朋友可以google相关文章。

    几本参考书:

    http://www.cnblogs.com/del/archive/2008/08/15/1268786.html

    http://read.pudn.com/downloads161/ebook/731442/delphi-generics.pdf

    http://www.jcolibri.com/articles/prog_objet_composants/delphi_generics/delphi_generics.html

    http://www.danysoft.com/free/using-new-delphi-coding-styles-and-architectures-marco-cantu.pdf

    http://docwiki.embarcadero.com/CodeExamples/XE5/en/Generics_Collections_TList_(Delphi)

    http://www.felix-colibri.com/papers/oop_components/delphi_generics_tutorial/delphi_generics_tutorial.html

  • 相关阅读:
    Linux下链接数据库图形化工具
    基于深度学习的中文语音识别系统框架(pluse)
    Centos配置深度学习开发环境
    aishell数据处理为thchs30格式
    GRU-CTC中文语音识别
    深度学习知识树,别处传过来,用于自己知识整理。
    kaldi HMM-GMM全部训练脚本分解
    使用深度学习来破解 captcha 验证码(转)
    kaldi
    神经网络最优化方法
  • 原文地址:https://www.cnblogs.com/findumars/p/3541193.html
Copyright © 2011-2022 走看看