Re: [Lazarus] operator overloading
FPC operator overloading doesn't work inside classes, it must be declared globally, so method2 should work. What error do you get? What FPC version do you use? -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-operator-overloading-tp4029399p4029400.html Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] WinINet STDCALL callback crash
On 02/23/2013 09:49 PM, matt...@accordancebible.com wrote: Hello Lazarus Community, I am implementing asynchronous file download using WinINet's STDCALL callback. However, when the callback function recursively calls itself, it generates a crash around fpc_popaddrstack. I hypothesize that Pascal does not understand how to handle callbacks that use the stdcall convention (which I must use since the callback interfaces with the Win32 API and is itself set via the Win32 WinINet procedure InternetSetStatusCallback). I was wondering if anyone might graciously offer guidance on how to implement asynchronous download to file using the Win32 API or associated libraries only. Note that I have tried WinHTTP and a different implementation of WinINet using InternetConnect/InternetOpenRequest/InternetSendRequest/InternetReadFile). In the previous two implementations I have encountered the same segmentation fault around fpc_popaddrstack. Based on my experience with the below code and other STDCALL implementations, I do not think that Free Pascal can handle the case where a STDCALL function interrupts itself recursively. In the STDCALL convention, the callee is responsible for cleaning up the stack upon function exit. However, because the function in question (HttpCallback) has been interrupted by a second call to it from the Windows API, it has not had a chance to clean up the stack (because it has not had a chance to exit and thereby execute the epilogue code that cleans up the stack). The conditio n that causes the callback to interrupt itself is when InternetReadFile errors out with ERROR_IO_PENDING. In this circumstance, InternetReadFile also sends back an INTERNET_STATUS_REQUEST_COMPLETE message which interrupts the currently executing HttpCallback function. To state the exact circumstance of the crash: when not stepping through, InternetReadFile below errors out frequently with ERROR_IO_PENDING. This is fine except that InternetReadFile ALSO recursively triggers the callback, which after the second recursive call causes a crash. My current code is as follows. I've added inline comments around the parts that seem to crash. Thank you very much for any asssistance you can provide. You are trying to read the complete HTTP reply inside the callback which will not work. ERROR_IO_PENDING just means that the data for the next buffer is not there yet. The callback function is called for every buffer you receive from the server and you should have only one InternetReadFile per INTERNET_STATUS_REQUEST_COMPLETE. So when the HTTP reply takes many buffers you will get many callbacks and in every callback you are supposed to read the buffer received with one single InternetReadFile, Take a look at this example on how to set up async processing: http://msdn.microsoft.com/en-us/library/windows/desktop/cc185684(v=vs.85).aspx. You'll notice the AcquireRequestHandle function that uses a EnterCriticalSection to lock the context. In your code you are not locking anything and your recursive entry in the callback is just using the same context which is the probable cause of your crash. STDCALL callbacks are used commonly in Freepascal and are not a problem at all. If you just want to download an url to file the easy way using the windows framework take a look at this post http://www.lazarus.freepascal.org/index.php?topic=18506.15#msg105226 Ludo -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Checkgroup behaviour
I notice that if the CheckGroup Edit right-click is used to disable all lines, that right-click stops working so it is impossible to reenable any of them. Trunk r40343. Also at runtime, the OnMouseUp event fires if the mouse is clicked over the group background, but not over one of the checkboxes or associated text. Similarly for the OnClick event- is this as it should be? -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Checkgroup behaviour
On Sunday 24 of February 2013 13:00:51 Mark Morgan Lloyd wrote: I notice that if the CheckGroup Edit right-click is used to disable all lines, that right-click stops working so it is impossible to reenable any of them. Trunk r40343. Also at runtime, the OnMouseUp event fires if the mouse is clicked over the group background, but not over one of the checkboxes or associated text. Similarly for the OnClick event- is this as it should be? And widgetset is ? -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Checkgroup behaviour
zeljko wrote: On Sunday 24 of February 2013 13:00:51 Mark Morgan Lloyd wrote: I notice that if the CheckGroup Edit right-click is used to disable all lines, that right-click stops working so it is impossible to reenable any of them. Trunk r40343. Also at runtime, the OnMouseUp event fires if the mouse is clicked over the group background, but not over one of the checkboxes or associated text. Similarly for the OnClick event- is this as it should be? And widgetset is ? GTK2. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] operator overloading
From: xrfang Sent: Sunday, February 24, 2013 7:31 AM To: Lazarus@lists.lazarus.freepascal.org Subject: [Lazarus] operator overloading operator (p1, p2: TPainter) b: Boolean; —method2 Close, but no cigar... operator (p1, p2: TPainter): Boolean; -- ___ 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
Re: [Lazarus] operator overloading
On 24.02.2013 15:51, Wildfire wrote: *From:* xrfang mailto:xrf...@gmail.com *Sent:* Sunday, February 24, 2013 7:31 AM *To:* Lazarus@lists.lazarus.freepascal.org mailto:Lazarus@lists.lazarus.freepascal.org *Subject:* [Lazarus] operator overloading operator (p1, p2: TPainter) b: Boolean; —method2 Close, but no cigar... operator (p1, p2: TPainter): Boolean; Both variants will work. The variant with b: Boolean was originally introduced for the non-Object-Pascal modes (fpc, tp), because there you only have the name of the procedure/function as a result variable and as operators don't have names (in that sense) you can specify the name of the result variable. It works in the Object Pascal modes (delphi, objfpc) however as well. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] operator overloading
I will test again tomorrow to find out what's wrong with my code. For now, one more queston: I noticed that generics does not work without {$mode objfpc}. I wonder what is the default mode without $mode? Why objfpc is not the default mode? 在 日, 2月 24, 2013 at 11:00 下午,Sven Barth pascaldra...@googlemail.com 写道: On 24.02.2013 15:51, Wildfire wrote: *From:* xrfang *Sent:* Sunday, February 24, 2013 7:31 AM *To:* Lazarus@lists.lazarus.freepascal.org *Subject:* [Lazarus] operator overloading operator (p1, p2: TPainter) b: Boolean; —method2 Close, but no cigar... operator (p1, p2: TPainter): Boolean; Both variants will work. The variant with b: Boolean was originally introduced for the non-Object-Pascal modes (fpc, tp), because there you only have the name of the procedure/function as a result variable and as operators don't have names (in that sense) you can specify the name of the result variable. It works in the Object Pascal modes (delphi, objfpc) however as well. Regards, Sven -- ___ 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
Re: [Lazarus] operator overloading
On 24.02.2013 08:31, xrfang wrote: Hi All, How can I use operator overloading? I know the syntax, but it simply does not compile... My situation is: 1. I wrote a TTreap generic class, which is a binary tree. 2. TTreap defines a Compare() with involves and operation on its keys. 3. I try to specialize it with the following: === interface TPainterManager = class(specialize TTreapTPainter, Integer) public class operator (p1, p2: TPainter) b: Boolean; -- method1 end; operator (p1, p2: TPainter) b: Boolean; -- method2 implementation ... === but neither method1 nor method2 compiles. What is the correct way to write operator overload routines? There is only one way how you can solve this: the type TPainter MUST be a record and there you can define the operator using class operator and class operator (in mode ObjFPC you need to use {$modeswitch advancedrecords} as well). Maybe one can think about allowing operators in other structured types (classes, objects, interfaces) as well... Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] operator overloading
Both variants will work. The variant with b: Boolean was originally introduced for the non-Object-Pascal modes (fpc, tp), because there you only have the name of the procedure/function as a result variable and as operators don't have names (in that sense) you can specify the name of the result variable. It works in the Object Pascal modes (delphi, objfpc) however as well. Thanks for the Heads Up Sven, you learn something new everyday. My apologies for the misinformation (and HTML) earlier.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] operator overloading
On 24.02.2013 16:02, xrfang wrote: I will test again tomorrow to find out what's wrong with my code. For now, one more queston: I noticed that generics does not work without {$mode objfpc}. I wonder what is the default mode without $mode? Why objfpc is not the default mode? The default mode is fpc and it will stay the default mode because of backwards compatibility. The difference between the two modes is that fpc is a bit more like tp (no classes, only objects) but with additional features. Generics will work for objects, records, arrays and procedural types in that mode. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Ide add-ons licensing issue
Il 23/02/2013 18:05, Alexsander Rosa ha scritto: Just send the components along with your source code. Add some kind of README.TXT explaining: 1) the requirements (Lazarus and FPC versions, etc) PLUS your components 2) step-by-step instructions to install your custom components on Lazarus. If they can't do that, they should not be messing with your code anyway... :-) Thank you for the suggestions. And thanks to all others too. But I'm a bit more conservative. If without step-by-step instructions they don't know how to install a component on Lazarus IDE, they should not be messing with our code... ;-) Giuliano -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] LazReport Band.name patch
--- El jue 21-feb-13, Giuliano Colla giuliano.co...@fastwebnet.it escribió: I've tested a different approach, i.e. not *setting* the Band name, but just *getting* Band name from BandView, (a Name property in TfrBand which just returns the name of the corresponding Bandview, i.e. View.Name). It doesn't produce side effects, because when the BandView name is set the corresponding Band object doesn't yet exist. There are two solutions: 1) I send you the new patch. 2) We leave things as they are, but the examples and the documentation are modified to make it clear that TfrBand.Name is always empty, and that one must use TfrBand.View.Name to obtain a meaningful information. You're the boss, so it's up to you to decide. Giuliano Yes, please send the patch. Jesus Reyes A. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Where are the fpc sources for fpc 2.6.2?
Hi All: I just got a new laptop and decided to put the latest and greatest Lazarus/FPC on it. I got FPC 2.6.2, installed it and used it to compile Lazarus 1.1. When I run Lazarus it asks for (as an example) rtl/linux/system.pp. I found rtl/linux/system.pp in /usr/share/fpcsrc/2.6.0/rtl/linux/system.pp (no sign of 2.6.2/linux) so I pointed Lazarus at that path and it warns about the version mismatch. Can I use this till I get the updated sources? I have /usr/lib/fpc/2.6.2 and ~/fpc-2.6.2/lib/fpc/2.6.2 but they both only have directories ide, msg and units. I've been searching for the appropriate sources on the web with no success. I probably am missing something obvious so if anyone can point me to them I would sure appreciate it. Thanks Don Z. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where are the fpc sources for fpc 2.6.2?
On 24.02.2013 23:18, Donald Ziesig wrote: Hi All: I just got a new laptop and decided to put the latest and greatest Lazarus/FPC on it. I got FPC 2.6.2, installed it and used it to compile Lazarus 1.1. When I run Lazarus it asks for (as an example) rtl/linux/system.pp. I found rtl/linux/system.pp in /usr/share/fpcsrc/2.6.0/rtl/linux/system.pp (no sign of 2.6.2/linux) so I pointed Lazarus at that path and it warns about the version mismatch. Can I use this till I get the updated sources? I have /usr/lib/fpc/2.6.2 and ~/fpc-2.6.2/lib/fpc/2.6.2 but they both only have directories ide, msg and units. I've been searching for the appropriate sources on the web with no success. I probably am missing something obvious so if anyone can point me to them I would sure appreciate it. Go to http://www.freepascal.org/ and go to Download on the right side. There you'll see the point Sources below Binaries. You can either select one of the mirrors (which will take you to a new site on freepascal.org first where you can do the approbiate selection) or you can go to SourceForge which will (sadly) send you to the root directory. There you navigate to Source = 2.6.2 and then you either want fpc-2.6.2-sources.zip or fpc-2.6.2-source.tar.gz. Regards, Sven -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where are the fpc sources for fpc 2.6.2?
On Sun, 24 Feb 2013 17:18:21 -0500 Donald Ziesig don...@ziesig.org wrote: Hi All: I just got a new laptop and decided to put the latest and greatest Lazarus/FPC on it. Not true. If that was really your decision you would already have the sources as you would get both via SVN. And it would be FPC 2.7.1 and not 2.6.2. :) I've been searching for the appropriate sources on the web with no success. I probably am missing something obvious so if anyone can point me to them I would sure appreciate it. Here is one link to the 'old' stuff: http://sourceforge.net/projects/freepascal/files/Source/2.6.2/ R. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where are the fpc sources for fpc 2.6.2?
On Sun, 24 Feb 2013 17:18:21 -0500 Donald Ziesig don...@ziesig.org wrote: Hi All: I just got a new laptop and decided to put the latest and greatest Lazarus/FPC on it. I got FPC 2.6.2, installed it and used it to compile Lazarus 1.1. When I run Lazarus it asks for (as an example) rtl/linux/system.pp. I found rtl/linux/system.pp in /usr/share/fpcsrc/2.6.0/rtl/linux/system.pp (no sign of 2.6.2/linux) so I pointed Lazarus at that path I hope you mean, you pointed Lazarus at /usr/share/fpcsrc/2.6.0, without the rtl/linux/system.pp. and it warns about the version mismatch. Can I use this till I get the updated sources? Yes, but then the IDE might miss a few sources and/or declarations. I have /usr/lib/fpc/2.6.2 and ~/fpc-2.6.2/lib/fpc/2.6.2 but they both only have directories ide, msg and units. I've been searching for the appropriate sources on the web with no success. I probably am missing something obvious so if anyone can point me to them I would sure appreciate it. See Sven's note. Mattias -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Where are the fpc sources for fpc 2.6.2?
On 02/24/2013 05:40 PM, Mattias Gaertner wrote: On Sun, 24 Feb 2013 17:18:21 -0500 Donald Ziesig don...@ziesig.org wrote: Hi All: I just got a new laptop and decided to put the latest and greatest Lazarus/FPC on it. I got FPC 2.6.2, installed it and used it to compile Lazarus 1.1. When I run Lazarus it asks for (as an example) rtl/linux/system.pp. I found rtl/linux/system.pp in /usr/share/fpcsrc/2.6.0/rtl/linux/system.pp (no sign of 2.6.2/linux) so I pointed Lazarus at that path I hope you mean, you pointed Lazarus at /usr/share/fpcsrc/2.6.0, without the rtl/linux/system.pp. and it warns about the version mismatch. Can I use this till I get the updated sources? Yes, but then the IDE might miss a few sources and/or declarations. I have /usr/lib/fpc/2.6.2 and ~/fpc-2.6.2/lib/fpc/2.6.2 but they both only have directories ide, msg and units. I've been searching for the appropriate sources on the web with no success. I probably am missing something obvious so if anyone can point me to them I would sure appreciate it. See Sven's note. Mattias -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus Thanks Sven, Reimar and Mattias. I totally missed that location.:-[ Downloaded, decompressed and copied to appropriate paths. Lazarus 1.1 works without complaining. 8-) Don -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] operator overloading
I confirm that it does not work. Test program below, and the class source is attached. ==Test Program=== program test; {$mode objfpc}{$H+} uses Classes, treap; type TSLCounter = specialize TTreapTStringList, Integer; operator (sl1, sl2: TStringList): Boolean; begin Result := sl1.Text sl2.Text; end; begin end. ==Error Message== Options changed, recompiling clean with -B /home/xrfang/git/fpcollection/src/units/treap.pas(216,10) Error: Operator is not overloaded: TStringList TStringList /home/xrfang/git/fpcollection/src/units/treap.pas(218,15) Error: Operator is not overloaded: TStringList TStringList test.lpr(19) Fatal: There were 2 errors compiling module, stopping = i.e. whether the operator overloading is defined or not, error message is same. Thanks. 在 日, 2月 24, 2013 at 4:21 下午,leledumbo leledumbo_c...@yahoo.co.id 写道: FPC operator overloading doesn't work inside classes, it must be declared globally, so method2 should work. What error do you get? What FPC version do you use? -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-operator-overloading-tp4029399p4029400.html Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus unit treap; {$mode objfpc} interface type { TTreap } generic TTreapTKey, TValue = class const MAX_PRIORITY = $7FFF; type PNode = ^TNode; TNode = record Key: TKey; Value: TValue; Priority: Cardinal; Left, Right: PNode; end; private Altered: Boolean; //for Insert Delete GoOn: Boolean;//for Traverse FCount: Integer; NullNode, RootNode: PNode; function GetCount: Integer; function LeftRotate(Node: PNode): PNode; function RightRotate(Node: PNode): PNode; function InsertNode(Key: TKey; Value: TValue; Node: PNode): PNode; function DeleteNode(Key: TKey; Node: PNode): PNode; procedure TraverseNode(Node: PNode; dir: Integer); procedure ClearNode(Node: PNode); function Compare({%H-}Key: TKey; Node: PNode): Integer; protected function Traverse({%H-}Key: TKey; {%H-}Value: TValue): Boolean; virtual; procedure OnDispose({%H-}Value: TValue); virtual; function OnInsert({%H-}Key: TKey; {%H-}Value: TValue; {%H-}IsNew: Boolean): Boolean; virtual; public property Count: Integer read GetCount; function Insert(Key: TKey; Value: TValue): Boolean; function Delete(Key: TKey): Boolean; function Find(Key: TKey): PNode; procedure Clear; constructor Create; virtual; destructor Destroy; override; procedure Walk(dir: Integer = 0); //0=ascending; 1=descending end; implementation function TTreap.InsertNode(Key: TKey; Value: TValue; Node: PNode): PNode; begin if Node = NullNode then begin if OnInsert(Key, Value, True) then begin New(Node); Node^.Key := Key; Node^.Value := Value; Node^.Priority := Random(MAX_PRIORITY); Node^.Left := NullNode; Node^.Right := NullNode; Altered := True; Inc(FCount); end; end else begin case Compare(Key, Node) of 0: begin Altered := Node^.Value Value; if Altered and OnInsert(Key, Value, False) then Node^.Value := Value; end; 1: begin Node^.Right := InsertNode(Key, Value, Node^.Right); if Node^.Right^.Priority Node^.Priority then Node := RightRotate(Node); end; else begin Node^.Left := InsertNode(Key, Value, Node^.Left); if Node^.Left^.Priority Node^.Priority then Node := LeftRotate(Node); end; end; end; Result := Node; end; function TTreap.DeleteNode(Key: TKey; Node: PNode): PNode; begin if Node NullNode then begin case Compare(Key, Node) of 0: begin if Node^.Left^.Priority Node^.Right^.Priority then Node := LeftRotate(Node) else Node := RightRotate(Node); if Node NullNode then Node := DeleteNode(Key, Node) else begin OnDispose(Node^.Left^.Value); Dispose(Node^.Left); Node^.Left := NullNode; Altered := True; Dec(FCount); end; end; 1: Node^.Right := DeleteNode(Key, Node^.Right); else Node^.Left := DeleteNode(Key, Node^.Left); end; end; Result := Node; end; procedure TTreap.TraverseNode(Node: PNode; dir: Integer); begin if (not GoOn) or (Node = NullNode) then Exit; if dir = 0 then begin TraverseNode(Node^.Left, dir); if GoOn then GoOn := Traverse(Node^.Key, Node^.Value); TraverseNode(Node^.Right, dir); end else begin TraverseNode(Node^.Right, dir); if GoOn then GoOn :=