Recent

Author Topic: Trying to create a dynamic form  (Read 5001 times)

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #30 on: February 19, 2024, 08:40:22 pm »
Usual a logo is an Image stored in the resource section of a binary so its available to all forms via resource-stream and easier to keep unified/update.
For a "DebugWindow" I suggest that you start using logging and in that "DebugWindow" put all those lines of log into a read-only TMemo or similar.
Best would be to show us an Image of what you want to achieve as of right now more and more comes into that was not mentioned in first post.

What I'm trying to do is simulate a console window to have outputs delivered live there, so I don't have to use breakpoints just to catch some glimpses.
When I was programming MQL4 we didn't have watches, and I got more accustomed to logs. Breaking the program often to take a peek at variables is quite annoying.
A TMemo would be the most easy peasy option, but I was thinking actually at writing text with TextOut and then scrolling it with something akin to GetImage / PutImage that were in the Graph unit long ago...
This would also allow me to control the color of the outputs.

rvk

  • Hero Member
  • *****
  • Posts: 6589
Re: Trying to create a dynamic form
« Reply #31 on: February 19, 2024, 08:47:57 pm »
A TMemo would be the most easy peasy option, but I was thinking actually at writing text with TextOut and then scrolling it with something akin to GetImage / PutImage that were in the Graph unit long ago...
This would also allow me to control the color of the outputs.
Then something like TRichMemo would be much easier.
Especially if you need to scroll, an image would not be easy.
And if text with different fonts and colors is all you need, a TRichMemo or some HtmlView would be more useable.

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #32 on: February 19, 2024, 09:18:51 pm »
A TMemo would be the most easy peasy option, but I was thinking actually at writing text with TextOut and then scrolling it with something akin to GetImage / PutImage that were in the Graph unit long ago...
This would also allow me to control the color of the outputs.
Then something like TRichMemo would be much easier.
Especially if you need to scroll, an image would not be easy.
And if text with different fonts and colors is all you need, a TRichMemo or some HtmlView would be more useable.

Thanks. I'm looking into TRichMemo.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Trying to create a dynamic form
« Reply #33 on: February 19, 2024, 09:20:28 pm »
A TMemo would be the most easy peasy option, but I was thinking actually at writing text with TextOut and then scrolling it with something akin to GetImage / PutImage that were in the Graph unit long ago...
This would also allow me to control the color of the outputs.
Then something like TRichMemo would be much easier.
Especially if you need to scroll, an image would not be easy.
And if text with different fonts and colors is all you need, a TRichMemo or some HtmlView would be more useable.
Absolute, since both, the RTF format and HTML, can contain and handle images way better than you could ever tinker with GetImage/PutImage together.
I will not say impossible, I would say unneccessary waste of RAM and time to develop logic.
My favorite would be RTF since that way you just need to handle only one bitmap at a time, scroll to position, transfer bitmap to the control, free it, repeat ....
HTML would enforce that you keep every bitmap as long your app is running and depending on your actual writings to the log it can raise up very fast and that would end in a crazy RAM burner.
My own way would be, dont give a dime about font or color or image(s), its a log not a fashion show, so log to a database and whenever needed populate a view of that table.
(while my own way of doing include just 2 colors, a main "all good" color and typical red for errors)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #34 on: February 24, 2024, 04:45:57 am »
I am still having trouble with the colors, but TRichMemo was a blast to use.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Trying to create a dynamic form
« Reply #35 on: February 24, 2024, 06:30:23 am »
I am still having trouble with the colors
That is sad, while I watch at the source you showed to us to know where the problem might be, I think line 123 needs adjustments or in other words, nobody of us does know what you do and how you do.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #36 on: February 24, 2024, 12:14:28 pm »
I am still having trouble with the colors
That is sad, while I watch at the source you showed to us to know where the problem might be, I think line 123 needs adjustments or in other words, nobody of us does know what you do and how you do.

 :D :D :D :D
