{"id":987,"date":"2008-10-16T23:49:23","date_gmt":"2008-10-16T22:49:23","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/987-sqlite-and-delphi-2009.html"},"modified":"2008-10-16T23:49:23","modified_gmt":"2008-10-16T22:49:23","slug":"sqlite-and-delphi-2009","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/987-sqlite-and-delphi-2009.html","title":{"rendered":"SQLite and Delphi 2009"},"content":{"rendered":"<p>I created a <a href=\"http:\/\/www.itwriting.com\/blog\/a-simple-delphi-wrapper-for-sqlite-3\">simple Delphi wrapper<\/a> for <a href=\"http:\/\/www.sqlite.org\">SQLite<\/a>, the popular open source database library. I\u2019ve just updated it to work with Delphi 2009 \u2013 I\u2019m not happy with what I\u2019ve done, because I\u2019ve changed a bunch of declarations from PChar to PAnsiChar and from String to AnsiString, just to get it working quickly. SQLite is fine for Unicode, so the next step is to revise it properly to support Unicode &#8230; when I or someone else has time.<\/p>\n<p>It was interesting to do some work with Delphi 2009. It has the old problem: out of date documentation. Here\u2019s what it says about PChar, in the entry on pointer types:<\/p>\n<blockquote>\n<p>The fundamental types <strong>PAnsiChar<\/strong> and <strong>PWideChar<\/strong> represent pointers to <strong>AnsiChar<\/strong> and <strong>WideChar<\/strong> values, respectively. The generic <strong>PChar<\/strong> represents a pointer to a <strong>Char<\/strong> (that is, in its current implementation, to an <strong>AnsiChar<\/strong>).<\/p>\n<\/blockquote>\n<p>Further, if you have the following code:<\/p>\n<blockquote>\n<p>var      <br \/>strTest: PChar;       <br \/>begin       <br \/>strTest := StrAlloc(6);       <br \/>strcopy(strTest,&#8217;Hello&#8217;);       <br \/>strdispose(strTest);       <br \/>end;<\/p>\n<\/blockquote>\n<p>and hover the mouse over strTest in the editor, the pop-up tip says:<\/p>\n<blockquote>\n<p>strTest \u2013 System.PAnsiChar<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/d2009error.gif\" \/> <\/p>\n<\/blockquote>\n<p>However, this is wrong. In Delphi 2009, a generic PChar is a PWideChar. Here\u2019s the code in SysUtils for StrAlloc:<\/p>\n<blockquote>\n<p>function StrAlloc(Size: Cardinal): PChar;      <br \/>begin       <br \/>{$IFDEF UNICODE}       <br \/>&#160; Result := WideStrAlloc(Size);       <br \/>{$ELSE}       <br \/>&#160; Result := AnsiStrAlloc(Size);       <br \/>{$ENDIF}       <br \/>end;<\/p>\n<\/blockquote>\n<p>UNICODE is defined in Delphi 2009, so StrAlloc returns a PWideChar.<\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d3d8264a-46a2-43b5-9c64-9183607d7969\" style=\"padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/delphi\" rel=\"tag\">delphi<\/a>, <a href=\"http:\/\/technorati.com\/tags\/sqlite\" rel=\"tag\">sqlite<\/a>, <a href=\"http:\/\/technorati.com\/tags\/unicode\" rel=\"tag\">unicode<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I created a simple Delphi wrapper for SQLite, the popular open source database library. I\u2019ve just updated it to work with Delphi 2009 \u2013 I\u2019m not happy with what I\u2019ve done, because I\u2019ve changed a bunch of declarations from PChar to PAnsiChar and from String to AnsiString, just to get it working quickly. SQLite is &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/987-sqlite-and-delphi-2009.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SQLite and Delphi 2009<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,80],"tags":[],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-delphi","category-software-development"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=987"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}