Re: [Lazarus] WinINet STDCALL callback crash

2013-03-09 Thread Ludo Brands
On 03/04/2013 12:45 AM, matt...@accordancebible.com wrote:
 Ludo, 
 
 Thank you very much for your most informative posting.  I have spent the week 
 trying to implement the msdn examples in pure Pascal and in Pascal-DLL 
 hybrids.  Success in non-threaded asynchrosity eludes me though.  
 
 Your example 
 (http://www.lazarus.freepascal.org/index.php?topic=18506.15#msg105226) using 
 URLMON's URLDownloadToFile works perfectly.  However, the example is 
 synchronous whilst we need asynchronous.  Research indicates that 
 URLOpenPullStream is the more relevant function in our case (because we 
 download asynchronously to both memory streams and files, depending on what 
 flags the user sets and can track the progress of the download).  The problem 
 is that URLOpenPullStream and URLDownloadToFile (which I am using as an 
 intermediate coding step) both require a variable of a type that implements 
 the IBindStatusCallback interface, which in turn requires declaration of the 
 IBinding interface.  I have tried doing so without success; I share my code 
 below.  
 
 Is there a way to access the UrlMon.dll's definition of IBindStatus and 
 IBinding so that these interfaces are available within Lazarus?  Currently, 
 the only option I see is to define these interfaces myself.  Alternatively, 
 is there an example of a Lazarus definition of these interfaces?
 
 FYI, after the program segfaults, the assembler window points within 
 urlmon!ZonesReInit
 
 Thank you for any help you might provide.
 
This is definitely the most difficult route to async you are trying to
walk;) Delphi has an unit to support urlmon that defines all these
interfaces but I still have to see a stable and reliable piece of code
that manages to use URLOpenPullStream. Also quite some knowledge on COM
interfaces is need to try to get that working. For example
QueryInterface := E_NOTIMPL; is a no go in interfaces.

Why don't you use a standard async library such as lNet
(http://wiki.freepascal.org/lNet, http://lnet.wordpress.com/)? It has a
lazarus package that will install amongst others the
TLHTTPClientComponent that has already the necessary events. The library
comes with a httpclienttest example application that show you how to use
the component.
There is also Indy (http://wiki.freepascal.org/Indy_with_Lazarus) which
is async although that library is much bigger and compatibility with
lazarus is not that good as well as its portability to other platforms.

Ludo


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] some number manipulation

2013-03-09 Thread appjaws

Hi all,
I have a series of results, for each day of the month I have 10 numbers 
ranging from 1 to 20. i.e.

Day11,3,4,5,7,9,12,16,17,20
Day23,4,5,6,8,9,15,17,18,19
etc.

Question 1 how can I find the number of 1's 2's 3's 4's etc. for the 
whole month series?


Question 2 How can I test for 3 or more consecutive numbers in each day?

Hope this is clear, any guidance will be most appreciated.
Paul
--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] some number manipulation

2013-03-09 Thread Howard Page-Clark

On 09/03/13 11:12, appjaws wrote:

Hi all,
I have a series of results, for each day of the month I have 10 numbers
ranging from 1 to 20. i.e.
Day11,3,4,5,7,9,12,16,17,20
Day23,4,5,6,8,9,15,17,18,19
etc.

Question 1 how can I find the number of 1's 2's 3's 4's etc. for the
whole month series?

Question 2 How can I test for 3 or more consecutive numbers in each day?


Q1 for such a small dataset a brute force approach of iterating over all 
values and counting each occurrence of 1, 2, 3 etc. in 20 distinct 
counters seems best.


Q2 Your data is ordered by value, so a function along these lines ought 
to work:


type
  TNumber = 1..20;
  TDayData = array[1..10] of TNumber;

function ThreeOrMoreConsecutiveNos(dd: TDayData): boolean;
var i: integer=1;
begin
 Result:= False;
 while i =8 do
  begin
if ( dd[i]=Pred(dd[i+1]) )
 and ( dd[i+1]=Pred(dd[i+2]) )
then Exit(True);
Inc(i);
  end;
end;


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] some number manipulation

2013-03-09 Thread appjaws

On 09/03/13 12:11, Howard Page-Clark wrote:

On 09/03/13 11:12, appjaws wrote:

Hi all,
I have a series of results, for each day of the month I have 10 numbers
ranging from 1 to 20. i.e.
Day11,3,4,5,7,9,12,16,17,20
Day23,4,5,6,8,9,15,17,18,19
etc.

Question 1 how can I find the number of 1's 2's 3's 4's etc. for the
whole month series?

Question 2 How can I test for 3 or more consecutive numbers in each day?


Q1 for such a small dataset a brute force approach of iterating over all
values and counting each occurrence of 1, 2, 3 etc. in 20 distinct
counters seems best.

Q2 Your data is ordered by value, so a function along these lines ought
to work:

type
   TNumber = 1..20;
   TDayData = array[1..10] of TNumber;

function ThreeOrMoreConsecutiveNos(dd: TDayData): boolean;
var i: integer=1;
begin
  Result:= False;
  while i =8 do
   begin
 if ( dd[i]=Pred(dd[i+1]) )
  and ( dd[i+1]=Pred(dd[i+2]) )
 then Exit(True);
 Inc(i);
   end;
end;


Thank you Howard,
I just realised that I need to sort the numbers because they are not 
like my example above. So where and how would I sort the array for each 
Day and then call ThreeOrMore?


I'm still learning and really appreciate your help
Paul


--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] some number manipulation

2013-03-09 Thread Howard Page-Clark

On 09/03/13 3:06, appjaws wrote:


I have a series of results, for each day of the month I have 10 numbers
ranging from 1 to 20. i.e.
Day11,3,4,5,7,9,12,16,17,20
Day23,4,5,6,8,9,15,17,18,19

...

I just realised that I need to sort the numbers because they are not
like my example above. So where and how would I sort the array for each
Day and then call ThreeOrMore?


If you have any programming books you'll almost certainly find they 
include a chapter on sorting algorithms (bubble sort, quicksort etc.).

One FPC/Lazarus tutorial implementation is at
http://www.pp4s.co.uk/main/tu-ss-sort-quick-demo1a.html
and Lazarus also has several integer quicksort implementations in its 
own code such as at ...\lazarus\lcl\grids.pas, line 2850


Howard


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] some number manipulation

2013-03-09 Thread Curt Carpenter
I would create a matrix A[i,j] with i = 1,2,3,...31 (31 rows) and 
j=1,2,3,...20 (20 columns).

Initialize the matrix to all zeroes.
Then for each day of the month, if the number k occurs in day j, then 
set A[j,k] := 1.
At the end of the month, the sum of the elements in row k will tell you 
how many times k occurred during the month.
Then scan each row of the matrix looking for three or more consecutive 
1's (left as an exercise :-)


On 3/9/2013 10:00 AM, Howard Page-Clark wrote:

On 09/03/13 3:06, appjaws wrote:

I have a series of results, for each day of the month I have 10 
numbers

ranging from 1 to 20. i.e.
Day11,3,4,5,7,9,12,16,17,20
Day23,4,5,6,8,9,15,17,18,19

...

I just realised that I need to sort the numbers because they are not
like my example above. So where and how would I sort the array for each
Day and then call ThreeOrMore?


If you have any programming books you'll almost certainly find they 
include a chapter on sorting algorithms (bubble sort, quicksort etc.).

One FPC/Lazarus tutorial implementation is at
http://www.pp4s.co.uk/main/tu-ss-sort-quick-demo1a.html
and Lazarus also has several integer quicksort implementations in its 
own code such as at ...\lazarus\lcl\grids.pas, line 2850


Howard


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus