DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: xiao2024
今日帖子: 15
在线用户: 17
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 tuesdays (Tuesday) ▲▲▲▲△ -
普通会员
2022/5/13 9:22:22
标题:
多次LoadFromStream 失败? 浏览:1147
加入我的收藏
楼主: 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最强. 写自己的代码, 让别人去运行.
作者:
男 wang_80919 (Flying Wang) ★☆☆☆☆ -
普通会员
2022/5/13 10:03:59
1楼: 好好学习 OOP 基础。雇个翻译。
翻译一下 Abstract 在 计算机词典里的含义。
----------------------------------------------
(C)(P)Flying Wang
作者:
男 roadrunner (roadrunner) ★☆☆☆☆ -
盒子活跃会员
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;
----------------------------------------------
-
作者:
男 sxqwhxq (步惊云) ★☆☆☆☆ -
普通会员
2022/5/13 11:57:14
4楼: 好久不见猫大神,尽管大神脾气很差,但本事了得。
----------------------------------------------
-
作者:
男 pcplayer (pcplayer) ★☆☆☆☆ -
普通会员
2022/5/13 18:21:49
5楼: 3楼正解
----------------------------------------------
-
作者:
男 dbyoung (dbyoung) ★☆☆☆☆ -
普通会员
2022/5/13 22:27:02
6楼: 猫大神虽然喜欢“喷”。的确是有些人该被“喷”。
但不代表猫大神生活中脾气不好。4楼措辞不当。该批评。哈哈哈。

猫大神的确好久不见,有些想念(俺性取向是没有问题的)。
偶尔冒冒也不错,别消失了就可以了。
----------------------------------------------
武汉天气不好
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
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!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
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!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
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!RAD 11.3
作者:
男 wk_knife (wk_knife) ★☆☆☆☆ -
盒子活跃会员
2022/5/14 12:13:16
11楼: 楼主真得学过python么?
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行62.5毫秒 RSS