Nah, I managed to patch it up. Quite proud of myself for this. Thing is I didn't know that if you add text after using SetTextAttributes it resets styles. I moved styling at the very end and now looks quite awesome.
The thing I don't like though is that I don't have a minimize button. I'm using bsToolWindow for the border style and that gives a close button but no minimize. I'd like to have minimize but no close button and no resizing.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Trying to create a dynamic form
« Reply #37 on: February 24, 2024, 01:12:23 pm »
I am still having trouble with the colors
That is sad, while I watch at the source you showed to us to know where the problem might be, I think line 123 needs adjustments or in other words, nobody of us does know what you do and how you do.

 :D :D :D :D
Nah, I managed to patch it up. Quite proud of myself for this. Thing is I didn't know that if you add text after using SetTextAttributes it resets styles. I moved styling at the very end and now looks quite awesome.
The thing I don't like though is that I don't have a minimize button. I'm using bsToolWindow for the border style and that gives a close button but no minimize. I'd like to have minimize but no close button and no resizing.
That sound great that you managed your RichMemo problems on your own  O:-)
For testing, as in my screenshot, I've quickly made me 2 methods that I call in those button events:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   LFont: TFont;
  4. begin
  5.   LFont := TFont.Create;
  6.   try
  7.     LFont.Name := Screen.Fonts[Random(Screen.Fonts.Count)];
  8.     LFont.Size := 20;
  9.     LFont.Color := RGBToColor(Random(High(Byte)), Random(High(Byte)), Random(High(Byte)));
  10.     // procedure TForm1.AddRichText(const ARichMemo: TRichMemo; const AText: string; const AFont: TFont; const ABackgroundColor: TColor);
  11.     AddRichText(RichMemo1, 'Test', LFont, RGBToColor(Random(High(Byte)), Random(High(Byte)), Random(High(Byte))));
  12.   finally
  13.     LFont.Free;
  14.   end;
  15. end;
  16.  
  17. procedure TForm1.Button2Click(Sender: TObject);
  18. begin
  19.   AddRichBreak(RichMemo1);
  20. end;

To your system button problem, such you can only realize by turning the borderstyle to bsNone and create your own Title with whatever you want to have, like a button that does "Self.Hide;"
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #38 on: February 24, 2024, 01:23:30 pm »

To your system button problem, such you can only realize by turning the borderstyle to bsNone and create your own Title with whatever you want to have, like a button that does "Self.Hide;"


That's ingenious! I don't think it works with Self.Hide, I think once hidden it cannot be shown again by mouse, but that gives me an idea. I can just put the button and collapse/expand the window.

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #39 on: February 25, 2024, 08:58:59 am »
It turned out quite beautifully with a Minimize/Restore button. Quite a nice tool to have, debugging was getting outta hand...

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #40 on: February 27, 2024, 02:09:31 pm »
I see that it slows down seriously when I increase the size. :o .. That's a bummer...

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Trying to create a dynamic form
« Reply #41 on: February 27, 2024, 02:30:25 pm »
I see that it slows down seriously when I increase the size. :o .. That's a bummer...
Line 84 where you resize, there is much perfomance lost! Or in other words, show code how you do so we can help make it faster.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #42 on: February 27, 2024, 03:20:49 pm »
I see that it slows down seriously when I increase the size. :o .. That's a bummer...
Line 84 where you resize, there is much perfomance lost! Or in other words, show code how you do so we can help make it faster.

Alrighty then. Ok, code looks a bit strange. It's in a unit and it's not made into a class, I'm not sure why...
This unit is much larger, I extracted only the code dealing with it.

