Hello.
Having an fphttpserver simple program running on windows. When responding to root (/) request, I read data from sqlite database & render html page using fcl-mustache package.
but results looks like ugly, the fields results precedes with questions marks (ex: a field value of ABCD will looks like ????ABCD).
here is a simple code.
procedure route3(aReq: TRequest; AResponse: TResponse);
Function StringOrFile(S : String) : TMustacheString;
begin
With TFileStream.Create(S,fmOpenRead or fmShareDenyNone) do
try
SetLength(Result,Size);
ReadBuffer(Result[1],Size);
finally
Free;
end;
end;
var
lCnt: TSQLite3Connection;
ltr: TSQLTransaction;
lDs: TSQLQuery;
lText: TMustacheString;
lTextRes: UTF8String;//TMustacheString;
lM: TMustache;
lC: TMustacheDBContext;
begin
ltr := TSQLTransaction.Create(nil); // transaction
lCnt := TSQLite3Connection.Create(nil); // Connection
lCnt.Transaction := ltr;
lCnt.DatabaseName := 'gsystem.db';
lCnt.KeepConnection := True;
lCnt.Open();
lDs := TSQLQuery.Create(nil); // Query
lDs.DataBase := lCnt;
lDs.SQL.Text := 'SELECT * FROM uc_system Where del=0';
lDS.Open();
lM := TMustache.Create(Nil);
try
lText := StringOrFile('app.tpl');
lC := TMustacheDBContext.Create(Nil);
lC.AddDataset(lDs, 'sysparam');
lM.Template := lText;
lTextRes := lM.Render(lC);
AResponse.ContentType := 'text/html; charset=utf-8';
AResponse.ContentEncoding := 'UTF-8';
AResponse.Content := lTextRes;
AResponse.SendContent();
finally
lM.Free;
lC.Free;
lDs.Free;
lCnt.Free;
ltr.Free;
end;
end;
The strange thing, also, is that when using a simple GUI program (not web), It works perfectly.
I think, I miss something when it comes to serve a web page.
Thank you in advence.