Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 14 total
Thread Reading a text file to a string
Thu, Jan 23 2014 6:47 AMPermanent Link

Doc

I'm new in trying EWB. I'm wondering wether it ist possible to read a text file into a string and work with this string. It's a .csv file on the Server. At the moment I can access this file using my Java applet, but it would be nice to do it with EWB, it should be possible in Javascript, but I didn't find a way in EWB.
Thu, Jan 23 2014 10:33 AMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 1/23/2014 6:47 AM, Doc wrote:
> I'm new in trying EWB. I'm wondering wether it ist possible to read a text file into a string and work with this string. It's a .csv file on the Server. At the moment I can access this file using my Java applet, but it would be nice to do it with EWB, it should be possible in Javascript, but I didn't find a way in EWB.

Sure. EWB app/javascript runs on client browser so you'd need your
backend server to provide the file. I assume you're using a web server
already so easiest would be to just get the web server to host the file
and then you can use a server request
(http://www.elevatesoft.com/manual?action=topics&id=ewb1&section=using_server_requests)
to get it using the file url and store in the string (basically
Request.ResponseContent will contain the file content after request).

do you need to save it back after ? if so then you'd need to do bit more
work for that but not much.

Raul

Fri, Jan 24 2014 7:44 AMPermanent Link

Doc

Thank you very much, that looks promising,
but I didn't find a way to use this.
How to assign the return data from this request to a TStringList or TStrings containing the text of my textfile.
Even the example from the help page doesn''t compile:

procedure TMyForm.RequestComplete(Request: TServerRequest);
-> [Error]: There is no function or procedure declaration that matches the RequestComplete declaration
Fri, Jan 24 2014 10:36 AMPermanent Link

Matthew Jones

I used TServerRequest to get data from a REST server, and the content (data
returned) is available in
szResponseText := Request.ResponseContent.Text;


/Matthew Jones/
Fri, Jan 24 2014 12:09 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

Doc wrote:
<<
Thank you very much, that looks promising,
but I didn't find a way to use this.
How to assign the return data from this request to a TStringList or TStrings containing the text of my textfile.
Even the example from the help page doesn''t compile:

procedure TMyForm.RequestComplete(Request: TServerRequest);
-> [Error]: There is no function or procedure declaration that matches the RequestComplete declaration
>>

OK - here is a really quick and basic tutorial on loading the file.

This assumes you're using the EWB IDE and using the built-in webserver. You need to copy the csv file to the output folder in step 3

1. start new visual project
2. put a memo, button, serverrequest and serverrequestqueue on the form
3. might as well save project now and compile it. this should result in the "output" folder under the project - make sure you now copy the cvs file into that folder
4. i renamed my button as ButtonGetFile.
5. double click on button to add Click event and make sure it looks like this (use whatever your file name was - this just loads the file from the same server as EWB app is run from)

procedure TForm1.ButtonGetFileClick(Sender: TObject);
begin                             
  ServerRequest1.URL := 'http://'+ window.location.host+'/mytextfile.csv';
  ServerRequestQueue1.AddRequest(ServerRequest1);
end;

6. you also need to add WebDOM to the uses clause of the unit.

7.then select serverequest and add the OnCompleteHandler. it should look something like this.

procedure TForm1.ServerRequest1Complete(Request: TServerRequest);
begin
  if (Request.StatusCode=200) then
  begin
     Memo1.Text := Request.ResponseContent.Text;
     ShowMessage('File loaded');
  end
  else
     ShowMessage('Failed to load file :' + IntToStr(Request.StatusCode) + '.' + Request.ResponseContent.Text );
end;

8. that's it. Compile and run your project and if everything works you should see the file loaded into the memo

now you should be able to access the file contents in the memo

Raul



Attachments: file_load_ewb.png
Sun, Jan 26 2014 5:19 AMPermanent Link

Doc

Thank you again, that works great.
I also had to enable HTML5 Functionallity.
I think I won't need the ServerRequestQueue, jut a ServerRequest1.Execute would do.


Raul wrote:

OK - here is a really quick and basic tutorial on loading the file.

This assumes you're using the EWB IDE and using the built-in webserver. You need to copy the csv file to the output folder in step 3

1. start new visual project
2. put a memo, button, serverrequest and serverrequestqueue on the form
3. might as well save project now and compile it. this should result in the "output" folder under the project - make sure you now copy the cvs file into that folder
4. i renamed my button as ButtonGetFile.
5. double click on button to add Click event and make sure it looks like this (use whatever your file name was - this just loads the file from the same server as EWB app is run from)

procedure TForm1.ButtonGetFileClick(Sender: TObject);
begin                             
  ServerRequest1.URL := 'http://'+ window.location.host+'/mytextfile.csv';
  ServerRequestQueue1.AddRequest(ServerRequest1);
end;

6. you also need to add WebDOM to the uses clause of the unit.

7.then select serverequest and add the OnCompleteHandler. it should look something like this.

procedure TForm1.ServerRequest1Complete(Request: TServerRequest);
begin
  if (Request.StatusCode=200) then
  begin
     Memo1.Text := Request.ResponseContent.Text;
     ShowMessage('File loaded');
  end
  else
     ShowMessage('Failed to load file :' + IntToStr(Request.StatusCode) + '.' + Request.ResponseContent.Text );
end;

8. that's it. Compile and run your project and if everything works you should see the file loaded into the memo

now you should be able to access the file contents in the memo

Raul
Tue, Jan 28 2014 6:14 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Doc,

<< I also had to enable HTML5 Functionallity. >>

No, that isn't correct.  You do not have to enable the HTML5 functionality
for server requests to work.

Tim Young
Elevate Software
www.elevatesoft.com




Tue, Jan 28 2014 6:18 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Doc,

<< Even the example from the help page doesn''t compile:  >>

It's a partial example of an event handler *implementation*.  You can't just
copy and paste it into an application without also creating the relevant
method prototype in the form class (interface section), or by just
double-clicking on the OnComplete event for your TServerRequest component in
the Object Inspector.

Tim Young
Elevate Software
www.elevatesoft.com


Wed, Jan 29 2014 11:57 AMPermanent Link

Doc

Thank you for that information,

but, strage thing, the TServerRequest Component was not available from the Toolbar until I pressed this
Enable HTML5 Functionality Button. Since then I can deselect this functionality and the TServerRequest Component ist still there.


"Tim Young [Elevate Software]" wrote:

Doc,

<< I also had to enable HTML5 Functionallity. >>

No, that isn't correct.  You do not have to enable the HTML5 functionality
for server requests to work.

Tim Young
Elevate Software
www.elevatesoft.com




Wed, Jan 29 2014 8:26 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Doc,

<< but, strage thing, the TServerRequest Component was not available from
the Toolbar until I pressed this Enable HTML5 Functionality Button. Since
then I can deselect this functionality and the TServerRequest Component ist
still there. >>

I don't see how that could be - those icons are hard-coded into the
component palette.  Perhaps you missed them earlier...

Tim Young
Elevate Software
www.elevatesoft.com
Page 1 of 2Next Page
Jump to Page:  1 2
Image