return value loadfromfile()

TeeChart for ActiveX, COM and ASP
Post Reply
Jack@007
Newbie
Newbie
Posts: 4
Joined: Fri Mar 21, 2014 12:00 am

return value loadfromfile()

Post by Jack@007 » Sun Sep 07, 2014 3:12 pm

Using the latest AX version.

I'm using the import method loadfromfile() and want to check if the loading went without problems. Looking via the debugger it shows that this method always returns NIL no matter if the was loaded successfully, wasn't found, was corrupt etc..
Shouldn't there be a return value like a Boolean or a pointer (like normal filehandling) to check this.

TIA,

Jack

Yeray
Site Admin
Site Admin
Posts: 9622
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: return value loadfromfile()

Post by Yeray » Mon Sep 08, 2014 12:10 pm

Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Jack007
Newbie
Newbie
Posts: 1
Joined: Thu Feb 26, 2015 12:00 am

Re: return value loadfromfile()

Post by Jack007 » Tue Apr 21, 2015 5:42 pm

Hi Yeray,

I posted this request some time ago.
In the tracker I see that at first:
Status CONFIRMED RESOLVED

but some time later:
Resolution --- WONTFIX

Does this means it won't get changed (AX2015 gives no returnvalue)? Why?

TIA,
Jack

Yeray
Site Admin
Site Admin
Posts: 9622
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: return value loadfromfile()

Post by Yeray » Wed Apr 22, 2015 7:36 am

Hello Jack,
Jack007 wrote:I posted this request some time ago.
In the tracker I see that at first:
Status CONFIRMED RESOLVED

but some time later:
Resolution --- WONTFIX
At the same time, not later.
First of all note TeeChart ActiveX is a wrapper from TeeChart VCL so some issues in the ActiveX version depend on the VCL version.
That's why I created both a VCL and an ActiveX ticket, B911 and B912 on 2014-09-08 with a "Blocks"/"Depends on" relation between them.
David closed B911 on 2014-09-12 setting "Status" field to "Resolved" and "Resolution" field to "Won't Fix", both fields at the same time. He also wrote a comment explaining the reason:
david wrote:Returning a Boolean will not indicate the exact cause.
Correct behaviour is to raise an exception, being the exception class and properties the info about the problem.

See for example Classes.pas TStrings LoadFromFile:

Code: Select all

procedure TStrings.LoadFromFile(const FileName: string);
var
  Stream: TStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  try
    LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;
OurTTeeSeriesSourceFile.LoadFromFile, TImportChart.LoadFromFile and TeeStore.pas unit LoadChartFromFile, all use the RTL default TFileStream classes.

A custom function can always "eat" the exception and return a boolean, if desired:

Code: Select all

uses
  TeeStore;

function Load(const AChart:TCustomChart; const AFile:String):Boolean;
begin
  try
    LoadChartFromFile(AChart,AFile);
    result:=True;
  except
    on Exception do
    begin
      // EAT
      result:=False;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if Load(Chart1,'test.tee') then
     Caption:='OK'
  else
     Caption:='BAD';
end;
However, this is not recommended. Exceptions must surface-up to callers.
Jack007 wrote:Does this means it won't get changed (AX2015 gives no returnvalue)? Why?
I'm afraid yes. And the reason is the one David explained there and I copied above.
Of course don't hesitate to let us know if you find it's not accurate enough or if it doesn't fit your needs.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply