TWebTableControl.LoadFromCSVAsync is missing?

This method is documented in the User Guide, but produces "Undeclared identifier" error upon entering and building. Is some additional unit needed in Uses?

Are you sure you use v2.1.0.3 as this compiles fine here?

I am using version 2.1.0.1, installed only last week! If this feature was added more recently I'd expect (a) that it would not be described in the documentation delivered with my version and (b) that there would be a change in more than the least-significant version number.

I will install 2.1.0.3 and report back.

LoadFromCSVAsync was introduced in v2.1.0.0.
You should see it in Core Source\WEBLib.Grids.pas

I installed 2.1.0.3, but something's not right. My copy of WEBLib.Grids.pas does not contain "async" anywhere. Attached is a screenshot of its properties. It appears to be a recent version.

Is this the subfolder “Core Source" as I can't see it from this screenshot.
The v2.1 version should definitely have the Async variants of LoadFromCSV & LoadFromJSON

Sorry, here's the full path: "C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Component Library Source\WEBLib.Grids.pas"

Ok, I told you this look into the “Core Source” subfolder!

The one I showed is what the Uses section pointed to via cntrl-click in the IDE. The other folder's copy does indeed have "async". I suppose that this means that my installation is broken. How to fix it?

The "Core Source" folder contains what is compiled for run-time, so it should compile & work.

Actually, when I ignore the squiggly red lines and click "compile" it fails. Here is the status panel:

And here is the log:

Checking project dependencies...
Compiling CW_EPG_Remote.dproj (Debug, Win32)
CWRmainForm.pas(1): Preprocessor: C:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA\CWRmainForm.pas
CWRmainForm.pas(1): Preprocessor: C:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA\CWRmainForm.pas
Command line: C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Bin\Win32\pas2js.exe C:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA\CW_EPG_Remote.dpr -MDelphi -l -JeJSON -JRnone -Jminclude -O- -Jc -B -viw -vnh -vm026,5024,3021,5023,4501 -Jitms.js -Jirtl.js -FUC:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA\TMSWeb\Debug -vb -vl -dDEBUG -dPAS2JS -dPWA -dWEBLIB "-FuC:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Core Source;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Core Source\RTL;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14" "-FiC:\Users\tpete\Documents\Embarcadero\Studio\Projects\CW_RemotePWA;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Core Source;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14\Core Source\RTL;C:\Users\tpete\AppData\Local\tmssoftware\registered\TMS WEB Core RSXE14"
Pas2JS Compiler version 2.3.1 [2023/03/06] for Win32 i386 / TMS WEB Core version v2.1.0.3
[Error] CWRmainForm.pas(67): async function expected, but Result:TJSPromise found
Error during compilation
[Fatal Error] Error during compilation

Do you mark the method from where you call the async method for [async]?

Please see:

Yes, I think so. Here's the Interface type section:

type
  TCWRmainFrm = class(TWebForm)
    WIDBCDS: TWebIndexedDbClientDataset;
    WebPageControl1: TWebPageControl;
    tbEPG: TWebTabSheet;
    tbCaptures: TWebTabSheet;
    tbHistory: TWebTabSheet;
    tbLog: TWebTabSheet;
    tbAbout: TWebTabSheet;
    WebGridPanel1: TWebGridPanel;
    WebTableControl1: TWebTableControl;
    [async] procedure WebFormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

And here's the method:

 procedure TCWRmainFrm.WebFormCreate(Sender: TObject);
var
  URL: string;
  i: integer;
  req: TJSXMLHttpRequest;
begin
  URL := application.EXEName;
//  ShowMessage(URL);
  i := pos('://', URL) + 3;
  URL := copy(URL, i, pos(':', URL, i) - i);
//  ShowMessage(URL);
  URL := 'http://' + URL + ':8181/getdbfile?filename=cwr_epg.csv';
  ShowMessage('Will request EPG load via: ' + URL);
  req := await(
  WebTableControl1.LoadFromCSVAsync(URL, ',', True)
  );
end;

So, I replaced the Component Library Source folder's WebLib.Grids.pas with the one from Core Source and that caused the red squiggly underline and associated Structure error to disappear, but the compiler error was the same.

The correct way to write this is:

req := await(TJSXMLHttpRequest, WebTableControl1.LoadFromCSVAsync('', ',', True));

Ah. Thanks! Where are the red squigglies when I need them?

BTW, it does compile now, but there is still a complaint in the Structure panel saying that "There is no overloaded version of 'Await' that...."

design-time/editor uses the DCC compiler to give this information. DCC does not know the await() construct as it is unique to the pas2js compiler for compiling to web.

If you are interested in getting rid of all the "squigglies" you could try something like the following. Note that the complexity can be reduced somewhat by adding the missing function directly into the Component Library Source Unit, but then the problem is if TMS haven't added the missing stub in the meantime then the function will be overwritten when you update. The beauty of creating the helper is that you are in control of the unit and it is safe during updates.

unit Unit1;

interface

uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, DB, Vcl.StdCtrls, WEBLib.StdCtrls, Vcl.Controls,
WEBLib.Grids;

type
TForm1 = class(TWebForm)
WebTableControl1: TWebTableControl;
WebButton1: TWebButton;
procedure WebButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
[async] procedure DoSomething;
end;

TWebTableControlHelper = class helper for TWebTableControl
function LoadFromCSVAsync(const AURL: string; Delimiter: char = ';'; LoadFixed: boolean = false): TJSPromise;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DoSomething;
var
req : TJSXMLHttpRequest;
begin
req := TAwait.ExecP(WebTableControl1.LoadFromCSVAsync('Test.csv', ',', False));
end;

procedure TForm1.WebButton1Click(Sender: TObject);
begin
DoSomething;
end;

{ TWebTableControlHelper }

function TWebTableControlHelper.LoadFromCSVAsync(const AURL: string;
Delimiter: char; LoadFixed: boolean): TJSPromise;
begin
//
inherited;
end;

end.

1 Like

Thanks, @Eiszele_Daniel . I agree, that is a safer approach than altering the Component Library Source folder and it does work (for units where the helper is added anyway).