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


  • Full Member
  • ***
  • Posts: 248
Using Visual Components in Web Server
« on: July 08, 2019, 04:50:08 am »
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
  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');
  6. AMemStream := TMemoryStream.Create;    
  7. tv1.SaveToStream(AMemStream);    // Save treeview to memory stream
  9. tv1.Free;
  11. AResponse.ContentStream := AMemStream;    // Response with the memory stream
  12. Handled := True;                    

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.?


  • Hero Member
  • *****
  • Posts: 8114
  • 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


  • Hero Member
  • *****
  • Posts: 9293
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 »
also related to equus asinus.