SigmaSciences / opaR

Port of R.NET to Embarcadero Delphi
20 stars 11 forks source link

Manualy Set R_HOME Cause Error in loading DLL...etc #6

Open crystalxp opened 7 years ago

crystalxp commented 7 years ago

Thanks for your good library...this lib is very cool. i want to report some bugs(maybe?...) When Manualy Set R_HOME in Windows setting , then program can't load dll successful...

and I think use {$IFDEF Win64} in lib better than {$IFNDEF CPUX64} and TOSVersion.Architecture to get right r.dll for app (win32 app load x32 dll, and win64 app load x64 dll)

rlsdevine commented 7 years ago

Thanks for your feedback - I'm hoping to get back onto this in a few weeks and will take a look at your report.

crystalxp commented 7 years ago

helllo,I finally find why this bug happend: because of the .FindRPaths has a logical bug:

the fixed function is below:

// ------------------------------------------------------------------------------ class procedure TNativeUtility.FindRPaths(var path: string; var homeDir: string; logger: TStringList); var printPath: string; printHome: string; begin if path = '' then printPath := 'null' else printPath := path; if homeDir = '' then printHome := 'null' else printHome := homeDir; logger.Add(Format('Caller provided path = "%s", homeDir = "%s"', [printPath, printHome]));

if homeDir = '' then begin homeDir := GetEnvironmentVariable('R_HOME'); if homeDir = '' then printHome := 'null' else printHome := homeDir; logger.Add(Format('opaR looked for preset R_HOME env. var. and found: "%s"', [printHome])); end;

if homeDir = '' then begin homeDir := FindRHome(path, logger); if homeDir = '' then printHome := 'null' else printHome := homeDir; logger.Add (Format('opaR looked for platform-specific way (e.g. win registry) and found: "%s"', [printHome])); end;

if homeDir = '' then logger.Add ('Error: R_HOME was not provided and a suitable path could not be found by opaR');

if not(homeDir = '') then begin if path = '' then begin path := FindRPath(homeDir); if path = '' then printPath := 'null' else printPath := path; logger.Add (Format('opaR trying to find rPath based on rHome; Deduced: "%s"', [printPath])); end;

if path = '' then
begin
  path := FindRPath;
  if path = '' then
    printPath := 'null'
  else
    printPath := path;
  logger.Add
    (Format('opaR trying to find rPath independently of rHome; Deduced: "%s"',
    [printPath]));
end;

end else begin homeDir := FindRHome(path); if homeDir = '' then printHome := 'null' else printHome := homeDir; logger.Add(Format('opaR trying to find rHome based on rPath; Deduced: "%s"', [printHome])); end; end;

crystalxp commented 7 years ago

and I find another bug in win64 app when excute some case, and i post that bug as another issue. please check it , thanks.