Solution to a multithread problem


! I have been using a 3rd party library (which I don't have the code for) and I have been experimenting some lockouts with my application. The dll accepts an object on a callback function to return some file names ...
Posted On: Tuesday 27th of November 2012 12:57:04 AM Total Views:  272
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

135

Posted on:

Saturday 22nd 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

154

Posted on:

Tuesday 2nd 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

131

Posted on:

Wednesday 3rd October 2012
View Replies!

functions in multithread applications

I wondered if using functions at the same time from threads can cause errors. I'm asking this question because sometimes i got "Invalid floating point operation" from MilliSecondsBetween function. Do i need to use synchronization for calling this function what happens if two threads enter a function at the same time As my second question is GetMem function in Delphi ThreadSafe
VIEWS ON THIS POST

185

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

149

Posted on:

Friday 5th 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

114

Posted on:

Tuesday 16th October 2012
View Replies!

Event problem traced to MessageDlg - need suggestions

w/D7 I have been trying to understand various event processes in an app of mine that displays text in a pagecontrol form. (The text is loaded from a Firefox db). Before a new page is loaded from either a dblclicked ...
VIEWS ON THIS POST

155

Posted on:

Thursday 22nd November 2012
View Replies!

Rounding problem doubles: 79.7 50.3 + 29.4

It appears that if I make q 79.7, r 50.3 and s 29.4 by reading from a string and using the function StrToFloat then q-(r+s) does not equal 0.0 but some very low number like 1E-15. What can I do, ...
VIEWS ON THIS POST

253

Posted on:

Thursday 22nd November 2012
View Replies!

ChecklistBox problems

I can't figure this out. I'm using a checklistbox with the style set as lVirtualOwnerDraw, everything is working as expected, except I can't figure out how to tell it that an item is checked or not. It keeps using the ...
VIEWS ON THIS POST

157

Posted on:

Thursday 22nd November 2012
View Replies!

Loading source problem

Hi people, I hope I am using the correct Group for this. I am getting an error when loading application source. From memory the error message is along the lines of... "Cannot load package c:\....\borland\delphi\bin\dclite50.bpl as it contains zlib which ...
VIEWS ON THIS POST

291

Posted on:

Thursday 22nd November 2012
View Replies!

TForm.Create-problems I

I have a TForm whichs property will be set by the caller. This form shall "ShowModal" other forms, which names will only be known at runtime. But know I dont know, how to do this with a Property: Normally I ...
VIEWS ON THIS POST

162

Posted on:

Thursday 22nd November 2012
View Replies!

Debugger problem in Delphi 2007

Howdy! I have a project that has been growing at a slow pace for several years, since many Delphi versions back. Migrating it to a trial version of Delphi 2007 caused me problems and I wonder if it's my fault ...
VIEWS ON THIS POST

203

Posted on:

Thursday 22nd November 2012
View Replies!

D2007 problems with GetWindowText and MainFormOnTaskbar

I have discouvered that since I upgraded to D2007 I am having problems with a procedure that tells me how many other instances of my application are running. function GetCurrentExeCount: integer; var hPrevInst : Thandle; sfClassName: PChar; begin hPrevInst ...
VIEWS ON THIS POST

301

Posted on:

Thursday 22nd November 2012
View Replies!

Need help with bizarre problem.

I have a multi-tiered db application that I maintain in Delphi 5, and have just run into the most bizarre problem I have ever seen. On a form is a panel which serves as parent for multiple controls (defined by ...
VIEWS ON THIS POST

101

Posted on:

Thursday 22nd November 2012
View Replies!

string to curreny. problem with decimal and thousand separators

Sergio Gonzalez wrote: > > , I have an import process in my app that reads a text file and > convert the values to currency. The text files are generated in other > PCs than the one with is ...
VIEWS ON THIS POST

119

Posted on:

Thursday 22nd November 2012
View Replies!

Hints problem

, I've a problem with the hints - I notice a few other messages about this but they don't solve it for me. I have an application and the hints both on the IDE, and also my application when I ...
VIEWS ON THIS POST

105

Posted on:

Thursday 22nd November 2012
View Replies!

Vista Delphi 6 problems

After I first installed some 3rd party components they worked fine, but once I restart Delphi they don't. I get: Can't load package C:\Program Files\Borland\Delphi6\Projects\Bpl\xxx.bpl. The specified module could not be found. Yet it is there. If I say ok ...
VIEWS ON THIS POST

79

Posted on:

Sunday 25th November 2012
View Replies!

Event conceptualization problem

I have a big hole in my Delphi/windows conceptualization and I'm requesting two types of help with it: 1. the specific language for the concepts that addresses the type of issue I'll describe so that I can find discussions that ...
VIEWS ON THIS POST

95

Posted on:

Sunday 25th November 2012
View Replies!

Does Anyone else have this problem?

Hi , I recently upgraded to Delphi 2007 for win32. Now when I am working in a project and excute the applictaion (F9), all of the component icon's names on the data module(s) disappear!. A real pain! This may happen ...
VIEWS ON THIS POST

116

Posted on:

Sunday 25th November 2012
View Replies!

Re: System tray problems

Lorne a crit : > By design my application only shows in the system tray. When the user > passes the mouse over the icon I can pick up WM_MOUSEMOVE and show a popup > menu above the icon. > ...
VIEWS ON THIS POST

96

Posted on:

Sunday 25th November 2012
View Replies!