Recent

Author Topic: Using Visual Components in Web Server  (Read 1389 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1289
Using Visual Components in Web Server
« on: July 08, 2019, 04:50:08 am »
Hi,
I can't use visual components like TTreeView, etc. in web server program. Actually defining "ComCtrls", etc. in uses clause makes error in the compilation process.

Is there any way that I can use only non-visual functions of these controls? Followings is a typical example of my cases.

Code: Pascal  [Select][+][-]
  1. tv1 := TTreeView.Create(nil);    //  Create a TTreeView within web server
  2.  
  3. tvItem := tv1.items.add(nil, 'this is first node');   // Add some items in there
  4. tvItem := tv1.items.addChild (tvItem, 'this is first child to first node');
  5.  
  6. AMemStream := TMemoryStream.Create;    
  7. tv1.SaveToStream(AMemStream);    // Save treeview to memory stream
  8.  
  9. tv1.Free;
  10.  
  11. AResponse.ContentStream := AMemStream;    // Response with the memory stream
  12. Handled := True;                    
  13.  
  14.  

My Windows application will receive the stream, and load it to a target visual component.

Code: Pascal  [Select][+][-]
  1. MyVisualTreeView.LoadFromStream(AMemStream);

Is there any way to do this, like using TCustomTreeView, etc.?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Using Visual Components in Web Server
« Reply #1 on: July 23, 2019, 10:52:12 am »
I'm not sure if streaming works across environment but let's assume it does. Add LCL to your project's dependency, now you should be able to compile your project but it will depend on libraries of the chosen widgetset. Then just run and try it

Thaddy

  • Hero Member
  • *****
  • Posts: 14357
  • Sensorship about opinions does not belong here.
Re: Using Visual Components in Web Server
« Reply #2 on: July 23, 2019, 11:31:20 am »
That create(nil) is indeed impossible to make it work correctly.
The proper approach is to create a GUI application that contains the webserver, not the other way around.
Your approach is simply wrong.
The GUI application can of course be hidden and running in the background. Use a hotkey to make it visible/hidden.

Another approach is to write a service or daemon as the webserver and a controller as a GUI app that communicates with the service/daemon.

Note: if you misuse the visual component as an ordinary tree (not visible), use an ordinary tree instead. (I have seen that happen!, wrong approach)
Note2: if it is your intention to serve a treeview, use a javascript component instead. You can Pascalize that with pas2js.
« Last Edit: July 23, 2019, 11:39:07 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018