Page 1 of 1

return value loadfromfile()

Posted: Sun Sep 07, 2014 3:12 pm
by 16668787
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

Re: return value loadfromfile()

Posted: Mon Sep 08, 2014 12:10 pm
by yeray

Re: return value loadfromfile()

Posted: Tue Apr 21, 2015 5:42 pm
by 16671577
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

Re: return value loadfromfile()

Posted: Wed Apr 22, 2015 7:36 am
by yeray
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.