Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 911 - Return value for LoadFromFile
Summary: Return value for LoadFromFile
Status: RESOLVED WONTFIX
Alias: None
Product: VCL TeeChart
Classification: Unclassified
Component: Export (show other bugs)
Version: 140512
Hardware: PC Windows
: Low enhancement
Target Milestone: ---
Assignee: Steema Issue Manager
URL: http://www.teechart.net/support/viewt...
Keywords:
Depends on:
Blocks: 912
  Show dependency treegraph
 
Reported: 2014-09-08 08:08 EDT by yeray alonso
Modified: 2014-09-12 12:39 EDT (History)
1 user (show)

See Also:
Chart Series: ---
Delphi / C++ Builder RAD IDE Version:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yeray alonso 2014-09-08 08:08:04 EDT
LoadFromFile method could return a Boolean or a pointer (like normal filehandling) to check this.

A customer would like to check if the file was loaded successfully, wasn't found, was corrupt etc..
Comment 1 david berneda 2014-09-12 12:39:09 EDT
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:

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:

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.