Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 836829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:02:45+00:00 2026-05-15T05:02:45+00:00

i have a function who’s job is to convert an ADO Recordset into html:

  • 0

i have a function who’s job is to convert an ADO Recordset into html:

class function RecordsetToHtml(const rs: _Recordset): WideString;

And the guts of the function involves a lot of wide string concatenation:

   while not rs.EOF do
   begin
      Result := Result+CRLF+
         '<TR>';

      for i := 0 to rs.Fields.Count-1 do
         Result := Result+'<TD>'+VarAsWideString(rs.Fields[i].Value)+'</TD>';

      Result := Result+'</TR>';
      rs.MoveNext;
    end;

With a few thousand results, the function takes, what any user would feel, is too long to run. The Delphi Sampling Profiler shows that 99.3% of the time is spent in widestring concatenation (@WStrCatN and @WstrCat).

Can anyone think of a way to improve widestring concatenation? i don’t think Delphi 5 has any kind of string builder. And Format doesn’t support Unicode.


And to make sure nobody tries to weasel out: pretend you are implementing the interface:

IRecordsetToHtml = interface(IUnknown)
    function RecordsetToHtml(const rs: _Recordset): WideString;
end;

Update One

I thought of using an IXMLDOMDocument, to build up the HTML as xml. But then i realized that the final HTML would be xhtml and not html – a subtle, but important, difference.

Update Two

Microsoft knowledge base article: How To Improve String Concatenation Performance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:02:45+00:00Added an answer on May 15, 2026 at 5:02 am

    i found the best solution. The open source HtmlParser for Delphi, has a helper TStringBuilder class. It is internally used to build what he calls DomStrings, which is actually an alias of WideString:

    TDomString = WideString;
    

    With a little bit of fiddling of his class:

    TStringBuilder = class
    public
       constructor Create(ACapacity: Integer);
       function EndWithWhiteSpace: Boolean;
       function TailMatch(const Tail: WideString): Boolean;
       function ToString: WideString;
       procedure AppendText(const TextStr: WideString);
       procedure Append(const value: WideString);
       procedure AppendLine(const value: WideString);
       property Length: Integer read FLength;
    end;
    

    The guts of the routine becomes:

    while not rs.EOF do
    begin
       sb.Append('<TR>');
    
       for i := 0 to rs.Fields.Count-1 do
          sb.Append('<TD>'+VarAsWideString(rs.Fields[i].Value));
    
       sb.AppendLine('</TR>');
    
       rs.MoveNext;
    end;
    

    The code then feels to run infinitely afaster. Profiling shows much improvement; the WideString manipulation and length-counting became negligible. In its place was FastMM’s own internal operations.

    Notes

    1. Nice catch on the mistaken forcing of all strings into current code-page (VarAsString rather than VarAsWideString)
    2. Some HTML closing tags are optional; omitted ones that logically make no sense.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.