Tstrings类的实例是怎么创建的

jumphigh 2000-08-15 03:35:00
var
st1:tstrings;
begin
下面怎么办
我用
st1:=tstrings.create;或直接st1.create都不行呀
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Penn 2000-08-15
  • 打赏
  • 举报
回复
TStrings是抽象的基础类,不能用来生成实例,生成实例要用TStringList.
jumphigh 2000-08-15
  • 打赏
  • 举报
回复
为什么不能用strings
能告诉我原因吗
alin 2000-08-15
  • 打赏
  • 举报
回复
var
st1:tstringlist;
begin
st1:=tstringlist.Create;
end;
内联函数(Inlining) D7中的inline关键字作为保留字并不会对编译器产生实际作用,在2009中此关键字起到内嵌到代码中起到实际作用。语法如下: function foo: Integer; inline; 内部函数/过程也可以使用,但在D2009测试版中,方法的内部函数使用inline后不认Self指针;的子过程/子函数,也可以使用inline关键字,但没有实际效果,且虚方法/继承方法(virtual/override)不能使用。 重载运算符(Operator Overloading) 可以重载部分运算符,如+、-、型转换等,在D2006只支持到record,但从2007开始支持到Class,以下示例修改自官网: TMyClass = class // Addition of two operands of type TMyClass class operator Add(a, b: TMyClass): TMyClass; // Subtraction of type TMyClass class operator Subtract(a, b: TMyClass): TMyclass; // Implicit conversion of an Integer to type TMyClass class operator Implicit(a: Integer): TMyClass; // Implicit conversion of TMyClass to Integer class operator Implicit(a: TMyClass): Integer; // Explicit conversion of a Double to TMyClass class operator Explicit(a: Double): TMyClass; end; class operator TMyClass.Add(a, b: TMyClass): TMyClass; begin //... end; var x, y: TMyClass begin x := 12; // Implicit conversion from an Integer y := x + x; // Calls TMyClass.Add(a, b: TMyClass): TMyClass end; 助手(Class Helpers) Helper是对原Class的扩展,是我们在不修改原的基础上增加方法,并加入原的空间中。在Delphi中,对对象的调用实际上采用了两个步骤,首先是把对象地址放入eax寄存器中,然后call方法,所以如果不使用继承增加数据的话,用父调用继承的方法是没问题的,所以其实这样的方法在D7中也可以使用,但却很麻烦。所以Class Helper起到的就是这个作用,在Class Helper中可以增加的就是与实例无关的内容,所以任何需要增加实例Size的活VMT的功能不能声明,例如变量、虚方法等,但只占用空间的没关系,如class var。在应用上我们可以通过这种方法方便的给VCL一控件加上某个属性。 TFoo = class helper for TControl private function GetA: Integer; public class var X: Integer; procedure MSG(var Message: TMessage); message WM_MYMESSAGE; procedure ProcFoo; property A: Integer read GetA; end; // ... procedure TForm1.Foofoo; begin ProcFoo; // TControl -> TWinControl -> TScrollingWinControl-> TCustomForm -> TForm -> TFrom1: Call TFoo.ProcFoo end; strict关键字(Keyword “strict”) 众所周知,在Delphi中,的private和protected域中的变量可以被同一单元中可以自由的被访问(Delphi的没有“友元”的概念,但同一个unit中可以说自动友元化了),而并非是真正的私有或只能被继承访问。而strict关键字的作用就是使该内容变成严格OO意义上的private/protected作用域,这点没有什么多说的。语法: strict private // Blah... strict protected // Blah... 结构方法(Records with Methods) 也没什么特别的,就是和class差不多,就一个不用创建和销毁、不能继承、没有作用域之,很容易掌握,所以这里就不多介绍了。但是很有意思的是带参数的constructor可以通过编译,可能是为了初始化的方便吧。 抽象和固实(Abstract and Sealed Classes) 这两个概念在OO中也并不陌生,抽象是不应该创建实例的(但D2006起的编译器就不给检查,连个Warning都没有,这还有啥用啊 -.- ),而固实是不能被继承的。语法: TAnAbstractClass = class abstract // or (TParentClass) // Blah... end; TASealedClass = class sealed(TAnAbstractClass) // or empty // Blah... end; 常量、变量、属性与静态方法(Class const/var/property and Static Class Methods) 老的Delphi中只提供了方法,而没有提供变量、常量和属性,这真的是很不方便。这里先区分一下我所使用的(Class)和对象(Object)即实例(Instance of Class)。当在Delphi中声明一个的时候,这个是有实际地址的,该地址记录了许多的相关信息,比如实例的Size啊、虚方法信息啊一堆东西,而创建一个对象的时候则把实例化,在堆(Heap)中分配一块地址,包括内部数据和VMT之的东西。在调用实例的时候,首先要知道对象地址,然后才能访问内部变量和调用方法时使用Self指针即实例地址;而在调用方法的时候,eax中的并不是实例的地址而是的地址,然后再call方法,这时的Self指针并非实例地址而是地址。所以对于每一个和继承来说,包括它和它的继承的所有实例变量、常量都是同一个,这样就存在了一个唯一的可供使用的变量或常量,方便同步并且不需要使用较多的内存(可以参考C#中的,不过C#中不允许从实例直接访问变量、常量、方法)。而静态方法则是在使用这个方法的时候不传入class地址,也就是说没有Self指针,这样的方法的访问开销要小于普通的方法;这自然也就意味着,该方法不能被继承(不能virtual/override)。另外,属性的get/set方法必须使用静态方法。 TFooClass = class private class procedure SetFoo(const Value: Integer); static; // A Static Class Method protected class var FX : Integer; // class var public const FC: Integer = 10; // class const class procedure VirtualProc; virtual; class property X: Integer read FX write FX; // class property class property Foo: Integer read FC write SetFoo; end; 内部型与嵌套(Class Types and Nested Classes) 可以说现在的Class的域几乎相当于原来的整个unit,以前不能放里面的元素现在都可以放里面了,这个也没什么好多说的,试验一下就很容易明白了。 终方法(Final Methods) 这个也是建立在虚方法的基础上的,在override后使用final关键字,则表示该虚方法不能再被子继承下去了。 TAClass = class public procedure Foo; virtual; end; TFinalMethodClass = class(TAClass) public procedure Test; override; final; // A Final Method end; For-in循环(For-in Loop) 这个应该是受.Net影响吧,支持遍历一个数组或提供了GetEnumerator函数的。GetEnumerator要求返回一个实例,该包含有Current属性和MoveNext方法。 procedure Foo(List: TStrings); i : Integer; lst : array[0..100]of Integer; s : string; begin for i in lst do ; for s in List do ; // Support of TStrings.GetEnumerator end;
OTL介绍: OTL 是 Oracle, Odbc and DB2-CLI Template Library 的缩写,是一个C++操控关系数据库的模板库,最新版本4.0.104,参见http://otl.sourceforge.net/ 优点:a. 跨平台 b. 运行效率高,与C语言直接调用API相当 c. 开发效率高,起码比ADO.net使用起来更简单,更简洁 d. 部署容易,不需要ADO组件,不需要.net framework 等 缺点: a. 只有C++才可以使用她 b. 说明以及范例不足(已附带了686个实例) This document describes the Oracle, ODBC and DB2-CLI Template Library, Version 4.0 (OTL 4.0). OTL 4.0 is a C++ library based on C++ templates. OTL 4.0 was designed as a combination of a C++ template framework and OTL-adapters. The framework is a generic implementation of the concept of OTL streams. The OTL-adapters are thin wrappers around the database APIs and are used as class type parameters to be passed into the template framework. OTL 4.0 covers the functionality of a full featured C++ database access library with just a handful of classes: otl_stream, otl_connect, otl_exception, otl_long_string, and several template PL/SQL (Oracle) table container classes, generated from the template framework and the OTL-adapters. The OTL code gets expanded into direct database API function calls, so it provides very decent performance (only 10-15% overhead, compared with the database APIs themselves) and reliability in multi-processor environments as well as traditional batch programs. OTL 4.0, being a template library, is highly portable since it is self-sufficient and compact enough. OTL 4.0 is ANSI C++ compliant (ANSI C++ typecasts, clean templatized code, etc.), tightly integrated with the Standard Template Library (STL) via STL-compliant stream iterators, and natively supports the STL std::string's in otl_stream's. OTL integrates with ACE, and supports ACE_TStrings. OTL 4.0 supports all versions of Oracle starting with 7.3 (natively via the corresponding version of the OCI), DB2 UDB LUW / zOS (natively via DB2 CLI), MS SQL Server 2005/2008 (natively via SNAC), Informix 11 (natively via Informix CLI), TimesTen 7 and higher (natively TimesTen CLI), SAP-MAX/DB (natively via SAP/DB CLI), ODBC 3.x as well as ODBC 2.5 (for legacy applications) compliant data sources in MS Windows, Linux/Unix/Mac OS X (via unixodbc and iODBC driver managers): Sybase, MySQL, PostgreSQL, EnterpriseDB, SQLite, MS ACCESS, Firebird, etc. The list of supported database back ends is growing. In the last few years, transition from the 32-bit platforms to the 64-bit platforms has occurred: OTL's source code is portable, and it support both 32-bit and 64-bit C++ compilers. Also, OTL supports UTF-8 and UTF-16 for Oracle, and UTF-16 for the rest of the database types, when the underlying database API / ODBC driver supports it.

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