Memo1.Text getting bigger and slower, better solution?


I have a program for sniffing RS232 and dumping the Hex output to screen.

It uses the ComPort library from sourceforge.

Here is the guts of it:-

procedure TForm1.Comm1RxChar(Sender: TObject; Count: Integer);
var
Str: String;
i: integer;
Temptext: String;
begin
Comm1.ReadStr(Str, Count);
Temptext := '' + Chr(13)+Chr(10);
Memo1.Text := Memo1.Text + Temptext;
Memo1.SelStart := Length(Memo1.Text);
SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0);
end;

this procedure gets called every time a char or a packet arrives at the RS232 port, and adds
something like this to the screen if a 3 byte packet arrives and then scrolls to the bottom.

As packets arrive I get a bigger and bigger scrolling memobox of packets, which I can then copy and
paste to notepad or something to ****yse.

The problem is that if the packets are arriving thick and fast, the memobox gets bigger and bigger
the program gets slower and slower. I suspect that constantly adding to Memo1.Text is a bad idea
because it also then has to be rendered to the screen, even if only the last 1% or something is
visible.

There must be a better way.

I'm guessing that really I should add the Temptext to some kind of buffer and then only display the
last 10 lines or something. Maybe there could be a "pause" or "stop" button which displays the
whole buffer but without updating it in real time.

Is just using a String variable as a huge buffer of chars a good way How does Delphi handle large
strings How big can they get before something bad happens

How do I copy the last N lines from HugeString to Memo1.Test

Any ideas. I'm pretty new to Delphi so don't be too hard in me...

thanks, Philip
,
"Martin James" wrote
> Yes - that's basically what I do, but I remove them in blocks:
> ...
> meBackupLog.Lines.beginUpdate;
> while (meBackupLog.Lines.Count>=200) do meBackupLog.Lines.Delete(0);
> meBackupLog.Lines.endUpdate;
> ...

Martin, Philip, and Remy,
If you were to store the text in a permanently allocated buffer within your code and then paint the text from an OnDrawCell event handler you would be surprised at the reduction in CPU load.
Posted On: Tuesday 16th of October 2012 03:55:18 AM Total Views:  109
View Complete with Replies

RELATED TOPICS OF Delphi Programming PROGRAMMING LANGUAGE




Natural sorting optimizing... and a working solution :)

