* * *

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: need help with calender
« Last post by rhong7 on Today at 11:14:22 am »
Code: Pascal  [Select]
  1. procedure Tform1.AddRank(Namee: String; Score: Integer);
  2. begin
  3.  x := 1;
  4. while (x <= 10) and (rank[x].score >= score) do inc(x);
  5. if x <= 10 then // are we still below 10?, so we broke out the previous loop with score > rank[x].score
  6. begin
  7.  for i:= 10 downto x+1 do
  8.     begin
  9.  
  10.      rank[i].score:=rank[i-1].score;
  11.      rank[i].name:=rank[i-1].name;
  12.      score:=rank[x].score;
  13.     namee:=rank[x].name;
  14.     reset(highscorefile);
  15.     seek(highscorefile, filesize(highscorefile));
  16.     write(highscorefile, info);
  17.     closefile(highscorefile);
  18.  
  19.     end;
  20.  
  21.   // now move everything from x onward one down and put score on rank[x]
  22. end;
  23. end;                        

so is it like this?
2
General / Re: Dealing with STDOUT with ProcThreadPool.DoParallel
« Last post by Cyrax on Today at 11:11:29 am »
Use StdOut variable which is defined in System unit as threadvar. And for each thread, allocate separate text buffer so output wont get corrupted.
3
General / Re: need help with calender
« Last post by rhong7 on Today at 11:10:39 am »
wait so

Code: Pascal  [Select]
  1. rank[1] = score(new value)
  2. rank[2] = rank[1]
  3. rank[3] = rank[2]
  4. rank[4] = rank[3]
  5. rank[5] = rank[4]

is different to that?

Code: Pascal  [Select]
  1. rank[1] = score(new value)
  2. rank[5] = rank[4]
  3. rank[4] = rank[3]
  4. rank[3] = rank[2]
  5. rank[2] = rank[1]
4
General / Re: need help with calender
« Last post by rvk on Today at 11:03:13 am »
like that?
Yes, you've got it. And last you can put the new highest number on spot 1.

Now you need to do that in a loop.
But the loop can't go from 2 to 4 but needs to go from 4 to 2.
You can read here how you can do that:
http://wiki.lazarus.freepascal.org/FOR..DO

Now you can go back to the AddRank procedure. In there you first need to see where the new number needs to be in the rank. Because if you want to add 60 as score it needs to go on spot 3 and only 3 and 4 need to move down (so not 2 to 4).

Yesterday at 16:22 I gave you the code how to get the correct spot with a while loop.
Use that code in AddRank and use the above for-loop to move the correct values down so you can add the new number at the correct spot in the rank. (Now you can go coding again :) )
5
General / Re: need help with calender
« Last post by rhong7 on Today at 10:54:01 am »
80 to spot 5
75 to spot 4
55 to spot 3
43 to spot 2?

so
rank 5 = rank 4
rank 4 = rank 3
rank 3 = rank 2
rank 2 = rank 1

like that?
6
General / Re: Stacked Panel Visibilty
« Last post by Zath on Today at 10:52:07 am »
Thanks for the replies.
I have several menu options each with multiple sub menus so multiple pages might look odd. I'll give it a go, see how it feels.
7
General / Re: Dealing with STDOUT with ProcThreadPool.DoParallel
« Last post by doropert on Today at 10:50:37 am »
Thank you all for your suggestions. Due to the ease of implementation and insignificant processing time of writing to STDOUT vs the calculations I need to make (in my actual application I spend a lot more time than just calculating an md5), I though I would try the TCriticalSection first. I also force the STDOUT flush.

I have simply created a TCriticalSection which I Enter and Leave before every writeln. However, threads still collide and I get corrupted output every now and then. 

Could someone please tell me what have I done wrong?  :-\

Code: Pascal  [Select]
  1. program mt;
  2. {$mode DELPHI}
  3.  
  4. uses {$ifdef unix} cthreads, cmem, {$endif} Sysutils, md5, classes, MTProcs;
  5.  
  6. var
  7.     MyCriticalSection: TRTLCriticalSection;
  8.     q: tstringlist;
  9.     i: integer;
  10.     F: Text;
  11.  
  12. procedure SyncWriteln (data: ansistring);
  13. begin
  14.     EnterCriticalSection(MyCriticalSection);
  15.     Try
  16.         Assign (F,'');
  17.         Rewrite (F);
  18.         writeln(F,data);
  19.         Flush(F);
  20.         Close(F);
  21.     Finally
  22.         LeaveCriticalSection(MyCriticalSection);
  23.     end;
  24. end;
  25.  
  26. procedure ParallelMD5 (Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);
  27. begin
  28.     SyncWriteln('#'+inttostr(Index)+'='+md5print(md5string(q[Index])));
  29. end;
  30.  
  31. begin
  32.  
  33.     // Load q with 10 strings
  34.     q:=tstringlist.create;
  35.     for i:=1 to 10 do q.add(inttostr(i));
  36.  
  37.     // Calculate MD5 hashes in a single thread
  38.     for i:=0 to 9 do writeln ('#',i,'=',md5print(md5string(q[i])));
  39.  
  40.     // Calculate MD5 hashes in 5 threads
  41.     InitCriticalSection(MyCriticalSection);
  42.     ProcThreadPool.DoParallel(@ParallelMD5, 0, 9, nil, 5);
  43.     DoneCriticalSection(MyCriticalSection);
  44.  
  45. end.
  46.  
8
General / Re: need help with calender
« Last post by rvk on Today at 10:38:18 am »
If you have those numbers 43, 55, 75, 80 and 85 in front of you on the table and you remove 85 from spot 5 and want to move the others to their new spot.... what is the first piece of paper you are going to move and to what spot?
9
Android / Re: LAMW App Crashes on Start up
« Last post by DonAlfredo on Today at 10:37:20 am »
The mORMot demo has been updated in the LAMW repo.
10
General / Re: need help with calender
« Last post by rhong7 on Today at 10:34:15 am »
can you give me any hint?
Pages: [1] 2 3 ... 10

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus