Delphi Pascal XE4编译器错误?
发布时间:2020-12-15 09:42:13 所属栏目:大数据 来源:网络整理
导读:我想知道我是否找到了Embarcadero编译器错误… 问题看起来与泛型有关. 这是我的源代码 unit u_DateCount;interfaceuses SysUtils,u_JavaScriptable ;type TDateCount = class (TJavaScriptable) strict private public NoOfSamples : Integer; TheDate : TDa
我想知道我是否找到了Embarcadero编译器错误…
问题看起来与泛型有关. 这是我的源代码 unit u_DateCount; interface uses SysUtils,u_JavaScriptable ; type TDateCount = class (TJavaScriptable) strict private public NoOfSamples : Integer; TheDate : TDate; function ToString():String; override; end; implementation function TDateCount.ToString():String; var myYear,myMonth,myDay : Word; begin DecodeDate(TheDate,myYear,myDay); Result := Format('[new Date(%d,%d,0),%d]',[myYear,NoOfSamples]); end; end. unit u_Javascriptable; interface type TJavaScriptable = class strict private public function ToString:String; override; end; implementation function TJavaScriptable.ToString:String; begin Result := ''; end; end. unit u_LineChart; interface uses System.IOUtils,SysUtils,System.Generics.Collections,u_JavaScriptable ; type TLineChart<RecordType : TJavaScriptable> = class strict private Template : String; function ConvertRecordsToString():String; public Records : TList<RecordType>; function ToString():String; constructor Create(templatePath : String); destructor Destroy(); override; end; implementation function TLineChart<RecordType>.ConvertRecordsToString():String; var I: Integer; begin //Open brackets Result := '[ '; //The first record if Records.Count > 0 then begin Result := Result + Records[0].ToString(); end; //Loop over records for I := 1 to Records.Count - 1 do begin Result := Result + ',' + Records[I].ToString(); end; //Close bracket Result := Result + ' ]'; end; function TLineChart<RecordType>.ToString():String; begin Result := Format(Template,[ConvertRecordsToString()]); end; constructor TLineChart<RecordType>.Create(templatePath : String); begin inherited Create(); Template := TFile.ReadAllText(templatePath); Records := TList<RecordType>.Create(); end; destructor TLineChart<RecordType>.Destroy(); var I: Integer; begin if Assigned(Records) then begin for I := 0 to Records.Count - 1 do begin Records[I].Destroy(); end; Records.Clear(); Records.Destroy(); Records := nil; end; inherited; end; end. 最后是主程序 program Project4; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils,u_Javascriptable in 'u_Javascriptable.pas',u_LineChart in 'u_LineChart.pas',u_DateCount in 'u_DateCount.pas'; var lineChart : TLineChart<TDateCount>; begin lineChart := TLineChart<TDateCount>.Create('linechart.html'); try except on E: Exception do Writeln(E.ClassName,': ',E.Message); end; end. 我尝试编译时得到的错误消息是
通常当我看到类似于此的错误消息时,我可以通过关闭embarcadero IDE并重新启动它来修复它.然而,这次似乎没有用. 解决方法
问题在于TLineChart< RecordType> .Destroy()的实现.
更改记录[I] .Destroy();记录[I] .Free();它的工作原理. 永远不要直接调用Destroy.使用免费.虽然它不应该导致编译器错误,但无论如何它都是错误的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |