Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


darnocian last won the day on November 11 2020

darnocian had the most liked content!

Community Reputation

22 Excellent

1 Follower

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. darnocian

    ANN: Sempare Template Engine for Delphi

    v1.4.1 is available on GetIt now. Sorry, that release is not compatible with XE4 (my CI is running the latest Delphi only - something in my dev pipeline to support more generally). The version in github has an XE4 compatible fix, but will be bundled into the next release.
  2. darnocian

    ANN: Sempare Template Engine for Delphi

    Hi A new version v1.4.1 is now available and merged into the main branch. This will be available on GetIt shortly. The new version includes a bug fix mentioned above impacting on the fmt() function.
  3. darnocian

    ANN: Sempare Template Engine for Delphi

    No problem. I just realised I could configure email notifications on this thread as well. Either location will do, but this topic may get a bit long. ­čśÇI was just mentioning as I only saw this after a few days.
  4. darnocian

    XLS 2 XLSX

    The apache POI java library ( https://poi.apache.org/ ) is pretty good when it comes to working with the office formats. I've mainly used it for extracting data, but have seen examples of it used for conversion too.
  5. darnocian

    ANN: Sempare Template Engine for Delphi

    Assert.AreEqual('123.457', Template.Eval('<% x := 123.456789 %><% fmt("%6.3f", x) %>')); here is a quick fix in Sempare.Template.Functions.pas: class function TInternalFuntions.Fmt(const AArgs: TArray<TValue>): string; var LArgs: TArray<TVarrec>; LIdx: integer; begin setlength(LArgs, high(AArgs)); for LIdx := 1 to high(AArgs) do LArgs[LIdx - 1] := AArgs[LIdx].AsVarRec; exit(format(AsString(AArgs[0]), LArgs)); end; I need to check into why the current helper does something different. Will get a fix into the main release soon. (fix is on dev branch)
  6. darnocian

    ANN: Sempare Template Engine for Delphi

    I created a test and the following is runs properly: Assert.AreEqual('543.21', Template.Eval('<% x:= 543.21 %><% x %>')); Assert.AreEqual('5.1234', Template.Eval('<% x:= 5.1234 %><% x %>')); floating point numbers should be using dot (.) as illustrated above. I'm not sure about fmt() offhand. Will investigate. fmt() is just a wrapper around SysUtils.Format(fmt, ...). Might be some issue with TValue to TVarRec conversion, but will double check. Most of the templates I've worked on passed values into the engine via the input record/class, but appreciate this should not be a problem. BTW. it is better to raise issues on github. https://github.com/sempare/sempare-delphi-template-engine/issues
  7. darnocian

    Creating custom file groupings

    Thanks Remy.
  8. darnocian

    Delphi and the new Apple M1 CPU

    I did a few tests using WINE a while ago and was quite impressed. I have never got the IDE itself to run on it since I've used it over the years. However, creating some 'hello world' console, VCL and FMX apps I was pleasantly surprised they worked quite well, but had seen some 'glitches' with FMX under 64bit.
  9. darnocian

    Delphi and the new Apple M1 CPU

    Not sure if you guys saw https://www.zdnet.com/article/aws-engineer-puts-windows-10-on-arm-on-apple-mac-m1-and-it-thrashes-surface-pro-x/ It is an old article from Dec 2020. They used Qemu which may be an alternative to launch Windows if VMware is not available. It would be cool to see some others confirm how well it works till we see what VMware comes up with.
  10. darnocian

    ANN: Sempare Template Engine for Delphi

    BTW. The new release v1.4.0 is now also available on GetIt (https://getitnow.embarcadero.com/?q=sempare&amp;product=rad-studio)
  11. darnocian

    ANN: Sempare Template Engine for Delphi

    I think subres should be an index into ChildRecords. Try change: to '<% for subresIdx´╗┐ in ChildRecords´╗┐ %>SubRes: |<% ChildRecords´╗┐[subresIdx´╗┐].Description %>|<br><%end%>'+ I've just renamed the variable as well to make it clearer. It may seem undesirable, but did it this way as sometimes you want to know where you are in the array. If you have many variables, you should be able to do: <% with ChildRecords´╗┐[subresIdx´╗┐] %> <% Description %> <% Vehicle %> <% end %>
  12. darnocian

    ANN: Sempare Template Engine for Delphi

    I tried to provide flexibility in many places. https://github.com/sempare/sempare-delphi-template-engine/blob/master/docs/configuration.md begin var ctx := Template.Context; ctx.StartToken := '{{'; ctx.EndToken := '}}'; Assert.IsEqual('hello', Template.Eval(ctx, '{{ if true }}hello{{else}}bye{{end}}')); end; There is a restriction however. Must be 2 characters in length. It will work as long as it doesn't conflict with any of the other tokens (no validation is done on this however, so you just need to check if you do override) There is also a global override where you can set GDefaultOpenTag and GDefaultCloseTag. These are defined in Sempare.Template.Context.pas. Once set, you don't have to explicitly create a context if you don't need one.
  13. darnocian

    ANN: Sempare Template Engine for Delphi

    Hi, Just a small announcement that a new version (v1.4.0) has been released. Changes: NEW: Context.StreamWriterProvider which allows greater flexibility in providing custom overrides to the StreamWriter NEW: Support for statement start and end tokens allowing for content to be swallowed (useful when statements are multi line) NEW: Added helper variables and functions for spaces, newlines, tabs, chr() and ord() FIX: Issue with custom text writer that supported a few options regarding newlines, but had a bug when it came to carriage returns. (not noticeable under html) FIX: Fixed a double free bug in a ParseFile helper. UPDATE: Documentation updates Context.StreamWriterProvider flexibility var ctx := Template.Context(); ctx.StreamWriterProvider := function(const AStream: TStream; AContext: ITemplateContext): TStreamWriter begin result := TStreamWriter.Create(AStream); end; The above is an example of how the override can be done on a per context basis. There is a GDefaultStreamProvider which is used when the context is initially created which can be used for global initialisation. Allow swallowing of content between start and end statement tokens Say you have a scenario like: <% for i := 1 to 5 %> <% i %> <% end %> What you may notice is that there are many newlines that appear something like: 1 2 3 4 5 Now consider the following: <% for i := 1 to 5 |> <% i %> <| end %> In this scenario, all normal output between |> and <| are ignored, except statements such as explicit print() or variable references will work as normal. Why? It just means that the template becomes responsible for any indenting and newlines within the end (|>) and start ( <|) tokens. --- If you have any feature requests or bug reports, please raise them on https://github.com/sempare/sempare-delphi-template-engine/issues
  14. darnocian

    ANN: Sempare Template Engine for Delphi

    A fix is now in the dev branch with some additional tests and a way to also change the StreamWriter if required. Will look at new tagged release next week or so. (with the fix in the dev branch, the the Context workaround above would be invalidated)
  15. darnocian

    ANN: Sempare Template Engine for Delphi

    @mvanrijnen Just looking at the bug you highlighted, there is also an alternative workaround by setting the IContext.NewLine = #$A. procedure TTestTemplate.TestNewLine; type TRec = record Value: string; description: string; end; var r: TRec; s: string; ctx: ITemplateContext; begin ctx := Template.Context(); ctx.newline := #10; r.Value := 'a value'; r.description := 'some desc'; s := Template.Eval(ctx, 'Value: <% value %>'#$D#$A'Description: <% description %>', r); Assert.AreEqual('Value: a value'#$D#$A'Description: some desc', s); end; I have a custom StreamWriter that allows for stripping repeated whitespace and new lines. I'll look into also providing a way to override that better.