导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
2022/5/13 9:22:22
标题:
多次LoadFromStream 失败?
浏览:426
加入我的收藏
楼主:
First chance exception at $7674F162. Exception class EAbstractError with message 'Abstract Error'. Process Project5.exe (1692) var fileStream: TFileStream; Tstr:TStrings; begin fileStream := TFileStream.Create('D:\delphi\a.txt',fmOpenRead); // 第一次读取 edt1.Lines.LoadFromStream( fileStream ); // 为什么不能再来一次 LoadFromStream ?. Tstr := TStrings.Create; try fileStream.Position := 0; Tstr.LoadFromStream(fileStream); edt1.Lines.AddStrings(Tstr); finally FreeAndNil(Tstr); end; FreeAndNil(fileStream);
----------------------------------------------
delphi界写python最强, python界写delphi最强. 写自己的代码, 让别人去运行.
作者:
2022/5/13 10:03:59
1楼:
好好学习 OOP 基础。雇个翻译。 翻译一下 Abstract 在 计算机词典里的含义。
----------------------------------------------
(C)(P)Flying Wang
作者:
2022/5/13 10:28:24
2楼:
这是历史遗留bug 在Classes单元里,TStrings的定义为: TStrings = class(TPersistent) 而实际上, 正确的定义应该是: TStrings = class abstract(TPersistent) 或许是为了照顾某些利用了这个bug的遗留代码,又或者是觉得不会有程序员真会掉这个坑里面,又或者是认为会犯这种错的程序员坑死活该,总之这个问题官方一直没打算改。
----------------------------------------------
-
作者:
aket (aket)
★☆☆☆☆
-
盒子活跃会员
2022/5/13 10:30:44
3楼:
TStrings抽象类不能实例化,用派生类去实例化就可以了 Tstr := TStringList.Create;
----------------------------------------------
-
作者:
2022/5/13 11:57:14
4楼:
好久不见猫大神,尽管大神脾气很差,但本事了得。
----------------------------------------------
-
作者:
2022/5/13 18:21:49
5楼:
3楼正解
----------------------------------------------
-
作者:
2022/5/13 22:27:02
6楼:
猫大神虽然喜欢“喷”。的确是有些人该被“喷”。 但不代表猫大神生活中脾气不好。4楼措辞不当。该批评。哈哈哈。 猫大神的确好久不见,有些想念(俺性取向是没有问题的)。 偶尔冒冒也不错,别消失了就可以了。
----------------------------------------------
武汉天气不好
作者:
2022/5/13 22:53:14
7楼:
Really, IS NOT A BUG, but rather, a deliberate action to be observed by the programmer. THERE IS NOTHING TO CHANGE IN THE DEFINITION OF THIS TYPE OF CLASS! All base classes must/can, in fact, define procedures that must/can be overridden by sub-classes. In this way, the 4 pillars of Object Oriented Programming will be respected. And he who neglects them will pay the price of little knowledge.Why dont use "abstract CLASSes (or with abstract methods)" like TStrings directly? -- Why many methods in this classes CAN "NOT BE" IMPLEMENTED , in fact! Ex. for TStrings class, in "System.Classes.pas": the error above happens when the procedure "CLEAR" is invoked, but this procedure is not implemented in real class (TStrings)... then, the "access violation" occurrs. System.Classes.pas. ... TStrings = class(TPersistent) .... line 731: procedure Clear; virtual; abstract; ... line 7230, ... Clear; // <--- this cause the error because it is "Abstract" in this class. ... NOT .LOADFROMSTREAM(...)
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!
作者:
2022/5/13 23:08:11
8楼:
for better understanding, "Abstract" can mean "draft, resume, ..." ... so a base class is just a "draft" of future real classes for use, in fact. And. "when" a class dont will receive any changes in future (EXTENDED in your SUB-CLASSES, of course), it will be defined like "SEALED" https://docwiki.embarcadero.com/RADStudio/Sydney/en/E2540_Cannot_seal_abstract_type_%27%25s%27_(Delphi) This occurs when declaring an abstract type as sealed. ----> A sealed class cannot be extended through inheritance. program E2540; {E2540 Cannot seal abstract type '%s'} {$APPTYPE CONSOLE} uses SysUtils, classes; type TMyClass = class sealed procedure setArea; Virtual; Abstract; //E2540 end; begin end.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!
作者:
2022/5/13 23:24:28
9楼:
{E2540 Cannot seal abstract type '%s'} type txxx = class sealed end; tzzz = class (txxx) // <----- SEALED IS NOT EXTENSIBLE!!! DONT COMPILE! end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!
作者:
2022/5/14 12:13:16
11楼:
楼主真得学过python么?
----------------------------------------------
-