- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好吧,这变得很傻了......
这是第二次(第一次是在 30 分钟前,在一个获取目录树的函数上)我曾经看到错误“抽象错误”,真的不知道为什么会发生。
我有这个功能,列出所有的硬盘:
function TForm2.GetDriveList:TStringList;
var
s:string;
i:integer;
DriveStr:array[1..255] of char;
t:integer;
begin
GetLogicalDriveStrings(255,@DriveStr);
result:=TStringList.create;
i:=1;
repeat
s:='';
while (i<=255) and (DriveStr[i]<>#00) do
begin
s:=s+char(drivestr[i]);
inc(i);
end;
inc(i); {step over #00}
t:=getdrivetype(Pchar(s));
if (length(s)>0) and (t=DRIVE_FIXED)
then result.add(s);
until length(s)=0;
end;
现在,我将 TStringList 更改为 TStrings,但在尝试调用它时出现此抽象错误;
我也试过把它改成过程,因为
procedure TFrom2.GetDriveList(List: TStrings);
从代码中删除结果,并在末尾添加 List.Add(s);
这个(函数到过程)以某种方式解决了我第一个案例中的问题,但没有解决这个问题。
我的问题是:上面的代码有什么问题,为什么不接受 TStrings...?
并且:这些抽象错误到底是什么,如何识别它们,因为它们出现(通过调试检查)在函数/过程的最后,在它基本上已经完成之后?
最佳答案
TStrings
是一个抽象基类。它不能被实例化。它作为具体派生类的公共(public)基类而存在。比如 TStringList
,比如 TMemo
公开的 TStrings
派生类,TListBox
等等。文档说:
TStrings is the base class for objects that represent a list of strings.
Derive a class from TStrings to store and manipulate a list of strings. TStrings contains abstract or, in C++ terminology, pure virtual methods and should not be directly instantiated.
规则说的很清楚。不要实例化 TStrings
。
抽象错误是调用抽象方法时出现的运行时错误。抽象方法是没有实现的虚方法。不能调用抽象方法。这就是为什么不应该实例化抽象类的原因。
如果您不熟悉什么是抽象方法,那么您需要返回文档并复习您的知识。从这里开始:http://docwiki.embarcadero.com/RADStudio/en/Methods#Virtual_and_Dynamic_Methods
关于delphi - 将 TStringList 更改为 TStrings 时出现抽象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27196682/
基本上我有(州,州代码)对,它们是国家的子集[美国] -> [VT] -> 32 所以我正在使用 std::map>但是我在分配州代码时遇到了问题 for(std::map>::const_itera
如何检查 TStrings 中是否存在特定字符串?例如,我有包含大量文本的 TString,我想检查字符串是否为“Hello!”出现在本文中。 “你好!”只是一个示例字符串。它可以是任何东西。字符串可
我有一个从 TFrame 扩展的对象。这包含一个 TCombobox。 我想确保当我的框架被破坏时释放任何关联的对象。然而,当我的析构函数运行时,我可以访问组合框,但它的项目已被清除。 这会做什么?我
我最近发现了这段代码,我一直在尝试修改它,但没有运气。我如何修改代码,以便它不仅接受文件,还接受 TStrings? 只能这样使用 TMultiStringList.LoadFromFile('som
我编写了一个类似 TListBox 的控件(类似于 Doctor Bob's SpeedBox )。 它运行良好,但有一个问题除外:分配给属性 Items 的字符串在启动时不会加载到 TListBox
我需要搜索一大组数据文件。我想查找包含字符串“foo\tbar\tboo”的文件。我试过这个... $ find . -name "foo*dat" -exec grep foo {} \; | le
我在尝试为自己输入一个方便的 tstring 时遇到问题(见下文) #ifndef _NISAMPLECLIENT_H_ #define _NISAMPLECLIENT_H_ #include #i
以下代码有效: var SL: TStrings; begin SL := TStringList.Create; try SL.Add(Format('%s=%s', ['Ale
我有一个文件.\input.txt,如下所示: aaa bbb ccc 如果我使用 TStrings.LoadFromFile 阅读它并使用 TStrings.SaveToFile 将其写回(即使不应
为什么变量声明为 TStrings 并创建为 TStringList? 例如:var sl 被声明为 TStrings 但创建为 TStringList var sl : TStrings; be
在 Delphi XE7 中,我使用 Anders Melander 著名的 DragAndDropSuite。该套件中的 TDropFileTarget 组件将删除的文件作为 TUnicodeStr
好吧,这变得很傻了...... 这是第二次(第一次是在 30 分钟前,在一个获取目录树的函数上)我曾经看到错误“抽象错误”,真的不知道为什么会发生。 我有这个功能,列出所有的硬盘: function
在 Delphi 7 中,我使用 TCheckListBox。我希望它使用 TStringList 而不是 TStrings,因此我可以将重复项设置为 dupIgnore,并将排序设置为 TRUE。
有人可以帮我解释为什么当底层函数中引发异常时 TStrings 会作为“不可访问的值”返回吗? function GetStrings():TStrings; begin result := TS
我正在尝试将 LPTSTR 变量转换为 tstring(即,unicode 应用程序中的 wstring 和 ANSI 中的字符串)。 我如何执行此转换? 我的代码尝试执行转换,但它导致错误:“调试断
Delphi XE在Encoding类中添加了TStrings属性,该属性存储在调用LoadFromFile()时从BOM表读取的编码。 Delphi 2010没有此属性。 我想效仿它。 我为TStr
我有字符串'AAA'+#$0d+#$0a+'BBB'+#$01d+'CCC'。我需要根据 #$1d 字符进行分割,例如: 'AAA'+#$0d+#$0a+'BBB' 'CCC' 我正在使用函数: pr
我在 WCP 1252 编码的头文件中有一个字符串: #define MY_STR "This string has some fancy characters like ©" 我如何使用像 UTF-
我饶有兴趣地阅读了 Nick Hodges 的博客 Why You Should Be Using Interfaces由于我已经爱上了编码中更高级别的接口(interface),因此我决定研究如何将
为什么Memo.Lines使用抽象类TStrings?为什么不使用 TStringList 来代替? 我应该在使用它之前将其转换为 TStringList 吗? 最佳答案 TMemo.Lines、TL
我是一名优秀的程序员,十分优秀!