I have been working with a natural sorting solution today and i was wondering if someone could have a look and maybe suggest how to optimize it. It works, but it is ugly code. It will for sure not work with tiburian strings. How should I work with strings when I need to extract each char Well anyway it is a good starting point if you are looking for this kind of sorting. I have looked very hard without finding a single delphi implementation so here is your chance I am using the code to sort filenames. Here is the code: function CompareNatural(s1, s2: String): Integer; var n1, n2, j: Integer; c1, c2: Char; t1, t2: String; b: Boolean; function ExtractNr(start: Integer; var txt: String): Integer; var n: Integer; s: String; begin Result:= 0; n:= start; while (n #47) and (txt[n] < #58) do n:= n + 1; s:= Copy(txt, start, (n - start)); Delete(txt, start - 1, (n - start) + 1); if s '' then Result:= StrToInt(s) end; begin t1:= LowerCase(s1); t2:= LowerCase(s2); j:= 1; b:= False; while (not b) do begin result:= 0; c1:= t1[j]; c2:= t2[j]; if c1 c2 then begin // Check if number... if ((c1 > #47) and (c1 < #58)) and ((c2 > #47) and (c2 < #58)) then begin n1:= ExtractNr(j, s1); n2:= ExtractNr(j, s2); if n1 = n2 then Result := 0 else begin if n1 > n2 then Result := 1 else Result := -1; b:= True; end; end else begin if c1 = c2 then // Check if chars are equal Result := 0 else begin if c1 > c2 then Result := 1 else Result := -1; b:= True; end; end; b:= b or (j = Min(Length(t1), Length(t2))); end; b:= b or (j = Min(Length(t1), Length(t2))); j:= j + 1; end; if result = 0 then begin if Length(t1) Length(t2) then if Length(t1) > Length(t2) then Result:= 1 else Result:= -1; end; end;
VIEWS ON THIS POST

127

Posted on:

Saturday 22nd September 2012
View Replies!

Software getting frozen under VISTA

Hi , I submit my question to you just in case some of you have clues to solve my problem : I have developped a software* with Delphi which works fine under XP, but under VISTA, sometimes (that can happen several times per hour), the program get frozen, if the user clic again somewhere on the window, the screen becomes brighter and "not responding" is written. There is absolutely not any particular circonstance, simply working on the software can result in that freezing... At that moment, it's like the program never manages to finish the task he's doing.. but if I look in the task manager, in front of my processus I see no CPU consumed.. Very strange. *My software is a kind of image processing CAD-CAM software. Does someone have any idea that could help me
VIEWS ON THIS POST

119

Posted on:

Friday 28th September 2012
View Replies!

Resolution and variables.

As I mentioned in another post, I'm trying to do a program to visualize the Mandelbrot function. Anyway, I did it in 'C', then in Turbo Basic. The visuals were stunning in both of those. So I thought I'd convert the program to Delphi as an exercise since I hadn't don't anything in a number of months. Well, I got it sorta working last night, but it appears to be low-res. At first I thought it was because I was using real variables so I changed them all to extended. Still no luck, Everything looks like a smoothed over picture with no detail at all. It's gotta be something I'm missing.
VIEWS ON THIS POST

150

Posted on:

Tuesday 2nd October 2012
View Replies!

Problem getting keyboard input

I have a Delphi program I've written to do Mandelbrots, and wanted to just put some quick keyboard commands in for pan and home. But I can't seem to get them to work. I've used them before, and I know it's not rocket science. I want to do is look for the 'Home' key so I set up a OnKeyDown for a form event, then in the procedure tied to the event I did a case key of VK_HOME and so on for my keys, but I can't get ANY of the keys to work. It's gotta be something real simple, or I'm braindamaged from being away from Delphi for a while... Mike Yetsko
VIEWS ON THIS POST

120

Posted on:

Wednesday 3rd October 2012
View Replies!

To better interact with the posters around here.

I have lately been helping a guy who has a manic-depressive (a.k.a. bipolar) problem. He gets depressed and angry when criticized; takes suggestions well; likes to be listened to; and loves praise. I think that this experience might help me with my responses to posters in these groups. --JohnH
VIEWS ON THIS POST

173

Posted on:

Wednesday 3rd October 2012
View Replies!

in-house development versus packaged solutions

Ray Porter wrote: A lot of the pros and cons of in-house developed vs pre-packaged vertical depend on the business/facility operations that you are trying to automate in the first place. For example. Accounting is accounting. It is hardly ever worth the effort to roll your package. That development time is better spent on integration with a well-established package or set of modules. While some packages offer a lot of customization possibilities (ie. SAP), you will pay dearly for it. If your operation does not easily fit into a "vertical" solution market, then going with your own development efforts often work out better. Don't underestimate the buy-in from your IT staff and the value of their ability to completely understand, support and modify a system without the assistance of a 3rd party. PS. If you're currently discussing options that run near 10 million, please contact me. I'm sure we can do it for less :-) -- Kevin Powick
VIEWS ON THIS POST

128

Posted on:

Wednesday 3rd October 2012
View Replies!

Memo1.Text getting bigger and slower, better solution?

I have a program for sniffing RS232 and dumping the Hex output to screen. It uses the ComPort library from sourceforge. Here is the guts of it:- procedure TForm1.Comm1RxChar(Sender: TObject; Count: Integer); var Str: String; i: integer; Temptext: String; begin Comm1.ReadStr(Str, Count); Temptext := '' + Chr(13)+Chr(10); Memo1.Text := Memo1.Text + Temptext; Memo1.SelStart := Length(Memo1.Text); SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); end; this procedure gets called every time a char or a packet arrives at the RS232 port, and adds something like this to the screen if a 3 byte packet arrives and then scrolls to the bottom. As packets arrive I get a bigger and bigger scrolling memobox of packets, which I can then copy and paste to notepad or something to ****yse. The problem is that if the packets are arriving thick and fast, the memobox gets bigger and bigger the program gets slower and slower. I suspect that constantly adding to Memo1.Text is a bad idea because it also then has to be rendered to the screen, even if only the last 1% or something is visible. There must be a better way. I'm guessing that really I should add the Temptext to some kind of buffer and then only display the last 10 lines or something. Maybe there could be a "pause" or "stop" button which displays the whole buffer but without updating it in real time. Is just using a String variable as a huge buffer of chars a good way How does Delphi handle large strings How big can they get before something bad happens How do I copy the last N lines from HugeString to Memo1.Test Any ideas. I'm pretty new to Delphi so don't be too hard in me... thanks, Philip , "Martin James" wrote > Yes - that's basically what I do, but I remove them in blocks: > ... > meBackupLog.Lines.beginUpdate; > while (meBackupLog.Lines.Count>=200) do meBackupLog.Lines.Delete(0); > meBackupLog.Lines.endUpdate; > ... Martin, Philip, and Remy, If you were to store the text in a permanently allocated buffer within your code and then paint the text from an OnDrawCell event handler you would be surprised at the reduction in CPU load.
VIEWS ON THIS POST

140

Posted on:

Friday 5th October 2012
View Replies!

FormKeyPress not getting fired

Hi all, I have a form with edit controls, buttons, panels , etc... and I want to hit ENTER to advance to the next control. OK I read that if I put If Key = #13 Then Begin If HiWord(GetKeyState(VK_SHIFT)) 0 then SelectNext(Sender as TWinControl,False,True) else SelectNext(Sender as TWinControl,True,True) ; Key := #0 end; in the Form's FormKeyPress that should do it - but it does not This event does not even get fired. I have no button with the DEFAULT set to TRUE. What else can stop this FormKeyPress event from firing If I select each control's OnKeyPress to the Form's FormKeyPress, it works OK (advances to the next control).
VIEWS ON THIS POST

113

Posted on:

Saturday 6th October 2012
View Replies!