Recent

Author Topic: Modifying existing fpcsrc library  (Read 312 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 530
    • MarcusFernstrom.com
Modifying existing fpcsrc library
« on: January 28, 2021, 05:24:18 am »
I'm trying to modify HTTPDefs but I'm running into what seems like an odd issue.

I have a line
Code: Pascal  [Select][+][-]
  1. aResponse.Content := jObject.AsJSON;

If I right-click on .Content, and Find Declaration, I'm brought to the HTTPDefs file in the path Lazarus is set up to use.

But if I modify anything, like changing the property for Content from

Code: Pascal  [Select][+][-]
  1. Property Content : RawByteString Read GetContent Write SetContent;

to

Code: Pascal  [Select][+][-]
  1. Property Content : Integer Read GetContent Write SetContent;

Nothing happens.

If I delete all content in the file, nothing happens.

This is the first time I'm trying to do this, so I might just be missing something super obvious, but how would I get at the source used so I can modify and run it?

ccrause

  • Sr. Member
  • ****
  • Posts: 350
Re: Modifying existing fpcsrc library
« Reply #1 on: January 28, 2021, 07:15:20 am »
I'm trying to modify HTTPDefs but I'm running into what seems like an odd issue.
This unit is part of the packages distributed with FPC with a prebuild unit stored separately from the source (at least in typical situations).  When you modify the source file in Lazarus without adding the unit to your project, the compiler will not check this out of project file for modifications, it will just check the configured folders for compiled units and detect and use the precompiled/installed version.

If you really want to modify a file in a package then you need to rebuild that specific package and re-install the package so the compiler can find the updated units.  Or you can copy the required package into your project and add the files to your project.  This way your modifications to the package only affects this one project.

Trenatos

  • Hero Member
  • *****
  • Posts: 530
    • MarcusFernstrom.com
Re: Modifying existing fpcsrc library
« Reply #2 on: February 02, 2021, 03:49:15 am »
That did the trick, thanks ccrause. I've also made a patch and submitted to the bugtracker.

What I did was just make it easier to respond with JSON data when using fphttpserver, by adding JSONContent.

Code: Pascal  [Select][+][-]
  1. procedure jsonEndpoint(aRequest : TRequest; aResponse : TResponse);
  2. var
  3.   jObject : TJSONObject;
  4. begin
  5.   jObject := TJSONObject.Create;
  6.   try
  7.     jObject.Booleans['success'] := true;
  8.     aResponse.JSONContent := jObject;
  9.     aResponse.SendContent;
  10.   finally
  11.     jObject.Free;
  12.   end;
  13. end;
  14.  

 

TinyPortal © 2005-2018