Jump to content

Alexander Brazda

Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

1 Neutral
  1. Alexander Brazda

    pixel-perfect bitmap FMX app

    For 2d/3d game better use DirectX/OpenGL libraries instead of canvas drawing For controls, painting is done using canvas, so speed it limited. Yo can draw component to a buffer using DirectX/OpenGL surfaces (for complex compositions) and transfer to canvas control, using some buffering to avoid redraw Forms and controls can be scaled from desing dpi to device dpi, check Handle.Scale from yout form For test pixel perfect, I made a simple app to place a Button, Label and TRectangle to get coordinates & dimension of the shape (no style) to see if they are scaled some way. TRectangle is positionated at (16,148) with a size of 64x64. I run on my samsung galaxy tab, click on button to update Label text with the rectangle position and size and compare with screen shot. Result, rectangle is positionated at 16,148 pixels in clientarea and is 64x64 pixels size, so no scaling has been done. Rectangle is show width 1 px arround the shape as desing.
  2. I agree, use TStringBuilder for string to buffer copy and prevent adding coma cheking before add a new line if buffer is empty. You can reduce memory reallocations if StringBuilder buffer is set to a initial capacity by calling EnsureCapacity or set a value to Capacity. Perheaps you can do some estimation based on max or average record size or just set a value like 4 MB as start point. For csv files with ansi or utf-8 encoding and with ram limitations perheaps you can use a buffered file stream with string encoding Attached file FileBuffer.pas is a Buffered file with string encoding and in memory concatenation, support multiple code pages for input and output. It's optimized for the same input and output codepage. Encoding preamble is writed at start of file, comment if you don't need this. UTF-8 is default encoding Usage sample Buffer:=TFileBuffer.Create('test.txt',CP_UTF8); Buffer.WriteLn('FieldName'#9'Value'); Buffer .Write('Name') .Write(#9) .Write('Alex'); Buffer.Free; FileBuffer.pas
  3. There is no diference between var AText:String and const AText:String and return the value as a function result AText is reference counted so assign a value to this variable inside the función is the same as assign the result of a función to a variable, SetLength would allocate a new string and assign this to AText, so reference counting would decrease inside the funcion instead outside. String functions should work when ZEROBASEDSTRINGS compiler flag is enabled or not, to be safe for any platform. Use StringHelper funcions from System.SysUtils instead base 1 string functions Some optimizations are: declare DeleteLastComma as inline , change "const ALastChar:String" to "ALastChar:Char" function DeleteLastChar(const AText:String;AChar:Char):String; begin if AText.IsEmpty then exit(AText); if AText.Chars[AText.Length-1]=AChar then exit(AText.Substring(0,AText.Length-1); Result:=AText; end; DeleteLastComma method can be a inline function. procedure DeleteLastComma(var AText:String); inline; begin AText:=DeleteLastChar(AText,','); end;
×