Code: Pascal  [Select][+][-]
  1. interface
  2. uses Forms,Controls,StdCtrls,ExtCtrls,RichMemo; //note: add pl_RichMemo in Project Inspector - Required Packages when compiling
  3.  
  4. var {console public variables}
  5.     ConsoleWindowEnabled:boolean;
  6.     ConsoleCurrentColor:tcolor;
  7.  
  8. procedure GetTextSizeEx(AText: string; AFont: string; AFontSize:word; var Shape:TShape; var sizex,sizey:longint);  
  9. procedure CreateConsoleWindow();
  10. procedure ShowConsoleWindow();
  11. procedure ConsoleResize(Rows,Cols:word);
  12. procedure ConsoleChangeFont(name:string;size:longint;Rows,Cols:word);
  13. procedure ConsoleClear();
  14. procedure ConsoleRestore();
  15. procedure ConsoleMinimize();
  16. procedure ConsoleWrite(s:string);
  17. procedure ConsoleOut(s:string);
  18.  
  19. implementation
  20.  
  21. type TConsoleButtonMinimizeRestore=class(TButton)
  22.                                         procedure Click(Sender:TObject);
  23.                                    end;
  24.  
  25. var {console private variables}
  26.     ConsoleWindow:TForm;
  27.     ConsoleBttnMinimizeRestore:TConsoleButtonMinimizeRestore;
  28.     ConsoleWindowShape:TShape;
  29.     ConsoleWindowMemo:TRichMemo;
  30.     ConsoleFontName:string;
  31.     ConsoleFontSize:word;
  32.     ConsoleTextLimit:longint;
  33.     ConsoleColorBuffer:array of TColor;
  34.     ConsoleTextBuffer:string;
  35.     ConsoleWindowMinimized:boolean;
  36.     ConsoleWindowRows,ConsoleWindowColumns:word;
  37.  
  38. procedure ConsoleRefresh(); forward;
  39. procedure ConsoleChangeState(); forward;
  40.  
  41. procedure TConsoleButtonMinimizeRestore.Click(Sender:TObject);
  42. begin
  43.    ConsoleChangeState();
  44. end;                                                      
  45.  
  46. procedure GetTextSizeEx(AText: string; AFont: string; AFontSize:word; var Shape:TShape; var sizex,sizey:longint);
  47. var ofn:string;
  48.     ofs:longint;
  49. begin
  50.   ofn:=shape.canvas.Font.Name;
  51.   ofs:=shape.canvas.font.Size;
  52.   shape.canvas.Font.Name:=Afont;
  53.   shape.canvas.Font.Size:=AFontSize;
  54.   sizex := shape.canvas.TextWidth(AText);
  55.   sizey := shape.canvas.TextHeight(AText);
  56.   shape.canvas.Font.Name:=ofn;
  57.   shape.canvas.Font.Size:=ofs;
  58. end;  
  59.  
  60. //must call from inside another form in order to be created
  61.  
  62. procedure CreateConsoleWindow;
  63. var szx,szy,diff:longint;
  64. begin
  65.    if ConsoleWindowEnabled=true then
  66.       if ConsoleWindow=nil then begin
  67.       ConsoleWindow:=TForm.Create(nil);
  68.       ConsoleWindow.Parent:=nil;
  69.       //size up window with a tolerance of 10 pixels up and down
  70.       ConsoleWindow.SetBounds(100,100,200,120);
  71.       diff:=ConsoleWindow.Height-ConsoleWindow.ClientHeight;
  72.       ConsoleWindow.BorderStyle := bsToolWindow;
  73.       ConsoleWindow.Caption:='Console Window';
  74.       ConsoleWindowShape:=TShape.Create(nil);
  75.       ConsoleWindowShape.Parent:=ConsoleWindow;
  76.       ConsoleWindowShape.Top:=0;
  77.       ConsoleWindowShape.Left:=0;
  78.       ConsoleWindowShape.Width:=1;
  79.       ConsoleWindowShape.Height:=1;
  80.       ConsoleWindowMemo:=TRichMemo.Create(nil);
  81.       ConsoleWindowMemo.Parent:=ConsoleWindow;
  82.       ConsoleWindowMemo.Top:=31;
  83.       ConsoleWindowMemo.left:=1;
  84.       ConsoleWindowMemo.Width:=ConsoleWindow.Width-1;
  85.       ConsoleWindowMemo.Height:=ConsoleWindow.Height-1;
  86.       ConsoleWindowMemo.Color:=clBlack;
  87.       ConsoleWindowMemo.WordWrap:=false;
  88.       ConsoleWindowMemo.Enabled:=false;
  89.       ConsoleWindowMemo.Font.Name:=ConsoleFontName;
  90.       ConsoleWindowMemo.Font.Size:=ConsoleFontSize;
  91.       ConsoleWindowMemo.Font.Color:=ConsoleCurrentColor;
  92.       GetTextSizeEx('X',ConsoleFontName,ConsoleFontSize,ConsoleWindowShape,szx,szy);
  93.       ConsoleWindow.SetBounds(ConsoleWindow.Top,ConsoleWindow.Left,szx*ConsoleWindowColumns+10,szy*ConsoleWindowRows+10+diff+(2*szy+4));
  94.       ConsoleBttnMinimizeRestore:=TConsoleButtonMinimizeRestore.Create(nil);
  95.       ConsoleBttnMinimizeRestore.Parent:=ConsoleWindow;
  96.       ConsoleBttnMinimizeRestore.Top:=1;
  97.       ConsoleBttnMinimizeRestore.Left:=1;
  98.       ConsoleBttnMinimizeRestore.Width:=ConsoleWindow.Width-2;
  99.       ConsoleBttnMinimizeRestore.Height:=2*szy+2;
  100.       ConsoleBttnMinimizeRestore.Caption:=' Minimize ';
  101.       ConsoleBttnMinimizeRestore.OnClick:=@ConsoleBttnMinimizeRestore.Click;  //seems a tautology, as it doesn't allow the use of TConsoleMinimizeRestoreClass as it should
  102.       ConsoleWindowMemo.Top:=2*szy+3;
  103.       ConsoleWindowMemo.left:=1;
  104.       ConsoleWindowMemo.Width:=ConsoleWindow.Width-2;
  105.       ConsoleWindowMemo.Height:=ConsoleWindow.Height-2;
  106.    end;
  107. end;
  108.  
  109. procedure ConsoleResize(Rows,Cols:word);
  110. var szx,szy,diff:longint;
  111. begin
  112.    CreateConsoleWindow();
  113.    if ConsoleWindowMinimized=true then ConsoleRestore();
  114.    if ConsoleWindowEnabled=true then begin
  115.       diff:=ConsoleWindow.Height-ConsoleWindow.ClientHeight;
  116.       GetTextSizeEx('X',ConsoleFontName,ConsoleFontSize,ConsoleWindowShape,szx,szy);
  117.       //size up window with a tolerance of 10 pixels up and down
  118.       ConsoleWindow.SetBounds(ConsoleWindow.Top,ConsoleWindow.Left,szx*Cols+10,szy*Rows+10+diff+(2*szy+4));
  119.       ConsoleBttnMinimizeRestore.Width:=ConsoleWindow.Width-2;
  120.       ConsoleWindowMemo.Width:=ConsoleWindow.Width-2;
  121.       ConsoleWindowMemo.Height:=ConsoleWindow.Height;
  122.       ConsoleWindowRows:=Rows;
  123.       ConsoleWindowColumns:=Cols;
  124.       ConsoleRefresh();
  125.    end;
  126. end;
  127.  
  128. procedure ConsoleChangeFont(name:string;size:longint;Rows,Cols:word);
  129. begin
  130.   CreateConsoleWindow();
  131.   ConsoleFontName:=name;
  132.   ConsoleFontSize:=size;
  133.   ConsoleResize(Rows,Cols);
  134. end;
  135.  
  136. procedure ConsoleMinimize();
  137. var szx,szy:longint;
  138. begin
  139.    CreateConsoleWindow();
  140.    if ConsoleWindowMinimized=true then exit;
  141.    if ConsoleWindowEnabled=true then begin
  142.       GetTextSizeEx('X',ConsoleFontName,ConsoleFontSize,ConsoleWindowShape,szx,szy);
  143.       ConsoleWindowMinimized:=true;
  144.       ConsoleWindowMemo.Hide();
  145.       ConsoleWindow.Height:=(2*szy+2);
  146.       ConsoleBttnMinimizeRestore.Caption:='Restore';
  147.       ConsoleWindow.Refresh();
  148.    end;
  149. end;
  150.  
  151. procedure ConsoleRestore();
  152. var szx,szy,diff:longint;
  153. begin
  154.    CreateConsoleWindow();
  155.    if ConsoleWindowMinimized=false then exit;
  156.    if ConsoleWindowEnabled=true then begin
  157.       ConsoleWindowMinimized:=false;
  158.       diff:=ConsoleWindow.Height-ConsoleWindow.ClientHeight;
  159.       GetTextSizeEx('X',ConsoleFontName,ConsoleFontSize,ConsoleWindowShape,szx,szy);
  160.       //size up window with a tolerance of 10 pixels up and down
  161.       ConsoleWindow.SetBounds(ConsoleWindow.Top,ConsoleWindow.Left,szx*ConsoleWindowColumns+10,szy*ConsoleWindowRows+10+diff+31);
  162.       ConsoleWindowMemo.Show();
  163.       ConsoleBttnMinimizeRestore.Caption:='Minimize';
  164.       ConsoleRefresh();
  165.    end;
  166. end;
  167.  
  168. procedure ConsoleChangeState();
  169. begin
  170. if ConsoleWindowMinimized=true then ConsoleRestore()
  171.                                else ConsoleMinimize();
  172. end;
  173.  
  174.  
  175. procedure ShowConsoleWindow;
  176. begin
  177.   CreateConsoleWindow();
  178.   if ConsoleWindowEnabled=true then begin
  179.      ConsoleWindow.Show();
  180.      ConsoleRefresh();
  181.   end;
  182. end;
  183.  
  184. procedure ConsoleClear();
  185. begin
  186.   CreateConsoleWindow();
  187.   ConsoleTextBuffer:='';
  188.   SetLength(ConsoleColorBuffer,0);
  189.   if ConsoleWindowEnabled=true then ConsoleWindowMemo.Text:='';
  190. end;
  191.  
  192.  
  193. procedure ConsoleRefresh();
  194. type change=record begins,lengthof:longint; colorof:tcolor;end;
  195. var i:longint;v,lastlen:word;lc,tf,beginp,endp:longint;c:string;
  196.     fp:tfontparams;slen:longint;colortext:tcolor;
  197.     changes:array of change; changehere:change; ichange:longint;
  198. begin
  199.   SetLength(changes,0);
  200.   if ConsoleWindowMinimized=true then exit;
  201.   CreateConsoleWindow();
  202.   if ConsoleWindowEnabled=true then begin
  203.     //fontparams defaults
  204.     with fp do begin
  205.        Name:=ConsoleFontName;
  206.        Color:=ConsoleCurrentColor;
  207.        Size:=ConsoleFontSize;
  208.        Style:=[];
  209.        HasBkClr:=false;
  210.        BkColor:=clBlack;
  211.        VScriptPos:=vpNormal;
  212.     end;
  213.  
  214.     //locate display position
  215.     lc:=length(ConsoleTextBuffer);
  216.     i:=lc;v:=1;lastlen:=0;tf:=1;
  217.     if i<>0
  218.        then repeat
  219.               c:=copy(ConsoleTextBuffer,i,1);
  220.               if c=#13
  221.                  then begin v:=v+1; lastlen:=0; if v>ConsoleWindowRows then begin tf:=i+1;break; end; end
  222.                  else begin
  223.                         lastlen:=lastlen+1;
  224.                         if lastlen>ConsoleWindowColumns then begin
  225.                                                                lastlen:=1;
  226.                                                                v:=v+1;
  227.                                                                if v>ConsoleWindowRows then begin tf:=i+1;break; end;
  228.                                                              end;
  229.                       end;
  230.               i:=i-1;
  231.             until i=0;
  232.  
  233.     //display block and list color changes
  234.     ConsoleWindowMemo.Text:='';
  235.     lastlen:=0;
  236.     for i:=tf to lc do begin
  237.         if i=tf then begin colortext:=ConsoleColorBuffer[i-1];beginp:=length(ConsoleWindowMemo.Text)+1;end
  238.                 else if ConsoleColorBuffer[i-1]<>colortext then begin
  239.                                                                   endp:=length(ConsoleWindowMemo.Text); slen:=endp-beginp+1;
  240.                                                                   with changehere do begin begins:=beginp-1;lengthof:=slen;colorof:=colortext;end;
  241.                                                                   SetLength(changes,Length(changes)+1);
  242.                                                                   changes[length(changes)-1]:=changehere;
  243.                                                                   colortext:=ConsoleColorBuffer[i-1];beginp:=length(ConsoleWindowMemo.Text)+1;
  244.                                                                 end;
  245.         if lastlen=ConsoleWindowColumns
  246.            then begin
  247.                   ConsoleWindowMemo.Text:=ConsoleWindowMemo.Text+#13;
  248.                   if ConsoleTextBuffer[i]<>#13 then ConsoleWindowMemo.Text:=ConsoleWindowMemo.Text+ConsoleTextBuffer[i]; //inhibit double line feed
  249.                   lastlen:=0;
  250.                 end
  251.            else begin
  252.                   ConsoleWindowMemo.Text:=ConsoleWindowMemo.Text+ConsoleTextBuffer[i];
  253.                   if ConsoleTextBuffer[i]=#13 then lastlen:=0 else lastlen:=lastlen+1;
  254.                 end;
  255.     end;//for i:=tf...
  256.     endp:=length(ConsoleWindowMemo.Text); slen:=endp-beginp+1;
  257.     with changehere do begin begins:=beginp-1;lengthof:=slen; colorof:=colortext;end;
  258.     SetLength(changes,Length(changes)+1);
  259.     changes[length(changes)-1]:=changehere;
  260.  
  261.     //implement color changes
  262.     for ichange:=0 to Length(Changes)-1 do begin
  263.         fp.color:=changes[ichange].colorof;
  264.         ConsoleWindowMemo.SetTextAttributes(changes[ichange].begins,changes[ichange].colorof,fp);
  265.     end;
  266.  
  267.     ConsoleWindow.Refresh();
  268.   end;//if ConsoleWindowEnabled=true
  269. end;
  270.  
  271. procedure ConsoleWrite(s:string);
  272. var newtext:string;lc:longint;lt,i,posi:longint;
  273. begin
  274.   CreateConsoleWindow();
  275.   if ConsoleWindowEnabled=true then begin
  276.      //newtext:=strclear(#0+#10,strtran(s,#9,'     ',1,0)); //clears nulls and LF and changes tabs
  277.      newtext:=s; //removed these references for this code ; strclear removes nulls and linefeeds, strtran changes tabs into a few spaces
  278.      ConsoleTextBuffer:=ConsoleTextBuffer+newtext;
  279.      lt:=length(newtext);
  280.      SetLength(ConsoleColorBuffer,Length(ConsoleColorBuffer)+lt);
  281.      lc:=length(ConsoleColorBuffer);
  282.      for i:=1 to length(newtext) do ConsoleColorBuffer[lc-lt+i-1]:=ConsoleCurrentColor;  //e.g. for (30) do CC[5020-30+30-1] (aka 5019)
  283.      if length(ConsoleTextBuffer)>ConsoleTextLimit then begin
  284.                                                           posi:=length(ConsoleTextBuffer)-ConsoleTextlimit+1;   //eg 5020-5000+1 : 21
  285.                                                           ConsoleTextBuffer:=copy(ConsoleTextBuffer,posi,ConsoleTextLimit); //eg from 21, for 5000 -> 5020
  286.                                                           for i:=0 to ConsoleTextLimit-1 do ConsoleColorBuffer[i]:=ConsoleColorBuffer[posi-1+i]; //eg. from 1 to 5000, assign for [0..4999] from [21+1-2]
  287.                                                         end;
  288.      if ConsoleWindowMinimized=false then ConsoleRefresh();
  289.    end;
  290. end;
  291.  
  292. procedure ConsoleOut(s:string);
  293. begin
  294.   ConsoleWrite(s+#13);
  295. end;
  296.  
  297.  
  298. begin
  299. ConsoleFontName:='Courier New';
  300. ConsoleFontSize:=10;
  301. ConsoleTextLimit:=5000;
  302. ConsoleTextBuffer:='';
  303. ConsoleCurrentColor:=clLtGray;
  304. ConsoleWindowEnabled:=true;
  305. ConsoleWindowMinimized:=false;
  306. ConsoleWindow:=nil;
  307. ConsoleWindowRows:=10;
  308. ConsoleWindowColumns:=35;                                
  309. end.
  310.  
  311.  
« Last Edit: February 27, 2024, 03:25:21 pm by fxeconomist »

rvk

  • Hero Member
  • *****
  • Posts: 6589
Re: Trying to create a dynamic form
« Reply #43 on: February 27, 2024, 05:33:43 pm »
When does this become slow?
When there is a lot of text in the ConsoleTextBuffer array and you resize your form?

You have
ConsoleWindowMemo.Text:=ConsoleWindowMemo.Text+ConsoleTextBuffer;
But you never disable the screen updates when you change the ConsoleWindowMemo.Text.
So begin with that (locking the screen with begin/endupdate).

And... why would you refill the ConsoleWindowMemo.Text when you resize?
Isn't that really inefficient?
When you just keep everything in the memo, it will resize by itself. You can apply coloring afterwards.

But you haven't exactly given specification as to what the TRichMemo is really used for and why it needs to behave like that.
(just a small windows into the larger buffer, or whole text, etc)

fxeconomist

  • New Member
  • *
  • Posts: 48
Re: Trying to create a dynamic form
« Reply #44 on: February 27, 2024, 07:07:16 pm »
When does this become slow?
When there is a lot of text in the ConsoleTextBuffer array and you resize your form?

You have
ConsoleWindowMemo.Text:=ConsoleWindowMemo.Text+ConsoleTextBuffer;
But you never disable the screen updates when you change the ConsoleWindowMemo.Text.
So begin with that (locking the screen with begin/endupdate).

And... why would you refill the ConsoleWindowMemo.Text when you resize?
Isn't that really inefficient?
When you just keep everything in the memo, it will resize by itself. You can apply coloring afterwards.

But you haven't exactly given specification as to what the TRichMemo is really used for and why it needs to behave like that.
(just a small windows into the larger buffer, or whole text, etc)

It's a bit strange, isn't it ?

I have a line displaying about 6 values and runs about 10 times in a block.
While console is set at original size, 10 x 35, it runs fast. Not blazing fast, but okay.

If I do a ConsoleResize(60,60) in advance, i don't really feel the first run. But at the second run, it takes more than a second per line.

Now indeed, ConsoleResize() calls ConsoleRefresh() in the end to update the console.
ConsoleWindowMemo is the TRichMemo, so it has to reflect what is visible on the console.
As the console is resized by ConsoleResize(), it has to adapt to the new size as well.
However, ConsoleResize() is intended for debug purposes. You put it once in your program to enlarge the console.

I presume you may have nailed it. The problem could be this screen update thing. How can I turn it on and off ? The thing is,
the resize from 10 x 35 to 60 x 60 is from 350 chars to 3600 chars, so probably this is the cause of the slowdown.

The TRichMemo is otherwise pretty nifty. Not only that you can set the font - per the whole window, with ConsoleChangeFont(), but also,
you can change color dynamically by changing ConsoleCurrentColor (that's why it's in the implementation section).
As in ConsoleCurrentColor:=clYellow;ConsoleOut('this stuff');ConsoleCurrentColor:=clLtGray;ConsoleOut('back to normal');
« Last Edit: February 27, 2024, 07:21:12 pm by fxeconomist »

 

TinyPortal © 2005-2018